Skip to content

Commit 74936bd

Browse files
committed
Auto merge of #131856 - lcnr:typing-mode, r=<try>
TypingMode 🤔 unsure how and whether to actually get this ready for merge, opening for input + perf for now #### `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 #124598 r? `@compiler-errors`
2 parents 8aca4ba + e393d40 commit 74936bd

File tree

87 files changed

+461
-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.

87 files changed

+461
-531
lines changed

Diff for: 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

Diff for: compiler/rustc_borrowck/src/region_infer/opaque_types.rs

+3-3
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;
@@ -346,8 +347,7 @@ fn check_opaque_type_well_formed<'tcx>(
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,7 @@ impl<'tcx> LazyOpaqueTyEnv<'tcx> {
517517
},
518518
);
519519

520-
let infcx = tcx.infer_ctxt().build();
520+
let infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis());
521521
let ocx = ObligationCtxt::new(&infcx);
522522

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

Diff for: 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| {

Diff for: compiler/rustc_const_eval/src/check_consts/check.rs

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

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

Diff for: 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};
@@ -108,7 +108,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
108108
let obligation =
109109
Obligation::new(tcx, ObligationCause::dummy(), param_env, trait_ref);
110110

111-
let infcx = tcx.infer_ctxt().build();
111+
let infcx = tcx.infer_ctxt().build(TypingMode::from_param_env(param_env));
112112
let mut selcx = SelectionContext::new(&infcx);
113113
let implsrc = selcx.select(&obligation);
114114

Diff for: compiler/rustc_const_eval/src/check_consts/qualifs.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,10 @@ 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+
let infcx = cx.tcx.infer_ctxt().build(ty::TypingMode::analysis_in_body(
118+
cx.tcx,
119+
cx.body.source.def_id().expect_local(),
120+
));
122121
let ocx = ObligationCtxt::new(&infcx);
123122
ocx.register_obligation(obligation);
124123
let errors = ocx.select_all_or_error();

Diff for: 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

Diff for: compiler/rustc_const_eval/src/util/compare_types.rs

+2-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,7 @@ pub fn relate_types<'tcx>(
4545
}
4646

4747
let mut builder = tcx.infer_ctxt().ignoring_regions();
48-
let infcx = builder.build();
48+
let infcx = builder.build(TypingMode::non_body_analysis());
4949
let ocx = ObligationCtxt::new(&infcx);
5050
let cause = ObligationCause::dummy();
5151
let src = ocx.normalize(&cause, param_env, src);

Diff for: compiler/rustc_hir_analysis/src/check/check.rs

+3-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,7 @@ 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+
let infcx = tcx.infer_ctxt().build(TypingMode::analysis_in_body(tcx, defining_use_anchor));
280281
let ocx = ObligationCtxt::new_with_diagnostics(&infcx);
281282

282283
let args = match *origin {
@@ -1675,8 +1676,7 @@ pub(super) fn check_coroutine_obligations(
16751676
// typeck writeback gives us predicates with their regions erased.
16761677
// As borrowck already has checked lifetimes, we do not need to do it again.
16771678
.ignoring_regions()
1678-
.with_opaque_type_inference(def_id)
1679-
.build();
1679+
.build(TypingMode::analysis_in_body(tcx, def_id));
16801680

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

Diff for: 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;
@@ -209,7 +209,7 @@ fn compare_method_predicate_entailment<'tcx>(
209209
let param_env = traits::normalize_param_env_or_error(tcx, param_env, normalize_cause);
210210
debug!(caller_bounds=?param_env.caller_bounds());
211211

212-
let infcx = &tcx.infer_ctxt().build();
212+
let infcx = &tcx.infer_ctxt().build(TypingMode::non_body_analysis());
213213
let ocx = ObligationCtxt::new_with_diagnostics(infcx);
214214

215215
// Create obligations for each predicate declared by the impl
@@ -469,7 +469,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
469469
ObligationCause::misc(tcx.def_span(impl_m_def_id), impl_m_def_id),
470470
);
471471

472-
let infcx = &tcx.infer_ctxt().build();
472+
let infcx = &tcx.infer_ctxt().build(TypingMode::non_body_analysis());
473473
let ocx = ObligationCtxt::new_with_diagnostics(infcx);
474474

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

1152-
let infcx = tcx.infer_ctxt().build();
1152+
let infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis());
11531153
let self_arg_ty = tcx.liberate_late_bound_regions(method.def_id, self_arg_ty);
11541154
let can_eq_self = |ty| infcx.can_eq(param_env, untransformed_self_ty, ty);
11551155
match ExplicitSelf::determine(self_arg_ty, can_eq_self) {
@@ -1754,7 +1754,7 @@ fn compare_const_predicate_entailment<'tcx>(
17541754
ObligationCause::misc(impl_ct_span, impl_ct_def_id),
17551755
);
17561756

