diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index 0d93e1478c420..df2412f446781 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -251,6 +251,10 @@ pub struct InferCtxt<'tcx> { /// Whether this inference context should care about region obligations in /// the root universe. Most notably, this is used during HIR typeck as region /// solving is left to borrowck instead. + /// + /// This is used in the old solver to enable the generation of regions constraints. + /// In the new solver its only used inside the InferCtxt's `Drop` implementation: + /// if we're considering regions, and new opaques are registered, we panic. pub considering_regions: bool, /// `-Znext-solver`: Whether this inference context is used by HIR typeck. If so, we /// need to make sure we don't rely on region identity in the trait solver or when diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 3d8ab41b37a31..10a5f380d4c80 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -118,7 +118,7 @@ pub use self::typeck_results::{ use crate::error::{OpaqueHiddenTypeMismatch, TypeMismatchReason}; use crate::metadata::{AmbigModChild, ModChild}; use crate::middle::privacy::EffectiveVisibilities; -use crate::mir::{Body, CoroutineLayout, CoroutineSavedLocal, SourceInfo}; +use crate::mir::{Body, CoroutineLayout, CoroutineSavedLocal, MirPhase, SourceInfo}; use crate::query::{IntoQueryKey, Providers}; use crate::ty; use crate::ty::codec::{TyDecoder, TyEncoder}; @@ -1777,7 +1777,7 @@ impl<'tcx> TyCtxt<'tcx> { /// Returns the possibly-auto-generated MIR of a [`ty::InstanceKind`]. #[instrument(skip(self), level = "debug")] pub fn instance_mir(self, instance: ty::InstanceKind<'tcx>) -> &'tcx Body<'tcx> { - match instance { + let body = match instance { ty::InstanceKind::Item(def) => { debug!("calling def_kind on def: {:?}", def); let def_kind = self.def_kind(def); @@ -1816,7 +1816,15 @@ impl<'tcx> TyCtxt<'tcx> { | ty::InstanceKind::FnPtrAddrShim(..) | ty::InstanceKind::AsyncDropGlueCtorShim(..) | ty::InstanceKind::AsyncDropGlue(..) => self.mir_shims(instance), - } + }; + + assert!( + matches!(body.phase, MirPhase::Runtime(_)), + "body: {body:?} instance: {instance:?} {:?}", + if let ty::InstanceKind::Item(d) = instance { Some(self.def_kind(d)) } else { None }, + ); + + body } /// Gets all attributes with the given name. diff --git a/compiler/rustc_mir_transform/src/shim.rs b/compiler/rustc_mir_transform/src/shim.rs index 50782c578f09f..6d9b8feea05f4 100644 --- a/compiler/rustc_mir_transform/src/shim.rs +++ b/compiler/rustc_mir_transform/src/shim.rs @@ -1074,7 +1074,12 @@ pub(super) fn build_adt_ctor(tcx: TyCtxt<'_>, ctor_id: DefId) -> Body<'_> { // so this would otherwise not get filled). body.set_mentioned_items(Vec::new()); - crate::pass_manager::dump_mir_for_phase_change(tcx, &body); + pm::run_passes_no_validate( + tcx, + &mut body, + &[], + Some(MirPhase::Runtime(RuntimePhase::Optimized)), + ); body } diff --git a/compiler/rustc_traits/src/normalize_erasing_regions.rs b/compiler/rustc_traits/src/normalize_erasing_regions.rs index d3a2c4d20f95d..1e6089dc37f95 100644 --- a/compiler/rustc_traits/src/normalize_erasing_regions.rs +++ b/compiler/rustc_traits/src/normalize_erasing_regions.rs @@ -22,7 +22,7 @@ fn try_normalize_after_erasing_regions<'tcx, T: TypeFoldable> + Par goal: PseudoCanonicalInput<'tcx, T>, ) -> Result { let PseudoCanonicalInput { typing_env, value } = goal; - let (infcx, param_env) = tcx.infer_ctxt().build_with_typing_env(typing_env); + let (infcx, param_env) = tcx.infer_ctxt().ignoring_regions().build_with_typing_env(typing_env); let cause = ObligationCause::dummy(); match infcx.at(&cause, param_env).query_normalize(value) { Ok(Normalized { value: normalized_value, obligations: normalized_obligations }) => { diff --git a/tests/mir-opt/unusual_item_types.Test-X-{constructor#0}.built.after.mir b/tests/mir-opt/unusual_item_types.Test-X-{constructor#0}.runtime-optimized.after.mir similarity index 73% rename from tests/mir-opt/unusual_item_types.Test-X-{constructor#0}.built.after.mir rename to tests/mir-opt/unusual_item_types.Test-X-{constructor#0}.runtime-optimized.after.mir index 1e497b412024c..527089e2b2cf0 100644 --- a/tests/mir-opt/unusual_item_types.Test-X-{constructor#0}.built.after.mir +++ b/tests/mir-opt/unusual_item_types.Test-X-{constructor#0}.runtime-optimized.after.mir @@ -1,4 +1,4 @@ -// MIR for `Test::X` after built +// MIR for `Test::X` after runtime-optimized fn Test::X(_1: usize) -> Test { let mut _0: Test; diff --git a/tests/mir-opt/unusual_item_types.rs b/tests/mir-opt/unusual_item_types.rs index 8ec15b4014ae5..e547246bae5f5 100644 --- a/tests/mir-opt/unusual_item_types.rs +++ b/tests/mir-opt/unusual_item_types.rs @@ -11,7 +11,7 @@ impl A { } // See #59021 -// EMIT_MIR unusual_item_types.Test-X-{constructor#0}.built.after.mir +// EMIT_MIR unusual_item_types.Test-X-{constructor#0}.runtime-optimized.after.mir enum Test { X(usize), Y { a: usize },