Skip to content

Commit 15ef7a0

Browse files
committed
add test for stack overflow with recursive type #98842
Fixes #98842
1 parent efc57fb commit 15ef7a0

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// #98842 stack overflow in trait inference
2+
//@ check-fail
3+
//@ edition:2021
4+
//~^^^ ERROR cycle detected when computing layout of `Foo`
5+
6+
// If the inner `Foo` is named through an associated type,
7+
// the "infinite size" error does not occur.
8+
struct Foo(<&'static Foo as ::core::ops::Deref>::Target);
9+
// But Rust will be unable to know whether `Foo` is sized or not,
10+
// and it will infinitely recurse somewhere trying to figure out the
11+
// size of this pointer (is my guess):
12+
const _: *const Foo = 0 as _;
13+
//~^ ERROR it is undefined behavior to use this value
14+
15+
pub fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
error[E0391]: cycle detected when computing layout of `Foo`
2+
|
3+
= note: ...which requires computing layout of `<&'static Foo as core::ops::deref::Deref>::Target`...
4+
= note: ...which again requires computing layout of `Foo`, completing the cycle
5+
note: cycle used when const-evaluating + checking `_`
6+
--> $DIR/stack-overflow-trait-infer-98842.rs:12:1
7+
|
8+
LL | const _: *const Foo = 0 as _;
9+
| ^^^^^^^^^^^^^^^^^^^
10+
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
11+
12+
error[E0080]: it is undefined behavior to use this value
13+
--> $DIR/stack-overflow-trait-infer-98842.rs:12:1
14+
|
15+
LL | const _: *const Foo = 0 as _;
16+
| ^^^^^^^^^^^^^^^^^^^ a cycle occurred during layout computation
17+
|
18+
= note: the raw bytes of the constant (size: 8, align: 8) {
19+
00 00 00 00 00 00 00 00 │ ........
20+
}
21+
22+
error: aborting due to 2 previous errors
23+
24+
Some errors have detailed explanations: E0080, E0391.
25+
For more information about an error, try `rustc --explain E0080`.

0 commit comments

Comments
 (0)