Skip to content

Commit eeaca54

Browse files
authored
Unrolled build for rust-lang#131856
Rollup merge of rust-lang#131856 - lcnr:typing-mode, r=compiler-errors TypingMode: merge intercrate, reveal, and defining_opaque_types This adds `TypingMode` and uses it in most places. We do not yet remove `Reveal` from `param_env`s. This and other future work as tracked in rust-lang#132279 and via `FIXME`s. Fetching the `TypingMode` of the `InferCtxt` asserts that the `TypingMode` agrees with `ParamEnv::reveal` to make sure we don't introduce any subtle bugs here. This will be unnecessary once `ParamEnv::reveal` no longer exists. As the `TypingMode` is now a part of the query input, I've merged the coherence and non-coherence caches for the new solver. I've also enabled the local `infcx` cache during coherence by clearing the cache when forking it with a different `TypingMode`. #### `TypingMode::from_param_env` I am using this even in cases where I know that the `param_env` will always be `Reveal::UserFacing`. This is to make it easier to correctly refactor this code in the future, any time we use `Reveal::UserFacing` in a body while not defining its opaque types is incorrect and should use a `TypingMode` which only reveals opaques defined by that body instead, cc rust-lang#124598 r? ``@compiler-errors``
2 parents 16422db + 524a22e commit eeaca54

File tree

89 files changed

+536
-531
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+536
-531
lines changed

