]> git.lizzy.rs Git - rust.git/commitdiff
Improve the cycle tests
authorJonas Schievink <jonasschievink@gmail.com>
Sat, 14 Sep 2019 23:18:37 +0000 (01:18 +0200)
committerJonas Schievink <jonasschievink@gmail.com>
Fri, 21 Feb 2020 18:41:22 +0000 (19:41 +0100)
src/test/ui/associated-types/defaults-cyclic-fail-1.rs [new file with mode: 0644]
src/test/ui/associated-types/defaults-cyclic-fail-1.stderr [new file with mode: 0644]
src/test/ui/associated-types/defaults-cyclic-fail-2.rs [new file with mode: 0644]
src/test/ui/associated-types/defaults-cyclic-fail-2.stderr [new file with mode: 0644]
src/test/ui/associated-types/defaults-cyclic-fail.rs [deleted file]
src/test/ui/associated-types/defaults-cyclic-fail.stderr [deleted file]
src/test/ui/associated-types/defaults-cyclic-pass-1.rs [new file with mode: 0644]
src/test/ui/associated-types/defaults-cyclic-pass-2.rs [new file with mode: 0644]
src/test/ui/associated-types/defaults-cyclic-pass.rs [deleted file]

diff --git a/src/test/ui/associated-types/defaults-cyclic-fail-1.rs b/src/test/ui/associated-types/defaults-cyclic-fail-1.rs
new file mode 100644 (file)
index 0000000..71ac914
--- /dev/null
@@ -0,0 +1,45 @@
+#![feature(associated_type_defaults)]
+
+// Having a cycle in assoc. type defaults is okay...
+trait Tr {
+    type A = Self::B;
+    type B = Self::A;
+}
+
+// ...but is an error in any impl that doesn't override at least one of the defaults
+impl Tr for () {}
+//~^ ERROR overflow evaluating the requirement
+
+// As soon as at least one is redefined, it works:
+impl Tr for u8 {
+    type A = u8;
+}
+
+impl Tr for u16 {
+    type B = ();
+}
+
+impl Tr for u32 {
+    type A = ();
+    type B = u8;
+}
+
+// ...but only if this actually breaks the cycle
+impl Tr for bool {
+//~^ ERROR overflow evaluating the requirement
+    type A = Box<Self::B>;
+    //~^ ERROR overflow evaluating the requirement
+}
+// (the error is shown twice for some reason)
+
+impl Tr for usize {
+//~^ ERROR overflow evaluating the requirement
+    type B = &'static Self::A;
+    //~^ ERROR overflow evaluating the requirement
+}
+
+fn main() {
+    // We don't check that the types project correctly because the cycle errors stop compilation
+    // before `main` is type-checked.
+    // `defaults-cyclic-pass-1.rs` does this.
+}
diff --git a/src/test/ui/associated-types/defaults-cyclic-fail-1.stderr b/src/test/ui/associated-types/defaults-cyclic-fail-1.stderr
new file mode 100644 (file)
index 0000000..4f28a50
--- /dev/null
@@ -0,0 +1,33 @@
+error[E0275]: overflow evaluating the requirement `<() as Tr>::B`
+  --> $DIR/defaults-cyclic-fail-1.rs:12:6
+   |
+LL | impl Tr for () {}
+   |      ^^
+
+error[E0275]: overflow evaluating the requirement `<bool as Tr>::B`
+  --> $DIR/defaults-cyclic-fail-1.rs:30:6
+   |
+LL | impl Tr for bool {
+   |      ^^
+
+error[E0275]: overflow evaluating the requirement `<usize as Tr>::B`
+  --> $DIR/defaults-cyclic-fail-1.rs:37:6
+   |
+LL | impl Tr for usize {
+   |      ^^
+
+error[E0275]: overflow evaluating the requirement `<bool as Tr>::B`
+  --> $DIR/defaults-cyclic-fail-1.rs:32:5
+   |
+LL |     type A = Box<Self::B>;
+   |     ^^^^^^^^^^^^^^^^^^^^^^
+
+error[E0275]: overflow evaluating the requirement `<usize as Tr>::A`
+  --> $DIR/defaults-cyclic-fail-1.rs:39:5
+   |
+LL |     type B = &'static Self::A;
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 5 previous errors
+
+For more information about this error, try `rustc --explain E0275`.
diff --git a/src/test/ui/associated-types/defaults-cyclic-fail-2.rs b/src/test/ui/associated-types/defaults-cyclic-fail-2.rs
new file mode 100644 (file)
index 0000000..2f2e84c
--- /dev/null
@@ -0,0 +1,49 @@
+// compile-fail
+
+#![feature(associated_type_defaults)]
+
+// A more complex version of `defaults-cyclic-fail-1.rs`, with non-trivial defaults.
+
+// Having a cycle in assoc. type defaults is okay...
+trait Tr {
+    type A = Vec<Self::B>;
+    type B = Box<Self::A>;
+}
+
+// ...but is an error in any impl that doesn't override at least one of the defaults
+impl Tr for () {}
+//~^ ERROR overflow evaluating the requirement
+
+// As soon as at least one is redefined, it works:
+impl Tr for u8 {
+    type A = u8;
+}
+
+impl Tr for u16 {
+    type B = ();
+}
+
+impl Tr for u32 {
+    type A = ();
+    type B = u8;
+}
+
+// ...but only if this actually breaks the cycle
+impl Tr for bool {
+//~^ ERROR overflow evaluating the requirement
+    type A = Box<Self::B>;
+    //~^ ERROR overflow evaluating the requirement
+}
+// (the error is shown twice for some reason)
+
+impl Tr for usize {
+//~^ ERROR overflow evaluating the requirement
+    type B = &'static Self::A;
+    //~^ ERROR overflow evaluating the requirement
+}
+
+fn main() {
+    // We don't check that the types project correctly because the cycle errors stop compilation
+    // before `main` is type-checked.
+    // `defaults-cyclic-pass-2.rs` does this.
+}
diff --git a/src/test/ui/associated-types/defaults-cyclic-fail-2.stderr b/src/test/ui/associated-types/defaults-cyclic-fail-2.stderr
new file mode 100644 (file)
index 0000000..bbc130f
--- /dev/null
@@ -0,0 +1,33 @@
+error[E0275]: overflow evaluating the requirement `<() as Tr>::B`
+  --> $DIR/defaults-cyclic-fail-2.rs:14:6
+   |
+LL | impl Tr for () {}
+   |      ^^
+
+error[E0275]: overflow evaluating the requirement `<bool as Tr>::B`
+  --> $DIR/defaults-cyclic-fail-2.rs:32:6
+   |
+LL | impl Tr for bool {
+   |      ^^
+
+error[E0275]: overflow evaluating the requirement `<usize as Tr>::B`
+  --> $DIR/defaults-cyclic-fail-2.rs:39:6
+   |
+LL | impl Tr for usize {
+   |      ^^
+
+error[E0275]: overflow evaluating the requirement `<bool as Tr>::B`
+  --> $DIR/defaults-cyclic-fail-2.rs:34:5
+   |
+LL |     type A = Box<Self::B>;
+   |     ^^^^^^^^^^^^^^^^^^^^^^
+
+error[E0275]: overflow evaluating the requirement `<usize as Tr>::A`
+  --> $DIR/defaults-cyclic-fail-2.rs:41:5
+   |
+LL |     type B = &'static Self::A;
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 5 previous errors
+
+For more information about this error, try `rustc --explain E0275`.
diff --git a/src/test/ui/associated-types/defaults-cyclic-fail.rs b/src/test/ui/associated-types/defaults-cyclic-fail.rs
deleted file mode 100644 (file)
index ab66fe0..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-#![feature(associated_type_defaults)]
-
-// Having a cycle in assoc. type defaults is okay...
-trait Tr {
-    type A = Self::B;
-    type B = Self::A;
-}
-
-// ...but is an error in any impl that doesn't override at least one of the defaults
-impl Tr for () {}
-//~^ ERROR overflow evaluating the requirement
-
-// As soon as at least one is redefined, it works:
-impl Tr for u8 {
-    type A = u8;
-}
-
-impl Tr for u32 {
-    type A = ();
-    type B = u8;
-}
-
-// ...but only if this actually breaks the cycle
-impl Tr for bool {
-//~^ ERROR overflow evaluating the requirement
-    type A = Box<Self::B>;
-    //~^ ERROR overflow evaluating the requirement
-}
-// (the error is shown twice for some reason)
-
-fn main() {
-    // Check that the overridden type propagates to the other
-    let _a: <u8 as Tr>::A = 0u8;
-    let _b: <u8 as Tr>::B = 0u8;
-}
diff --git a/src/test/ui/associated-types/defaults-cyclic-fail.stderr b/src/test/ui/associated-types/defaults-cyclic-fail.stderr
deleted file mode 100644 (file)
index dd0e5c2..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-error[E0275]: overflow evaluating the requirement `<() as Tr>::B`
-  --> $DIR/defaults-cyclic-fail.rs:10:6
-   |
-LL | impl Tr for () {}
-   |      ^^
-
-error[E0275]: overflow evaluating the requirement `<bool as Tr>::B`
-  --> $DIR/defaults-cyclic-fail.rs:24:6
-   |
-LL | impl Tr for bool {
-   |      ^^
-
-error[E0275]: overflow evaluating the requirement `<bool as Tr>::B`
-  --> $DIR/defaults-cyclic-fail.rs:26:5
-   |
-LL |     type A = Box<Self::B>;
-   |     ^^^^^^^^^^^^^^^^^^^^^^
-
-error: aborting due to 3 previous errors
-
-For more information about this error, try `rustc --explain E0275`.
diff --git a/src/test/ui/associated-types/defaults-cyclic-pass-1.rs b/src/test/ui/associated-types/defaults-cyclic-pass-1.rs
new file mode 100644 (file)
index 0000000..97c6e5b
--- /dev/null
@@ -0,0 +1,56 @@
+// check-pass
+
+#![feature(associated_type_defaults)]
+
+// Having a cycle in assoc. type defaults is okay, as long as there's no impl
+// that retains it.
+trait Tr {
+    type A = Self::B;
+    type B = Self::A;
+
+    fn f();
+}
+
+// An impl has to break the cycle to be accepted.
+impl Tr for u8 {
+    type A = u8;
+
+    fn f() {
+        // Check that the type propagates as expected (seen from inside the impl)
+        let _: Self::A = 0u8;
+        let _: Self::B = 0u8;
+    }
+}
+
+impl Tr for String {
+    type B = ();
+
+    fn f() {
+        // Check that the type propagates as expected (seen from inside the impl)
+        let _: Self::A = ();
+        let _: Self::B = ();
+    }
+}
+
+impl Tr for () {
+    type A = Vec<()>;
+    type B = u8;
+
+    fn f() {
+        // Check that the type propagates as expected (seen from inside the impl)
+        let _: Self::A = Vec::<()>::new();
+        let _: Self::B = 0u8;
+    }
+}
+
+fn main() {
+    // Check that both impls now have the right types (seen from outside the impls)
+    let _: <u8 as Tr>::A = 0u8;
+    let _: <u8 as Tr>::B = 0u8;
+
+    let _: <String as Tr>::A = ();
+    let _: <String as Tr>::B = ();
+
+    let _: <() as Tr>::A = Vec::<()>::new();
+    let _: <() as Tr>::B = 0u8;
+}
diff --git a/src/test/ui/associated-types/defaults-cyclic-pass-2.rs b/src/test/ui/associated-types/defaults-cyclic-pass-2.rs
new file mode 100644 (file)
index 0000000..69315a0
--- /dev/null
@@ -0,0 +1,56 @@
+// check-pass
+
+#![feature(associated_type_defaults)]
+
+// Having a cycle in assoc. type defaults is okay, as long as there's no impl
+// that retains it.
+trait Tr {
+    type A = Vec<Self::B>;
+    type B = Box<Self::A>;
+
+    fn f();
+}
+
+// An impl has to break the cycle to be accepted.
+impl Tr for u8 {
+    type A = u8;
+
+    fn f() {
+        // Check that the type propagates as expected (seen from inside the impl)
+        let _: Self::A = 0u8;
+        let _: Self::B = Box::new(0u8);
+    }
+}
+
+impl Tr for String {
+    type B = ();
+
+    fn f() {
+        // Check that the type propagates as expected (seen from inside the impl)
+        let _: Self::A = Vec::<()>::new();
+        let _: Self::B = ();
+    }
+}
+
+impl Tr for () {
+    type A = Vec<()>;
+    type B = u8;
+
+    fn f() {
+        // Check that the type propagates as expected (seen from inside the impl)
+        let _: Self::A = Vec::<()>::new();
+        let _: Self::B = 0u8;
+    }
+}
+
+fn main() {
+    // Check that both impls now have the right types (seen from outside the impls)
+    let _: <u8 as Tr>::A = 0u8;
+    let _: <u8 as Tr>::B = Box::new(0u8);
+
+    let _: <String as Tr>::A = Vec::<()>::new();
+    let _: <String as Tr>::B = ();
+
+    let _: <() as Tr>::A = Vec::<()>::new();
+    let _: <() as Tr>::B = 0u8;
+}
diff --git a/src/test/ui/associated-types/defaults-cyclic-pass.rs b/src/test/ui/associated-types/defaults-cyclic-pass.rs
deleted file mode 100644 (file)
index 74a0cfa..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-// check-pass
-
-#![feature(associated_type_defaults)]
-
-// Having a cycle in assoc. type defaults is okay, as long as there's no impl
-// that retains it.
-trait Tr {
-    type A = Self::B;
-    type B = Self::A;
-}
-
-// An impl has to break the cycle to be accepted.
-impl Tr for u8 {
-    type A = u8;
-}
-
-fn main() {}