Skip to content

Dont resolve instance of root in mir_callgraph_cyclic #143551

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 7, 2025
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
11 changes: 2 additions & 9 deletions compiler/rustc_mir_transform/src/inline/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,8 @@ pub(crate) fn mir_callgraph_cyclic<'tcx>(
let recursion_limit = tcx.recursion_limit() / 2;
let mut involved = FxHashSet::default();
let typing_env = ty::TypingEnv::post_analysis(tcx, root);
let Ok(Some(root_instance)) = ty::Instance::try_resolve(
tcx,
typing_env,
root.to_def_id(),
ty::GenericArgs::identity_for_item(tcx, root.to_def_id()),
) else {
trace!("cannot resolve, skipping");
return involved.into();
};
let root_instance =
ty::Instance::new_raw(root.to_def_id(), ty::GenericArgs::identity_for_item(tcx, root));
if !should_recurse(tcx, root_instance) {
trace!("cannot walk, skipping");
return involved.into();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
- // MIR for `Trait::a` before Inline
+ // MIR for `Trait::a` after Inline

fn Trait::a(_1: &Self) -> () {
debug self => _1;
let mut _0: ();
let _2: ();
let mut _3: &();
let _4: ();
let mut _5: &();

bb0: {
StorageLive(_2);
StorageLive(_3);
_5 = const <Self as Trait>::a::promoted[0];
_3 = &(*_5);
_2 = <() as Trait>::b(move _3) -> [return: bb1, unwind unreachable];
}

bb1: {
StorageDead(_3);
StorageDead(_2);
_0 = const ();
return;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
- // MIR for `Trait::a` before Inline
+ // MIR for `Trait::a` after Inline

fn Trait::a(_1: &Self) -> () {
debug self => _1;
let mut _0: ();
let _2: ();
let mut _3: &();
let _4: ();
let mut _5: &();

bb0: {
StorageLive(_2);
StorageLive(_3);
_5 = const <Self as Trait>::a::promoted[0];
_3 = &(*_5);
_2 = <() as Trait>::b(move _3) -> [return: bb1, unwind continue];
}

bb1: {
StorageDead(_3);
StorageDead(_2);
_0 = const ();
return;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
- // MIR for `Trait::b` before Inline
+ // MIR for `Trait::b` after Inline

fn Trait::b(_1: &Self) -> () {
debug self => _1;
let mut _0: ();
let _2: ();
let mut _3: &();
let _4: ();
let mut _5: &();

bb0: {
StorageLive(_2);
StorageLive(_3);
_5 = const <Self as Trait>::b::promoted[0];
_3 = &(*_5);
_2 = <() as Trait>::a(move _3) -> [return: bb1, unwind unreachable];
}

bb1: {
StorageDead(_3);
StorageDead(_2);
_0 = const ();
return;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
- // MIR for `Trait::b` before Inline
+ // MIR for `Trait::b` after Inline

fn Trait::b(_1: &Self) -> () {
debug self => _1;
let mut _0: ();
let _2: ();
let mut _3: &();
let _4: ();
let mut _5: &();

bb0: {
StorageLive(_2);
StorageLive(_3);
_5 = const <Self as Trait>::b::promoted[0];
_3 = &(*_5);
_2 = <() as Trait>::a(move _3) -> [return: bb1, unwind continue];
}

bb1: {
StorageDead(_3);
StorageDead(_2);
_0 = const ();
return;
}
}

19 changes: 19 additions & 0 deletions tests/mir-opt/inline_default_trait_body.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
// skip-filecheck
//@ test-mir-pass: Inline
//@ edition: 2021
//@ compile-flags: -Zinline-mir --crate-type=lib

// EMIT_MIR inline_default_trait_body.Trait-a.Inline.diff
// EMIT_MIR inline_default_trait_body.Trait-b.Inline.diff
pub trait Trait {
fn a(&self) {
().b();
}

fn b(&self) {
().a();
}
}

impl Trait for () {}
Loading