Skip to content

Commit ad0bb9c

Browse files
committed
Require all ObligationCtxt to have a defining anchor at creation time
1 parent 429e107 commit ad0bb9c

File tree

27 files changed

+69
-70
lines changed

27 files changed

+69
-70
lines changed

compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use rustc_infer::infer::canonical::Canonical;
66
use rustc_infer::infer::error_reporting::nice_region_error::NiceRegionError;
77
use rustc_infer::infer::region_constraints::Constraint;
88
use rustc_infer::infer::region_constraints::RegionConstraintData;
9+
use rustc_infer::infer::DefiningAnchor;
910
use rustc_infer::infer::RegionVariableOrigin;
1011
use rustc_infer::infer::{InferCtxt, RegionResolutionError, SubregionOrigin, TyCtxtInferExt as _};
1112
use rustc_infer::traits::ObligationCause;
@@ -245,7 +246,7 @@ impl<'tcx> TypeOpInfo<'tcx> for PredicateQuery<'tcx> {
245246
) -> Option<DiagnosticBuilder<'tcx, ErrorGuaranteed>> {
246247
let (infcx, key, _) =
247248
mbcx.infcx.tcx.infer_ctxt().build_with_canonical(cause.span, &self.canonical_query);
248-
let ocx = ObligationCtxt::new(&infcx);
249+
let ocx = ObligationCtxt::new(&infcx, DefiningAnchor::Error);
249250
type_op_prove_predicate_with_cause(&ocx, key, cause);
250251
try_extract_error_from_fulfill_cx(&ocx, placeholder_region, error_region)
251252
}
@@ -286,7 +287,7 @@ where
286287
) -> Option<DiagnosticBuilder<'tcx, ErrorGuaranteed>> {
287288
let (infcx, key, _) =
288289
mbcx.infcx.tcx.infer_ctxt().build_with_canonical(cause.span, &self.canonical_query);
289-
let ocx = ObligationCtxt::new(&infcx);
290+
let ocx = ObligationCtxt::new(&infcx, DefiningAnchor::Error);
290291

291292
// FIXME(lqd): Unify and de-duplicate the following with the actual
292293
// `rustc_traits::type_op::type_op_normalize` query to allow the span we need in the
@@ -330,7 +331,7 @@ impl<'tcx> TypeOpInfo<'tcx> for AscribeUserTypeQuery<'tcx> {
330331
) -> Option<DiagnosticBuilder<'tcx, ErrorGuaranteed>> {
331332
let (infcx, key, _) =
332333
mbcx.infcx.tcx.infer_ctxt().build_with_canonical(cause.span, &self.canonical_query);
333-
let ocx = ObligationCtxt::new(&infcx);
334+
let ocx = ObligationCtxt::new(&infcx, DefiningAnchor::Error);
334335
type_op_ascribe_user_type_with_span(&ocx, key, Some(cause.span)).ok()?;
335336
try_extract_error_from_fulfill_cx(&ocx, placeholder_region, error_region)
336337
}

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use rustc_data_structures::vec_map::VecMap;
33
use rustc_errors::ErrorGuaranteed;
44
use rustc_hir::def_id::LocalDefId;
55
use rustc_hir::OpaqueTyOrigin;
6-
use rustc_infer::infer::InferCtxt;
76
use rustc_infer::infer::TyCtxtInferExt as _;
7+
use rustc_infer::infer::{DefiningAnchor, InferCtxt};
88
use rustc_infer::traits::{Obligation, ObligationCause};
99
use rustc_middle::ty::subst::{GenericArgKind, InternalSubsts};
1010
use rustc_middle::ty::visit::TypeVisitableExt;
@@ -277,7 +277,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
277277
// HACK This bubble is required for this tests to pass:
278278
// nested-return-type2-tait2.rs
279279
// nested-return-type2-tait3.rs
280-
let ocx = ObligationCtxt::new_with_opaque_type_bubbling(&infcx);
280+
let ocx = ObligationCtxt::new(&infcx, DefiningAnchor::Bubble);
281281
// Require the hidden type to be well-formed with only the generics of the opaque type.
282282
// Defining use functions may have more bounds than the opaque type, which is ok, as long as the
283283
// hidden type is well formed even without those bounds.

compiler/rustc_borrowck/src/type_check/canonical.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::fmt;
22

