Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_mir_transform/src/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(

@RalfJung RalfJung Jun 24, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems worth a comment explaining why we run the empty list of passes here?

View changes since the review

tcx,
&mut body,
&[],
Some(MirPhase::Runtime(RuntimePhase::Optimized)),
);

body
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_traits/src/normalize_erasing_regions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn try_normalize_after_erasing_regions<'tcx, T: TypeFoldable<TyCtxt<'tcx>> + Par
goal: PseudoCanonicalInput<'tcx, T>,
) -> Result<T, NoSolution> {
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 }) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/unusual_item_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
Loading