1757-
let infcx = tcx.infer_ctxt().build();
1757+
let infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis());
17581758
let ocx = ObligationCtxt::new_with_diagnostics(&infcx);
17591759

17601760
let impl_ct_own_bounds = impl_ct_predicates.instantiate_own_identity();
@@ -1885,7 +1885,7 @@ fn compare_type_predicate_entailment<'tcx>(
18851885
let param_env = traits::normalize_param_env_or_error(tcx, param_env, normalize_cause);
18861886
debug!(caller_bounds=?param_env.caller_bounds());
18871887

1888-
let infcx = tcx.infer_ctxt().build();
1888+
let infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis());
18891889
let ocx = ObligationCtxt::new_with_diagnostics(&infcx);
18901890

18911891
for (predicate, span) in impl_ty_own_bounds {
@@ -1947,7 +1947,7 @@ pub(super) fn check_type_bounds<'tcx>(
19471947
let impl_ty_args = GenericArgs::identity_for_item(tcx, impl_ty.def_id);
19481948
let rebased_args = impl_ty_args.rebase_onto(tcx, container_id, impl_trait_ref.args);
19491949

1950-
let infcx = tcx.infer_ctxt().build();
1950+
let infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis());
19511951
let ocx = ObligationCtxt::new_with_diagnostics(&infcx);
19521952

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

Diff for: 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:

Diff for: 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());

Diff for: 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,

Diff for: compiler/rustc_hir_analysis/src/check/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ use rustc_infer::infer::{self, TyCtxtInferExt as _};
8484
use rustc_infer::traits::ObligationCause;
8585
use rustc_middle::query::Providers;
8686
use rustc_middle::ty::error::{ExpectedFound, TypeError};
87-
use rustc_middle::ty::{self, GenericArgs, GenericArgsRef, Ty, TyCtxt};
87+
use rustc_middle::ty::{self, GenericArgs, GenericArgsRef, Ty, TyCtxt, TypingMode};
8888
use rustc_middle::{bug, span_bug};
8989
use rustc_session::parse::feature_err;
9090
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();

Diff for: 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;
@@ -105,7 +105,7 @@ where
105105
F: for<'a> FnOnce(&WfCheckingCtxt<'a, 'tcx>) -> Result<(), ErrorGuaranteed>,
106106
{
107107
let param_env = tcx.param_env(body_def_id);
108-
let infcx = &tcx.infer_ctxt().build();
108+
let infcx = &tcx.infer_ctxt().build(TypingMode::non_body_analysis());
109109
let ocx = ObligationCtxt::new_with_diagnostics(infcx);
110110

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

769769
add_constraints(&infcx);
770770

Diff for: 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>,

Diff for: compiler/rustc_hir_analysis/src/coherence/orphan.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
77
use rustc_lint_defs::builtin::UNCOVERED_PARAM_IN_PROJECTION;
88
use rustc_middle::ty::{
99
self, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeSuperVisitable,
10-
TypeVisitable, TypeVisitableExt, TypeVisitor,
10+
TypeVisitable, TypeVisitableExt, TypeVisitor, TypingMode,
1111
};
1212
use rustc_middle::{bug, span_bug};
1313
use rustc_span::def_id::{DefId, LocalDefId};
@@ -302,7 +302,7 @@ fn orphan_check<'tcx>(
302302
}
303303

304304
// (1) Instantiate all generic params with fresh inference vars.
305-
let infcx = tcx.infer_ctxt().intercrate(true).build();
305+
let infcx = tcx.infer_ctxt().build(TypingMode::Coherence);
306306
let cause = traits::ObligationCause::dummy();
307307
let args = infcx.fresh_args_for_item(cause.span, impl_def_id.to_def_id());
308308
let trait_ref = trait_ref.instantiate(tcx, args);

0 commit comments

Comments
 (0)