about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Markeffsky <@>2023-12-26 17:50:41 +0100
committerLukas Markeffsky <@>2023-12-26 17:57:33 +0100
commit29036045c3d156e2e952732c61034ec0c00f5903 (patch)
tree7880c48a7f6bd97358c3973367464ba5c084ea6b
parentcb2fc0967fbecc26a33dcc9b99bbeccc826d576b (diff)
downloadrust-29036045c3d156e2e952732c61034ec0c00f5903.tar.gz
rust-29036045c3d156e2e952732c61034ec0c00f5903.zip
add test for coercing never to infinite type
-rw-r--r--tests/ui/sized/recursive-type-coercion-from-never.rs16
-rw-r--r--tests/ui/sized/recursive-type-coercion-from-never.stderr14
2 files changed, 30 insertions, 0 deletions
diff --git a/tests/ui/sized/recursive-type-coercion-from-never.rs b/tests/ui/sized/recursive-type-coercion-from-never.rs
new file mode 100644
index 00000000000..a1b65463731
--- /dev/null
+++ b/tests/ui/sized/recursive-type-coercion-from-never.rs
@@ -0,0 +1,16 @@
+// build-fail
+//~^ ERROR cycle detected when computing layout of `Foo<()>`
+
+// Regression test for a stack overflow: https://github.com/rust-lang/rust/issues/113197
+
+trait A { type Assoc; }
+
+impl A for () {
+    type Assoc = Foo<()>;
+}
+
+struct Foo<T: A>(T::Assoc);
+
+fn main() {
+    Foo::<()>(todo!());
+}
diff --git a/tests/ui/sized/recursive-type-coercion-from-never.stderr b/tests/ui/sized/recursive-type-coercion-from-never.stderr
new file mode 100644
index 00000000000..7580e780dda
--- /dev/null
+++ b/tests/ui/sized/recursive-type-coercion-from-never.stderr
@@ -0,0 +1,14 @@
+error[E0391]: cycle detected when computing layout of `Foo<()>`
+   |
+   = note: ...which requires computing layout of `<() as A>::Assoc`...
+   = note: ...which again requires computing layout of `Foo<()>`, completing the cycle
+note: cycle used when elaborating drops for `main`
+  --> $DIR/recursive-type-coercion-from-never.rs:14:1
+   |
+LL | fn main() {
+   | ^^^^^^^^^
+   = 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: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0391`.