about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJonas Schievink <jonasschievink@gmail.com>2019-09-15 01:18:37 +0200
committerJonas Schievink <jonasschievink@gmail.com>2020-02-21 19:41:22 +0100
commitfbcd136b655c2743d3a8c3aa87e460ac38d57046 (patch)
tree453f729c628f22338ae5e17697199be041e93424
parentf40879408cb055fc078912ca226ac0a41ddb61ce (diff)
downloadrust-fbcd136b655c2743d3a8c3aa87e460ac38d57046.tar.gz
rust-fbcd136b655c2743d3a8c3aa87e460ac38d57046.zip
Improve the cycle tests
-rw-r--r--src/test/ui/associated-types/defaults-cyclic-fail-1.rs (renamed from src/test/ui/associated-types/defaults-cyclic-fail.rs)16
-rw-r--r--src/test/ui/associated-types/defaults-cyclic-fail-1.stderr33
-rw-r--r--src/test/ui/associated-types/defaults-cyclic-fail-2.rs49
-rw-r--r--src/test/ui/associated-types/defaults-cyclic-fail-2.stderr33
-rw-r--r--src/test/ui/associated-types/defaults-cyclic-fail.stderr21
-rw-r--r--src/test/ui/associated-types/defaults-cyclic-pass-1.rs56
-rw-r--r--src/test/ui/associated-types/defaults-cyclic-pass-2.rs56
-rw-r--r--src/test/ui/associated-types/defaults-cyclic-pass.rs17
8 files changed, 240 insertions, 41 deletions
diff --git a/src/test/ui/associated-types/defaults-cyclic-fail.rs b/src/test/ui/associated-types/defaults-cyclic-fail-1.rs
index ab66fe0b52e..71ac914ef57 100644
--- a/src/test/ui/associated-types/defaults-cyclic-fail.rs
+++ b/src/test/ui/associated-types/defaults-cyclic-fail-1.rs
@@ -15,6 +15,10 @@ impl Tr for u8 {
     type A = u8;
 }
 
+impl Tr for u16 {
+    type B = ();
+}
+
 impl Tr for u32 {
     type A = ();
     type B = u8;
@@ -28,8 +32,14 @@ impl Tr for bool {
 }
 // (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() {
-    // Check that the overridden type propagates to the other
-    let _a: <u8 as Tr>::A = 0u8;
-    let _b: <u8 as Tr>::B = 0u8;
+    // 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
index 00000000000..4f28a50701a
--- /dev/null
+++ b/src/test/ui/associated-types/defaults-cyclic-fail-1.stderr
@@ -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
index 00000000000..2f2e84c6000
--- /dev/null
+++ b/src/test/ui/associated-types/defaults-cyclic-fail-2.rs
@@ -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
index 00000000000..bbc130f11f7
--- /dev/null
+++ b/src/test/ui/associated-types/defaults-cyclic-fail-2.stderr
@@ -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.stderr b/src/test/ui/associated-types/defaults-cyclic-fail.stderr
deleted file mode 100644
index dd0e5c2ef42..00000000000
--- a/src/test/ui/associated-types/defaults-cyclic-fail.stderr
+++ /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
index 00000000000..97c6e5bade2
--- /dev/null
+++ b/src/test/ui/associated-types/defaults-cyclic-pass-1.rs
@@ -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
index 00000000000..69315a02210
--- /dev/null
+++ b/src/test/ui/associated-types/defaults-cyclic-pass-2.rs
@@ -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
index 74a0cfa6b73..00000000000
--- a/src/test/ui/associated-types/defaults-cyclic-pass.rs
+++ /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() {}