compiler/rustc_borrowck/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use rustc_infer::infer::{
3434
use rustc_middle::mir::tcx::PlaceTy;
3535
use rustc_middle::mir::*;
3636
use rustc_middle::query::Providers;
37-
use rustc_middle::ty::{self, ParamEnv, RegionVid, TyCtxt};
37+
use rustc_middle::ty::{self, ParamEnv, RegionVid, TyCtxt, TypingMode};
3838
use rustc_middle::{bug, span_bug};
3939
use rustc_mir_dataflow::Analysis;
4040
use rustc_mir_dataflow::impls::{
@@ -440,7 +440,7 @@ pub struct BorrowckInferCtxt<'tcx> {
440440

441441
impl<'tcx> BorrowckInferCtxt<'tcx> {
442442
pub(crate) fn new(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Self {
443-
let infcx = tcx.infer_ctxt().with_opaque_type_inference(def_id).build();
443+
let infcx = tcx.infer_ctxt().build(TypingMode::analysis_in_body(tcx, def_id));
444444
BorrowckInferCtxt { infcx, reg_var_to_origin: RefCell::new(Default::default()) }
445445
}
446446

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_macros::extension;
99
use rustc_middle::ty::visit::TypeVisitableExt;
1010
use rustc_middle::ty::{
1111
self, GenericArgKind, GenericArgs, OpaqueHiddenType, OpaqueTypeKey, Ty, TyCtxt, TypeFoldable,
12+
TypingMode,
1213
};
1314
use rustc_span::Span;
1415
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
@@ -340,14 +341,13 @@ fn check_opaque_type_well_formed<'tcx>(
340341
parent_def_id = tcx.local_parent(parent_def_id);
341342
}
342343

343-
// FIXME(-Znext-solver): We probably should use `&[]` instead of
344-
// and prepopulate this `InferCtxt` with known opaque values, rather than
345-
// allowing opaque types to be defined and checking them after the fact.
344+
// FIXME(#132279): This should eventually use the already defined hidden types
345+
// instead. Alternatively we'll entirely remove this function given we also check
346+
// the opaque in `check_opaque_meets_bounds` later.
346347
let infcx = tcx
347348
.infer_ctxt()
348349
.with_next_trait_solver(next_trait_solver)
349-
.with_opaque_type_inference(parent_def_id)
350-
.build();
350+
.build(TypingMode::analysis_in_body(tcx, parent_def_id));
351351
let ocx = ObligationCtxt::new_with_diagnostics(&infcx);
352352
let identity_args = GenericArgs::identity_for_item(tcx, def_id);
353353

@@ -517,7 +517,9 @@ impl<'tcx> LazyOpaqueTyEnv<'tcx> {
517517
},
518518
);
519519

520-
let infcx = tcx.infer_ctxt().build();
520+
// FIXME(#132279): It feels wrong to use `non_body_analysis` here given that we're
521+
// in a body here.
522+
let infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis());
521523
let ocx = ObligationCtxt::new(&infcx);
522524

523525
let wf_tys = ocx.assumed_wf_types(param_env, parent).unwrap_or_else(|_| {

compiler/rustc_codegen_ssa/src/base.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_middle::mir::BinOp;
2121
use rustc_middle::mir::mono::{CodegenUnit, CodegenUnitNameBuilder, MonoItem};
2222
use rustc_middle::query::Providers;
2323
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf, TyAndLayout};
24-
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
24+
use rustc_middle::ty::{self, Instance, Ty, TyCtxt, TypingMode};
2525
use rustc_session::Session;
2626
use rustc_session::config::{self, CrateType, EntryFnType, OptLevel, OutputType};
2727
use rustc_span::symbol::sym;
@@ -119,7 +119,7 @@ pub fn validate_trivial_unsize<'tcx>(
119119
) -> bool {
120120
match (source_data.principal(), target_data.principal()) {
121121
(Some(hr_source_principal), Some(hr_target_principal)) => {
122-
let infcx = tcx.infer_ctxt().build();
122+
let infcx = tcx.infer_ctxt().build(TypingMode::PostAnalysis);
123123
let universe = infcx.universe();
124124
let ocx = ObligationCtxt::new(&infcx);
125125
infcx.enter_forall(hr_target_principal, |target_principal| {

compiler/rustc_const_eval/src/check_consts/check.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_middle::mir::visit::Visitor;
1616
use rustc_middle::mir::*;
1717
use rustc_middle::span_bug;
1818
use rustc_middle::ty::adjustment::PointerCoercion;
19-
use rustc_middle::ty::{self, Instance, InstanceKind, Ty, TypeVisitableExt};
19+
use rustc_middle::ty::{self, Instance, InstanceKind, Ty, TypeVisitableExt, TypingMode};
2020
use rustc_mir_dataflow::Analysis;
2121
use rustc_mir_dataflow::impls::MaybeStorageLive;
2222
use rustc_mir_dataflow::storage::always_storage_live_locals;
@@ -593,7 +593,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
593593
// Typeck only does a "non-const" check since it operates on HIR and cannot distinguish
594594
// which path expressions are getting called on and which path expressions are only used
595595
// as function pointers. This is required for correctness.
596-
let infcx = tcx.infer_ctxt().build();
596+
let infcx = tcx.infer_ctxt().build(TypingMode::from_param_env(param_env));
597597
let ocx = ObligationCtxt::new_with_diagnostics(&infcx);
598598

599599
let predicates = tcx.predicates_of(callee).instantiate(tcx, fn_args);

compiler/rustc_const_eval/src/check_consts/ops.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_middle::mir::CallSource;
1212
use rustc_middle::span_bug;
1313
use rustc_middle::ty::print::{PrintTraitRefExt as _, with_no_trimmed_paths};
1414
use rustc_middle::ty::{
15-
self, Closure, FnDef, FnPtr, GenericArgKind, GenericArgsRef, Param, TraitRef, Ty,
15+
self, Closure, FnDef, FnPtr, GenericArgKind, GenericArgsRef, Param, TraitRef, Ty, TypingMode,
1616
suggest_constraining_type_param,
1717
};
1818
use rustc_middle::util::{CallDesugaringKind, CallKind, call_kind};
@@ -116,7 +116,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
116116
let obligation =
117117
Obligation::new(tcx, ObligationCause::dummy(), param_env, trait_ref);
118118

119-
let infcx = tcx.infer_ctxt().build();
119+
let infcx = tcx.infer_ctxt().build(TypingMode::from_param_env(param_env));
120120
let mut selcx = SelectionContext::new(&infcx);
121121
let implsrc = selcx.select(&obligation);
122122

compiler/rustc_const_eval/src/check_consts/qualifs.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,11 @@ impl Qualif for HasMutInterior {
114114
ty::TraitRef::new(cx.tcx, freeze_def_id, [ty::GenericArg::from(ty)]),
115115
);
116116

117-
let infcx = cx
118-
.tcx
119-
.infer_ctxt()
120-
.with_opaque_type_inference(cx.body.source.def_id().expect_local())
121-
.build();
117+
// FIXME(#132279): This should eventually use the already defined hidden types.
118+
let infcx = cx.tcx.infer_ctxt().build(ty::TypingMode::analysis_in_body(
119+
cx.tcx,
120+
cx.body.source.def_id().expect_local(),
121+
));
122122
let ocx = ObligationCtxt::new(&infcx);
123123
ocx.register_obligation(obligation);
124124
let errors = ocx.select_all_or_error();

compiler/rustc_const_eval/src/interpret/eval_context.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ use rustc_middle::query::TyCtxtAt;
99
use rustc_middle::ty::layout::{
1010
self, FnAbiError, FnAbiOfHelpers, FnAbiRequest, LayoutError, LayoutOfHelpers, TyAndLayout,
1111
};
12-
use rustc_middle::ty::{self, GenericArgsRef, ParamEnv, Ty, TyCtxt, TypeFoldable, Variance};
12+
use rustc_middle::ty::{
13+
self, GenericArgsRef, ParamEnv, Ty, TyCtxt, TypeFoldable, TypingMode, Variance,
14+
};
1315
use rustc_middle::{mir, span_bug};
1416
use rustc_session::Limit;
1517
use rustc_span::Span;
@@ -325,7 +327,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
325327
return true;
326328
}
327329
// Slow path: spin up an inference context to check if these traits are sufficiently equal.
328-
let infcx = self.tcx.infer_ctxt().build();
330+
let infcx = self.tcx.infer_ctxt().build(TypingMode::from_param_env(self.param_env));
329331
let ocx = ObligationCtxt::new(&infcx);
330332
let cause = ObligationCause::dummy_with_span(self.cur_span());
331333
// equate the two trait refs after normalization

compiler/rustc_const_eval/src/util/compare_types.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
use rustc_infer::infer::TyCtxtInferExt;
77
use rustc_middle::traits::ObligationCause;
8-
use rustc_middle::ty::{ParamEnv, Ty, TyCtxt, Variance};
8+
use rustc_middle::ty::{ParamEnv, Ty, TyCtxt, TypingMode, Variance};
99
use rustc_trait_selection::traits::ObligationCtxt;
1010

1111
/// Returns whether the two types are equal up to subtyping.
@@ -45,7 +45,8 @@ pub fn relate_types<'tcx>(
4545
}
4646

4747
let mut builder = tcx.infer_ctxt().ignoring_regions();
48-
let infcx = builder.build();
48+
// FIXME(#132279): This should eventually use the already defined hidden types.
49+
let infcx = builder.build(TypingMode::from_param_env(param_env));
4950
let ocx = ObligationCtxt::new(&infcx);
5051
let cause = ObligationCause::dummy();
5152
let src = ocx.normalize(&cause, param_env, src);

compiler/rustc_hir_analysis/src/check/check.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use rustc_trait_selection::traits;
3030
use rustc_trait_selection::traits::outlives_bounds::InferCtxtExt as _;
3131
use rustc_type_ir::fold::TypeFoldable;
3232
use tracing::{debug, instrument};
33+
use ty::TypingMode;
3334
use {rustc_attr as attr, rustc_hir as hir};
3435

3536
use super::compare_impl_item::{check_type_bounds, compare_impl_method, compare_impl_ty};
@@ -276,7 +277,8 @@ fn check_opaque_meets_bounds<'tcx>(
276277
};
277278
let param_env = tcx.param_env(defining_use_anchor);
278279

279-
let infcx = tcx.infer_ctxt().with_opaque_type_inference(defining_use_anchor).build();
280+
// FIXME(#132279): This should eventually use the already defined hidden types.
281+
let infcx = tcx.infer_ctxt().build(TypingMode::analysis_in_body(tcx, defining_use_anchor));
280282
let ocx = ObligationCtxt::new_with_diagnostics(&infcx);
281283

282284
let args = match *origin {
@@ -1675,8 +1677,8 @@ pub(super) fn check_coroutine_obligations(
16751677
// typeck writeback gives us predicates with their regions erased.
16761678
// As borrowck already has checked lifetimes, we do not need to do it again.
16771679
.ignoring_regions()
1678-
.with_opaque_type_inference(def_id)
1679-
.build();
1680+
// FIXME(#132279): This should eventually use the already defined hidden types.
1681+
.build(TypingMode::analysis_in_body(tcx, def_id));
16801682

16811683
let ocx = ObligationCtxt::new_with_diagnostics(&infcx);
16821684
for (predicate, cause) in &typeck_results.coroutine_stalled_predicates {

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_middle::ty::fold::BottomUpFolder;
1717
use rustc_middle::ty::util::ExplicitSelf;
1818
use rustc_middle::ty::{
1919
self, GenericArgs, GenericParamDefKind, Ty, TyCtxt, TypeFoldable, TypeFolder,
20-
TypeSuperFoldable, TypeVisitableExt, Upcast,
20+
TypeSuperFoldable, TypeVisitableExt, TypingMode, Upcast,
2121
};
2222
use rustc_middle::{bug, span_bug};
2323
use rustc_span::Span;
@@ -228,7 +228,7 @@ fn compare_method_predicate_entailment<'tcx>(
228228
let param_env = traits::normalize_param_env_or_error(tcx, param_env, normalize_cause);
229229
debug!(caller_bounds=?param_env.caller_bounds());
230230

231-
let infcx = &tcx.infer_ctxt().build();
231+
let infcx = &tcx.infer_ctxt().build(TypingMode::non_body_analysis());
232232
let ocx = ObligationCtxt::new_with_diagnostics(infcx);
233233

234234
// Create obligations for each predicate declared by the impl
@@ -516,7 +516,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
516516
ObligationCause::misc(tcx.def_span(impl_m_def_id), impl_m_def_id),
517517
);
518518

519-
let infcx = &tcx.infer_ctxt().build();
519+
let infcx = &tcx.infer_ctxt().build(TypingMode::non_body_analysis());
520520
let ocx = ObligationCtxt::new_with_diagnostics(infcx);
521521

522522
// Normalize the impl signature with fresh variables for lifetime inference.
@@ -1196,7 +1196,7 @@ fn compare_self_type<'tcx>(
11961196
let self_arg_ty = tcx.fn_sig(method.def_id).instantiate_identity().input(0);
11971197
let param_env = ty::ParamEnv::reveal_all();
11981198

1199-
let infcx = tcx.infer_ctxt().build();
1199+
let infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis());
12001200
let self_arg_ty = tcx.liberate_late_bound_regions(method.def_id, self_arg_ty);
12011201
let can_eq_self = |ty| infcx.can_eq(param_env, untransformed_self_ty, ty);
12021202
match ExplicitSelf::determine(self_arg_ty, can_eq_self) {
@@ -1801,7 +1801,7 @@ fn compare_const_predicate_entailment<'tcx>(
18011801
ObligationCause::misc(impl_ct_span, impl_ct_def_id),
18021802
);
18031803

1804-
let infcx = tcx.infer_ctxt().build();
1804+
let infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis());
18051805
let ocx = ObligationCtxt::new_with_diagnostics(&infcx);
18061806

18071807
let impl_ct_own_bounds = impl_ct_predicates.instantiate_own_identity();
@@ -1951,7 +1951,7 @@ fn compare_type_predicate_entailment<'tcx>(
19511951
let param_env = traits::normalize_param_env_or_error(tcx, param_env, normalize_cause);
19521952
debug!(caller_bounds=?param_env.caller_bounds());
19531953

1954-
let infcx = tcx.infer_ctxt().build();
1954+
let infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis());
19551955
let ocx = ObligationCtxt::new_with_diagnostics(&infcx);
19561956

19571957
for (predicate, span) in impl_ty_own_bounds {
@@ -2036,7 +2036,7 @@ pub(super) fn check_type_bounds<'tcx>(
20362036
let impl_ty_args = GenericArgs::identity_for_item(tcx, impl_ty.def_id);
20372037
let rebased_args = impl_ty_args.rebase_onto(tcx, container_id, impl_trait_ref.args);
20382038

2039-
let infcx = tcx.infer_ctxt().build();
2039+
let infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis());
20402040
let ocx = ObligationCtxt::new_with_diagnostics(&infcx);
20412041

20422042
// A synthetic impl Trait for RPITIT desugaring or assoc type for effects desugaring has no HIR,

compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_middle::span_bug;
88
use rustc_middle::traits::{ObligationCause, Reveal};
99
use rustc_middle::ty::{
1010
self, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperVisitable, TypeVisitable,
11-
TypeVisitableExt, TypeVisitor,
11+
TypeVisitableExt, TypeVisitor, TypingMode,
1212
};
1313
use rustc_span::Span;
1414
use rustc_trait_selection::regions::InferCtxtRegionExt;
@@ -132,7 +132,7 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
132132
let param_env = ty::ParamEnv::new(tcx.mk_clauses_from_iter(hybrid_preds), Reveal::UserFacing);
133133
let param_env = normalize_param_env_or_error(tcx, param_env, ObligationCause::dummy());
134134

135-
let ref infcx = tcx.infer_ctxt().build();
135+
let ref infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis());
136136
let ocx = ObligationCtxt::new(infcx);
137137

138138
// Normalize the bounds. This has two purposes:

compiler/rustc_hir_analysis/src/check/dropck.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_infer::infer::outlives::env::OutlivesEnvironment;
99
use rustc_infer::infer::{RegionResolutionError, TyCtxtInferExt};
1010
use rustc_infer::traits::{ObligationCause, ObligationCauseCode};
1111
use rustc_middle::ty::util::CheckRegions;
12-
use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt};
12+
use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt, TypingMode};
1313
use rustc_trait_selection::regions::InferCtxtRegionExt;
1414
use rustc_trait_selection::traits::{self, ObligationCtxt};
1515

