]> git.lizzy.rs Git - rust.git/commitdiff
add some more tests
authorlcnr <rust@lcnr.de>
Tue, 27 Apr 2021 12:24:19 +0000 (14:24 +0200)
committerMichael Goulet <michael@errs.io>
Thu, 10 Nov 2022 21:18:06 +0000 (21:18 +0000)
src/test/ui/sized/recursive-type-1.rs [new file with mode: 0644]
src/test/ui/sized/recursive-type-2.rs [new file with mode: 0644]
src/test/ui/sized/recursive-type-2.stderr [new file with mode: 0644]

diff --git a/src/test/ui/sized/recursive-type-1.rs b/src/test/ui/sized/recursive-type-1.rs
new file mode 100644 (file)
index 0000000..cd68059
--- /dev/null
@@ -0,0 +1,10 @@
+// check-pass
+trait A { type Assoc; }
+
+impl A for () {
+    // FIXME: it would be nice for this to at least cause a warning.
+    type Assoc = Foo<()>;
+}
+struct Foo<T: A>(T::Assoc);
+
+fn main() {}
diff --git a/src/test/ui/sized/recursive-type-2.rs b/src/test/ui/sized/recursive-type-2.rs
new file mode 100644 (file)
index 0000000..7d95417
--- /dev/null
@@ -0,0 +1,13 @@
+// build-fail
+//~^ ERROR cycle detected when computing layout of `Foo<()>`
+
+trait A { type Assoc: ?Sized; }
+
+impl A for () {
+    type Assoc = Foo<()>;
+}
+struct Foo<T: A>(T::Assoc);
+
+fn main() {
+    let x: Foo<()>;
+}
diff --git a/src/test/ui/sized/recursive-type-2.stderr b/src/test/ui/sized/recursive-type-2.stderr
new file mode 100644 (file)
index 0000000..2102c93
--- /dev/null
@@ -0,0 +1,12 @@
+error[E0391]: cycle detected when computing layout of `Foo<()>`
+   |
+   = note: ...which again requires computing layout of `Foo<()>`, completing the cycle
+note: cycle used when optimizing MIR for `main`
+  --> $DIR/recursive-type-2.rs:11:1
+   |
+LL | fn main() {
+   | ^^^^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0391`.