3+
use rustc_infer::infer::DefiningAnchor;
34
use rustc_infer::infer::{canonical::Canonical, InferOk};
45
use rustc_middle::mir::ConstraintCategory;
56
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt, TypeFoldable};
@@ -221,7 +222,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
221222
let cause = ObligationCause::dummy_with_span(span);
222223
let param_env = self.param_env;
223224
let op = |infcx: &'_ _| {
224-
let ocx = ObligationCtxt::new_in_snapshot(infcx);
225+
let ocx = ObligationCtxt::new_in_snapshot(infcx, DefiningAnchor::Error);
225226
let user_ty = ocx.normalize(&cause, param_env, user_ty);
226227
ocx.eq(&cause, param_env, user_ty, mir_ty)?;
227228
if !ocx.select_all_or_error().is_empty() {

compiler/rustc_const_eval/src/transform/check_consts/check.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_errors::{Diagnostic, ErrorGuaranteed};
44
use rustc_hir as hir;
55
use rustc_hir::def_id::DefId;
66
use rustc_index::bit_set::BitSet;
7-
use rustc_infer::infer::TyCtxtInferExt;
7+
use rustc_infer::infer::{DefiningAnchor, TyCtxtInferExt};
88
use rustc_infer::traits::{ImplSource, Obligation, ObligationCause};
99
use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor};
1010
use rustc_middle::mir::*;
@@ -752,7 +752,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
752752
// "non-const" check. This is required for correctness here.
753753
{
754754
let infcx = tcx.infer_ctxt().build();
755-
let ocx = ObligationCtxt::new(&infcx);
755+
let ocx = ObligationCtxt::new(&infcx, DefiningAnchor::Error);
756756

757757
let predicates = tcx.predicates_of(callee).instantiate(tcx, substs);
758758
let cause = ObligationCause::new(

compiler/rustc_const_eval/src/util/compare_types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! FIXME: Move this to a more general place. The utility of this extends to
44
//! other areas of the compiler as well.
55
6-
use rustc_infer::infer::TyCtxtInferExt;
6+
use rustc_infer::infer::{DefiningAnchor, TyCtxtInferExt};
77
use rustc_infer::traits::ObligationCause;
88
use rustc_middle::ty::{ParamEnv, Ty, TyCtxt};
99
use rustc_trait_selection::traits::ObligationCtxt;
@@ -43,7 +43,7 @@ pub fn is_subtype<'tcx>(
4343

4444
let mut builder = tcx.infer_ctxt().ignoring_regions();
4545
let infcx = builder.build();
46-
let ocx = ObligationCtxt::new_with_opaque_type_bubbling(&infcx);
46+
let ocx = ObligationCtxt::new(&infcx, DefiningAnchor::Bubble);
4747
let cause = ObligationCause::dummy();
4848
let src = ocx.normalize(&cause, param_env, src);
4949
let dest = ocx.normalize(&cause, param_env, dest);

compiler/rustc_hir_analysis/src/astconv/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use rustc_hir::def_id::{DefId, LocalDefId};
2828
use rustc_hir::intravisit::{walk_generics, Visitor as _};
2929
use rustc_hir::{GenericArg, GenericArgs, OpaqueTyOrigin};
3030
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
31-
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
31+
use rustc_infer::infer::{DefiningAnchor, InferCtxt, TyCtxtInferExt};
3232
use rustc_infer::traits::ObligationCause;
3333
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind};
3434
use rustc_middle::middle::stability::AllowUnstable;
@@ -2231,7 +2231,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
22312231
.iter()
22322232
.filter_map(|&(impl_, (assoc_item, def_scope))| {
22332233
infcx.probe(|_| {
2234-
let ocx = ObligationCtxt::new_in_snapshot(&infcx);
2234+
let ocx = ObligationCtxt::new_in_snapshot(&infcx, DefiningAnchor::Error);
22352235

22362236
let impl_ty = tcx.type_of(impl_);
22372237
let impl_substs = infcx.fresh_item_substs(impl_);

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ fn check_opaque_meets_bounds<'tcx>(
414414
let param_env = tcx.param_env(defining_use_anchor);
415415

416416
let infcx = tcx.infer_ctxt().build();
417-
let ocx = ObligationCtxt::new_with_opaque_type_anchor(&infcx, defining_use_anchor);
417+
let ocx = ObligationCtxt::new(&infcx, defining_use_anchor);
418418
let opaque_ty = tcx.mk_opaque(def_id.to_def_id(), substs);
419419

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

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_hir::intravisit;
1111
use rustc_hir::{GenericParamKind, ImplItemKind};
1212
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
1313
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
14-
use rustc_infer::infer::{self, InferCtxt, TyCtxtInferExt};
14+
use rustc_infer::infer::{self, DefiningAnchor, InferCtxt, TyCtxtInferExt};
1515
use rustc_infer::traits::util;
1616
use rustc_middle::ty::error::{ExpectedFound, TypeError};
1717
use rustc_middle::ty::util::ExplicitSelf;
@@ -203,7 +203,7 @@ fn compare_method_predicate_entailment<'tcx>(
203203
let param_env = traits::normalize_param_env_or_error(tcx, param_env, normalize_cause);
204204

205205
let infcx = &tcx.infer_ctxt().build();
206-
let ocx = ObligationCtxt::new(infcx);
206+
let ocx = ObligationCtxt::new(infcx, DefiningAnchor::Error);
207207

208208
debug!("compare_impl_method: caller_bounds={:?}", param_env.caller_bounds());
209209

@@ -619,7 +619,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
619619
impl_to_placeholder_substs.rebase_onto(tcx, impl_m.container_id(tcx), trait_to_impl_substs);
620620

621621
let infcx = &tcx.infer_ctxt().build();
622-
let ocx = ObligationCtxt::new(infcx);
622+
let ocx = ObligationCtxt::new(infcx, DefiningAnchor::Error);
623623

624624
// Normalize the impl signature with fresh variables for lifetime inference.
625625
let norm_cause = ObligationCause::misc(return_span, impl_m_def_id);
@@ -1652,7 +1652,7 @@ pub(super) fn compare_impl_const_raw(
16521652

16531653
let infcx = tcx.infer_ctxt().build();
16541654
let param_env = tcx.param_env(impl_const_item_def.to_def_id());
1655-
let ocx = ObligationCtxt::new(&infcx);
1655+
let ocx = ObligationCtxt::new(&infcx, DefiningAnchor::Error);
16561656

16571657
// The below is for the most part highly similar to the procedure
16581658
// for methods above. It is simpler in many respects, especially
@@ -1806,7 +1806,7 @@ fn compare_type_predicate_entailment<'tcx>(
18061806
);
18071807
let param_env = traits::normalize_param_env_or_error(tcx, param_env, normalize_cause);
18081808
let infcx = tcx.infer_ctxt().build();
1809-
let ocx = ObligationCtxt::new(&infcx);
1809+
let ocx = ObligationCtxt::new(&infcx, DefiningAnchor::Error);
18101810

18111811
debug!("compare_type_predicate_entailment: caller_bounds={:?}", param_env.caller_bounds());
18121812

@@ -1992,7 +1992,7 @@ pub(super) fn check_type_bounds<'tcx>(
19921992
let rebased_substs = impl_ty_substs.rebase_onto(tcx, container_id, impl_trait_ref.substs);
19931993

19941994
let infcx = tcx.infer_ctxt().build();
1995-
let ocx = ObligationCtxt::new(&infcx);
1995+
let ocx = ObligationCtxt::new(&infcx, DefiningAnchor::Error);
19961996

19971997
let impl_ty_span = match tcx.hir().get_by_def_id(impl_ty_def_id) {
19981998
hir::Node::TraitItem(hir::TraitItem {

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_hir::lang_items::LangItem;
1111
use rustc_hir::ItemKind;
1212
use rustc_infer::infer::outlives::env::{OutlivesEnvironment, RegionBoundPairs};
1313
use rustc_infer::infer::outlives::obligations::TypeOutlives;
14-
use rustc_infer::infer::{self, InferCtxt, TyCtxtInferExt};
14+
use rustc_infer::infer::{self, DefiningAnchor, InferCtxt, TyCtxtInferExt};
1515
use rustc_middle::mir::ConstraintCategory;
1616
use rustc_middle::ty::query::Providers;
1717
use rustc_middle::ty::trait_def::TraitSpecializationKind;
@@ -97,7 +97,7 @@ pub(super) fn enter_wf_checking_ctxt<'tcx, F>(
9797
{
9898
let param_env = tcx.param_env(body_def_id);
9999
let infcx = &tcx.infer_ctxt().build();
100-
let ocx = ObligationCtxt::new(infcx);
100+
let ocx = ObligationCtxt::new(infcx, DefiningAnchor::Error);
101101

102102
let mut wfcx = WfCheckingCtxt { ocx, span, body_def_id, param_env };
103103

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use rustc_hir as hir;
2525
use rustc_hir::def_id::{DefId, LocalDefId};
2626
use rustc_hir::intravisit::{self, Visitor};
2727
use rustc_hir::{GenericParamKind, Node};
28-
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
28+
use rustc_infer::infer::{DefiningAnchor, InferCtxt, TyCtxtInferExt};
2929
use rustc_infer::traits::ObligationCause;
3030
use rustc_middle::hir::nested_filter;
3131
use rustc_middle::ty::query::Providers;
@@ -1320,7 +1320,7 @@ fn suggest_impl_trait<'tcx>(
13201320
{
13211321
continue;
13221322
}
1323-
let ocx = ObligationCtxt::new_in_snapshot(&infcx);
1323+
let ocx = ObligationCtxt::new_in_snapshot(&infcx, DefiningAnchor::Error);
13241324
let item_ty = ocx.normalize(
13251325
&ObligationCause::misc(span, def_id),
13261326
param_env,

0 commit comments

Comments
 (0)