Skip to content

Commit 15f7e81

Browse files
committed
Check all opaque types, even return position impl trait.
While not necessary right now, this is the safe choice and will be necessary for lazy TAIT.
1 parent 5d07a6c commit 15f7e81

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

compiler/rustc_typeck/src/check/check.rs

+18-14
Original file line numberDiff line numberDiff line change
@@ -626,25 +626,22 @@ pub(super) fn check_opaque_for_cycles<'tcx>(
626626
///
627627
/// Without this check the above code is incorrectly accepted: we would ICE if
628628
/// some tried, for example, to clone an `Option<X<&mut ()>>`.
629-
#[instrument(skip(tcx))]
629+
#[instrument(level = "debug", skip(tcx))]
630630
fn check_opaque_meets_bounds<'tcx>(
631631
tcx: TyCtxt<'tcx>,
632632
def_id: LocalDefId,
633633
substs: SubstsRef<'tcx>,
634634
span: Span,
635635
origin: &hir::OpaqueTyOrigin,
636636
) {
637-
match origin {
638-
// Checked when type checking the function containing them.
639-
hir::OpaqueTyOrigin::FnReturn(..) | hir::OpaqueTyOrigin::AsyncFn(..) => return,
640-
// Can have different predicates to their defining use
641-
hir::OpaqueTyOrigin::TyAlias => {}
642-
}
643-
644637
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
645-
let param_env = tcx.param_env(def_id);
638+
let defining_use_anchor = match *origin {
639+
hir::OpaqueTyOrigin::FnReturn(did) | hir::OpaqueTyOrigin::AsyncFn(did) => did,
640+
hir::OpaqueTyOrigin::TyAlias => def_id,
641+
};
642+
let param_env = tcx.param_env(defining_use_anchor);
646643

647-
tcx.infer_ctxt().with_opaque_type_inference(def_id).enter(move |infcx| {
644+
tcx.infer_ctxt().with_opaque_type_inference(defining_use_anchor).enter(move |infcx| {
648645
let inh = Inherited::new(infcx, def_id);
649646
let infcx = &inh.infcx;
650647
let opaque_ty = tcx.mk_opaque(def_id.to_def_id(), substs);
@@ -678,10 +675,17 @@ fn check_opaque_meets_bounds<'tcx>(
678675
infcx.report_fulfillment_errors(&errors, None, false);
679676
}
680677

681-
// Finally, resolve all regions. This catches wily misuses of
682-
// lifetime parameters.
683-
let fcx = FnCtxt::new(&inh, param_env, hir_id);
684-
fcx.regionck_item(hir_id, span, FxHashSet::default());
678+
match origin {
679+
// Checked when type checking the function containing them.
680+
hir::OpaqueTyOrigin::FnReturn(..) | hir::OpaqueTyOrigin::AsyncFn(..) => return,
681+
// Can have different predicates to their defining use
682+
hir::OpaqueTyOrigin::TyAlias => {
683+
// Finally, resolve all regions. This catches wily misuses of
684+
// lifetime parameters.
685+
let fcx = FnCtxt::new(&inh, param_env, hir_id);
686+
fcx.regionck_item(hir_id, span, FxHashSet::default());
687+
}
688+
}
685689
});
686690
}
687691

0 commit comments

Comments
 (0)