Skip to content

Commit f928076

Browse files
committed
Actually set the defining use anchor on ObligationCtxt
1 parent d0f6215 commit f928076

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
278278
// nested-return-type2-tait3.rs
279279
let infcx =
280280
self.tcx.infer_ctxt().with_opaque_type_inference(DefiningAnchor::Bubble).build();
281-
let ocx = ObligationCtxt::new(&infcx);
281+
let ocx = ObligationCtxt::new_with_opaque_type_bubbling(&infcx);
282282
// Require the hidden type to be well-formed with only the generics of the opaque type.
283283
// Defining use functions may have more bounds than the opaque type, which is ok, as long as the
284284
// hidden type is well formed even without those bounds.

compiler/rustc_const_eval/src/util/compare_types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub fn is_subtype<'tcx>(
4444
let mut builder =
4545
tcx.infer_ctxt().ignoring_regions().with_opaque_type_inference(DefiningAnchor::Bubble);
4646
let infcx = builder.build();
47-
let ocx = ObligationCtxt::new(&infcx);
47+
let ocx = ObligationCtxt::new_with_opaque_type_bubbling(&infcx);
4848
let cause = ObligationCause::dummy();
4949
let src = ocx.normalize(&cause, param_env, src);
5050
let dest = ocx.normalize(&cause, param_env, dest);

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ fn check_opaque_meets_bounds<'tcx>(
417417
.infer_ctxt()
418418
.with_opaque_type_inference(DefiningAnchor::Bind(defining_use_anchor))
419419
.build();
420-
let ocx = ObligationCtxt::new(&infcx);
420+
let ocx = ObligationCtxt::new_with_opaque_type_anchor(&infcx, defining_use_anchor);
421421
let opaque_ty = tcx.mk_opaque(def_id.to_def_id(), substs);
422422

423423
// `ReErased` regions appear in the "parent_substs" of closures/generators.

compiler/rustc_trait_selection/src/traits/engine.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,23 @@ impl<'a, 'tcx> ObligationCtxt<'a, 'tcx> {
6060
Self {
6161
infcx,
6262
engine: RefCell::new(<dyn TraitEngine<'_>>::new(infcx.tcx)),
63-
defining_use_anchor: infcx.old_defining_use_anchor,
63+
defining_use_anchor: DefiningAnchor::Error,
64+
}
65+
}
66+
67+
pub fn new_with_opaque_type_bubbling(infcx: &'a InferCtxt<'tcx>) -> Self {
68+
Self {
69+
infcx,
70+
engine: RefCell::new(<dyn TraitEngine<'_>>::new(infcx.tcx)),
71+
defining_use_anchor: DefiningAnchor::Bubble,
72+
}
73+
}
74+
75+
pub fn new_with_opaque_type_anchor(infcx: &'a InferCtxt<'tcx>, anchor: LocalDefId) -> Self {
76+
Self {
77+
infcx,
78+
engine: RefCell::new(<dyn TraitEngine<'_>>::new(infcx.tcx)),
79+
defining_use_anchor: DefiningAnchor::Bind(anchor),
6480
}
6581
}
6682

0 commit comments

Comments
 (0)