Skip to content

Commit a40274d

Browse files
Dont resolve instance of root in mir_callgraph_cyclic
1 parent 3c95364 commit a40274d

6 files changed

+129
-9
lines changed

compiler/rustc_mir_transform/src/inline/cycle.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,8 @@ pub(crate) fn mir_callgraph_cyclic<'tcx>(
155155
let recursion_limit = tcx.recursion_limit() / 2;
156156
let mut involved = FxHashSet::default();
157157
let typing_env = ty::TypingEnv::post_analysis(tcx, root);
158-
let Ok(Some(root_instance)) = ty::Instance::try_resolve(
159-
tcx,
160-
typing_env,
161-
root.to_def_id(),
162-
ty::GenericArgs::identity_for_item(tcx, root.to_def_id()),
163-
) else {
164-
trace!("cannot resolve, skipping");
165-
return involved.into();
166-
};
158+
let root_instance =
159+
ty::Instance::new_raw(root.to_def_id(), ty::GenericArgs::identity_for_item(tcx, root));
167160
if !should_recurse(tcx, root_instance) {
168161
trace!("cannot walk, skipping");
169162
return involved.into();
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
- // MIR for `Trait::a` before Inline
2+
+ // MIR for `Trait::a` after Inline
3+
4+
fn Trait::a(_1: &Self) -> () {
5+
debug self => _1;
6+
let mut _0: ();
7+
let _2: ();
8+
let mut _3: &();
9+
let _4: ();
10+
let mut _5: &();
11+
12+
bb0: {
13+
StorageLive(_2);
14+
StorageLive(_3);
15+
_5 = const <Self as Trait>::a::promoted[0];
16+
_3 = &(*_5);
17+
_2 = <() as Trait>::b(move _3) -> [return: bb1, unwind unreachable];
18+
}
19+
20+
bb1: {
21+
StorageDead(_3);
22+
StorageDead(_2);
23+
_0 = const ();
24+
return;
25+
}
26+
}
27+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
- // MIR for `Trait::a` before Inline
2+
+ // MIR for `Trait::a` after Inline
3+
4+
fn Trait::a(_1: &Self) -> () {
5+
debug self => _1;
6+
let mut _0: ();
7+
let _2: ();
8+
let mut _3: &();
9+
let _4: ();
10+
let mut _5: &();
11+
12+
bb0: {
13+
StorageLive(_2);
14+
StorageLive(_3);
15+
_5 = const <Self as Trait>::a::promoted[0];
16+
_3 = &(*_5);
17+
_2 = <() as Trait>::b(move _3) -> [return: bb1, unwind continue];
18+
}
19+
20+
bb1: {
21+
StorageDead(_3);
22+
StorageDead(_2);
23+
_0 = const ();
24+
return;
25+
}
26+
}
27+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
- // MIR for `Trait::b` before Inline
2+
+ // MIR for `Trait::b` after Inline
3+
4+
fn Trait::b(_1: &Self) -> () {
5+
debug self => _1;
6+
let mut _0: ();
7+
let _2: ();
8+
let mut _3: &();
9+
let _4: ();
10+
let mut _5: &();
11+
12+
bb0: {
13+
StorageLive(_2);
14+
StorageLive(_3);
15+
_5 = const <Self as Trait>::b::promoted[0];
16+
_3 = &(*_5);
17+
_2 = <() as Trait>::a(move _3) -> [return: bb1, unwind unreachable];
18+
}
19+
20+
bb1: {
21+
StorageDead(_3);
22+
StorageDead(_2);
23+
_0 = const ();
24+
return;
25+
}
26+
}
27+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
- // MIR for `Trait::b` before Inline
2+
+ // MIR for `Trait::b` after Inline
3+
4+
fn Trait::b(_1: &Self) -> () {
5+
debug self => _1;
6+
let mut _0: ();
7+
let _2: ();
8+
let mut _3: &();
9+
let _4: ();
10+
let mut _5: &();
11+
12+
bb0: {
13+
StorageLive(_2);
14+
StorageLive(_3);
15+
_5 = const <Self as Trait>::b::promoted[0];
16+
_3 = &(*_5);
17+
_2 = <() as Trait>::a(move _3) -> [return: bb1, unwind continue];
18+
}
19+
20+
bb1: {
21+
StorageDead(_3);
22+
StorageDead(_2);
23+
_0 = const ();
24+
return;
25+
}
26+
}
27+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
2+
// skip-filecheck
3+
//@ test-mir-pass: Inline
4+
//@ edition: 2021
5+
//@ compile-flags: -Zinline-mir --crate-type=lib
6+
7+
// EMIT_MIR inline_default_trait_body.Trait-a.Inline.diff
8+
// EMIT_MIR inline_default_trait_body.Trait-b.Inline.diff
9+
pub trait Trait {
10+
fn a(&self) {
11+
().b();
12+
}
13+
14+
fn b(&self) {
15+
().a();
16+
}
17+
}
18+
19+
impl Trait for () {}

0 commit comments

Comments
 (0)