forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test for stack overflow with recursive type rust-lang#98842
Fixes rust-lang#98842
- Loading branch information
1 parent
5ae9025
commit 57f5005
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |