Skip to content

Commit 8dca16c

Browse files
authored
Rollup merge of #111097 - oli-obk:🚲_layout, r=compiler-errors
Avoid ICEing miri on layout query cycles Miri has special logic for catching panics during interpretation. Raising a fatal error in rustc uses unwinding to abort compilation. Thus miri ends up catching that fatal error and thinks it saw an ICE. While we should probably change that to ignore `Fatal` payloads, I think it's also neat to continue compilation after a layout query cycle 😆 Query cycles now (in addition to reporting an error just like before), return `Err(Cycle)` instead of raising a fatal error. This allows the interpreter to wind down via the regular error paths. r? `@RalfJung` for a first round, feel free to reroll for the compiler team once the miri side looks good
2 parents b6e74ed + b1e8770 commit 8dca16c

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

tests/fail/layout_cycle.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//@error-pattern: a cycle occurred during layout computation
2+
//~^ ERROR: cycle detected when computing layout of
3+
4+
use std::mem;
5+
6+
pub struct S<T: Tr> {
7+
pub f: <T as Tr>::I,
8+
}
9+
10+
pub trait Tr {
11+
type I: Tr;
12+
}
13+
14+
impl<T: Tr> Tr for S<T> {
15+
type I = S<S<T>>;
16+
}
17+
18+
impl Tr for () {
19+
type I = ();
20+
}
21+
22+
fn foo<T: Tr>() -> usize {
23+
mem::size_of::<S<T>>()
24+
}
25+
26+
fn main() {
27+
println!("{}", foo::<S<()>>());
28+
}

tests/fail/layout_cycle.stderr

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
error[E0391]: cycle detected when computing layout of `S<S<()>>`
2+
|
3+
= note: ...which requires computing layout of `<S<()> as Tr>::I`...
4+
= note: ...which again requires computing layout of `S<S<()>>`, completing the cycle
5+
6+
error: post-monomorphization error: a cycle occurred during layout computation
7+
--> RUSTLIB/core/src/mem/mod.rs:LL:CC
8+
|
9+
LL | intrinsics::size_of::<T>()
10+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ a cycle occurred during layout computation
11+
|
12+
= note: inside `std::mem::size_of::<S<S<()>>>` at RUSTLIB/core/src/mem/mod.rs:LL:CC
13+
note: inside `foo::<S<()>>`
14+
--> $DIR/layout_cycle.rs:LL:CC
15+
|
16+
LL | mem::size_of::<S<T>>()
17+
| ^^^^^^^^^^^^^^^^^^^^^^
18+
note: inside `main`
19+
--> $DIR/layout_cycle.rs:LL:CC
20+
|
21+
LL | println!("{}", foo::<S<()>>());
22+
| ^^^^^^^^^^^^^^
23+
24+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
25+
26+
error: aborting due to 2 previous errors
27+
28+
For more information about this error, try `rustc --explain E0391`.

0 commit comments

Comments
 (0)