@@ -124,7 +124,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
124124
adt_def_id: LocalDefId,
125125
adt_to_impl_args: GenericArgsRef<'tcx>,
126126
) -> Result<(), ErrorGuaranteed> {
127-
let infcx = tcx.infer_ctxt().build();
127+
let infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis());
128128
let ocx = ObligationCtxt::new_with_diagnostics(&infcx);
129129

130130
let impl_span = tcx.def_span(drop_impl_def_id.to_def_id());

compiler/rustc_hir_analysis/src/check/entry.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_hir as hir;
44
use rustc_hir::Node;
55
use rustc_infer::infer::TyCtxtInferExt;
66
use rustc_middle::span_bug;
7-
use rustc_middle::ty::{self, Ty, TyCtxt};
7+
use rustc_middle::ty::{self, Ty, TyCtxt, TypingMode};
88
use rustc_session::config::EntryFnType;
99
use rustc_span::Span;
1010
use rustc_span::def_id::{CRATE_DEF_ID, DefId, LocalDefId};
@@ -128,7 +128,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
128128
tcx.dcx().emit_err(errors::MainFunctionReturnTypeGeneric { span: return_ty_span });
129129
return;
130130
};
131-
let infcx = tcx.infer_ctxt().build();
131+
let infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis());
132132
let cause = traits::ObligationCause::new(
133133
return_ty_span,
134134
main_diagnostics_def_id,

compiler/rustc_hir_analysis/src/check/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ use rustc_infer::infer::{self, TyCtxtInferExt as _};
8585
use rustc_infer::traits::ObligationCause;
8686
use rustc_middle::query::Providers;
8787
use rustc_middle::ty::error::{ExpectedFound, TypeError};
88-
use rustc_middle::ty::{self, GenericArgs, GenericArgsRef, Ty, TyCtxt};
88+
use rustc_middle::ty::{self, GenericArgs, GenericArgsRef, Ty, TyCtxt, TypingMode};
8989
use rustc_middle::{bug, span_bug};
9090
use rustc_session::parse::feature_err;
9191
use rustc_span::def_id::CRATE_DEF_ID;
@@ -530,7 +530,7 @@ fn suggestion_signature<'tcx>(
530530
let ty = tcx.type_of(assoc.def_id).instantiate_identity();
531531
let val = tcx
532532
.infer_ctxt()
533-
.build()
533+
.build(TypingMode::non_body_analysis())
534534
.err_ctxt()
535535
.ty_kind_suggestion(tcx.param_env(assoc.def_id), ty)
536536
.unwrap_or_else(|| "value".to_string());
@@ -620,7 +620,7 @@ pub fn check_function_signature<'tcx>(
620620

621621
let param_env = ty::ParamEnv::empty();
622622

623-
let infcx = &tcx.infer_ctxt().build();
623+
let infcx = &tcx.infer_ctxt().build(TypingMode::non_body_analysis());
624624
let ocx = ObligationCtxt::new_with_diagnostics(infcx);
625625

626626
let actual_sig = tcx.fn_sig(fn_id).instantiate_identity();

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_middle::ty::print::with_no_trimmed_paths;
1717
use rustc_middle::ty::trait_def::TraitSpecializationKind;
1818
use rustc_middle::ty::{
1919
self, AdtKind, GenericArgKind, GenericArgs, GenericParamDefKind, Ty, TyCtxt, TypeFoldable,
20-
TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, Upcast,
20+
TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, TypingMode, Upcast,
2121
};
2222
use rustc_middle::{bug, span_bug};
2323
use rustc_session::parse::feature_err;
@@ -106,7 +106,7 @@ where
106106
F: for<'a> FnOnce(&WfCheckingCtxt<'a, 'tcx>) -> Result<(), ErrorGuaranteed>,
107107
{
108108
let param_env = tcx.param_env(body_def_id);
109-
let infcx = &tcx.infer_ctxt().build();
109+
let infcx = &tcx.infer_ctxt().build(TypingMode::non_body_analysis());
110110
let ocx = ObligationCtxt::new_with_diagnostics(infcx);
111111

112112
let mut wfcx = WfCheckingCtxt { ocx, span, body_def_id, param_env };
@@ -765,7 +765,7 @@ fn test_region_obligations<'tcx>(
765765
// Unfortunately, we have to use a new `InferCtxt` each call, because
766766
// region constraints get added and solved there and we need to test each
767767
// call individually.
768-
let infcx = tcx.infer_ctxt().build();
768+
let infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis());
769769

770770
add_constraints(&infcx);
771771

compiler/rustc_hir_analysis/src/coherence/builtin.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ use rustc_infer::infer::{self, RegionResolutionError, TyCtxtInferExt};
1515
use rustc_infer::traits::Obligation;
1616
use rustc_middle::ty::adjustment::CoerceUnsizedInfo;
1717
use rustc_middle::ty::print::PrintTraitRefExt as _;
18-
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt, suggest_constraining_type_params};
18+
use rustc_middle::ty::{
19+
self, Ty, TyCtxt, TypeVisitableExt, TypingMode, suggest_constraining_type_params,
20+
};
1921
use rustc_span::{DUMMY_SP, Span};
2022
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
2123
use rustc_trait_selection::traits::misc::{
@@ -213,7 +215,7 @@ fn visit_implementation_of_dispatch_from_dyn(checker: &Checker<'_>) -> Result<()
213215

214216
let param_env = tcx.param_env(impl_did);
215217

216-
let infcx = tcx.infer_ctxt().build();
218+
let infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis());
217219
let cause = ObligationCause::misc(span, impl_did);
218220

219221
// Later parts of the compiler rely on all DispatchFromDyn types to be ABI-compatible with raw
@@ -354,7 +356,7 @@ pub(crate) fn coerce_unsized_info<'tcx>(
354356

355357
debug!("visit_implementation_of_coerce_unsized: {:?} -> {:?} (free)", source, target);
356358

357-
let infcx = tcx.infer_ctxt().build();
359+
let infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis());
358360
let cause = ObligationCause::misc(span, impl_did);
359361
let check_mutbl = |mt_a: ty::TypeAndMut<'tcx>,
360362
mt_b: ty::TypeAndMut<'tcx>,

0 commit comments

Comments
 (0)