add test for stack overflow with recursive type #98842

Fixes #98842
This commit is contained in:
Matthias Krüger 2024-03-22 19:06:46 +01:00
parent 5ae90256da
commit 57f500512b
2 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,15 @@
// #98842 stack overflow in trait inference
//@ check-fail
//@ edition:2021
//~^^^ ERROR cycle detected when computing layout of `Foo`
// If the inner `Foo` is named through an associated type,
// the "infinite size" error does not occur.
struct Foo(<&'static Foo as ::core::ops::Deref>::Target);
// But Rust will be unable to know whether `Foo` is sized or not,
// and it will infinitely recurse somewhere trying to figure out the
// size of this pointer (is my guess):
const _: *const Foo = 0 as _;
//~^ ERROR it is undefined behavior to use this value
pub fn main() {}

View File

@ -0,0 +1,25 @@
error[E0391]: cycle detected when computing layout of `Foo`
|
= note: ...which requires computing layout of `<&'static Foo as core::ops::deref::Deref>::Target`...
= note: ...which again requires computing layout of `Foo`, completing the cycle
note: cycle used when const-evaluating + checking `_`
--> $DIR/stack-overflow-trait-infer-98842.rs:12:1
|
LL | const _: *const Foo = 0 as _;
| ^^^^^^^^^^^^^^^^^^^
= 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
error[E0080]: it is undefined behavior to use this value
--> $DIR/stack-overflow-trait-infer-98842.rs:12:1
|
LL | const _: *const Foo = 0 as _;
| ^^^^^^^^^^^^^^^^^^^ a cycle occurred during layout computation
|
= note: the raw bytes of the constant (size: 8, align: 8) {
00 00 00 00 00 00 00 00 │ ........
}
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0080, E0391.
For more information about an error, try `rustc --explain E0080`.