about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-03-22 19:06:46 +0100
committerMatthias Krüger <matthias.krueger@famsik.de>2024-03-24 09:23:13 +0100
commit57f500512bec1e29dbae876499899b579273aa2a (patch)
treebd46c0a1870935c84235767a99277baefb30c4d1 /tests
parent5ae90256daff3442ffe823035b79001b49c28ee1 (diff)
downloadrust-57f500512bec1e29dbae876499899b579273aa2a.tar.gz
rust-57f500512bec1e29dbae876499899b579273aa2a.zip
add test for stack overflow with recursive type #98842
Fixes #98842
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/sized/stack-overflow-trait-infer-98842.rs15
-rw-r--r--tests/ui/sized/stack-overflow-trait-infer-98842.stderr25
2 files changed, 40 insertions, 0 deletions
diff --git a/tests/ui/sized/stack-overflow-trait-infer-98842.rs b/tests/ui/sized/stack-overflow-trait-infer-98842.rs
new file mode 100644
index 00000000000..2bba0777be4
--- /dev/null
+++ b/tests/ui/sized/stack-overflow-trait-infer-98842.rs
@@ -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() {}
diff --git a/tests/ui/sized/stack-overflow-trait-infer-98842.stderr b/tests/ui/sized/stack-overflow-trait-infer-98842.stderr
new file mode 100644
index 00000000000..42b2718e332
--- /dev/null
+++ b/tests/ui/sized/stack-overflow-trait-infer-98842.stderr
@@ -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`.