From fbcd136b655c2743d3a8c3aa87e460ac38d57046 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Sun, 15 Sep 2019 01:18:37 +0200 Subject: [PATCH] Improve the cycle tests --- ...clic-fail.rs => defaults-cyclic-fail-1.rs} | 18 ++++-- .../defaults-cyclic-fail-1.stderr | 33 +++++++++++ .../defaults-cyclic-fail-2.rs | 49 ++++++++++++++++ .../defaults-cyclic-fail-2.stderr | 33 +++++++++++ .../defaults-cyclic-fail.stderr | 21 ------- .../defaults-cyclic-pass-1.rs | 56 +++++++++++++++++++ .../defaults-cyclic-pass-2.rs | 56 +++++++++++++++++++ .../associated-types/defaults-cyclic-pass.rs | 17 ------ 8 files changed, 241 insertions(+), 42 deletions(-) rename src/test/ui/associated-types/{defaults-cyclic-fail.rs => defaults-cyclic-fail-1.rs} (65%) create mode 100644 src/test/ui/associated-types/defaults-cyclic-fail-1.stderr create mode 100644 src/test/ui/associated-types/defaults-cyclic-fail-2.rs create mode 100644 src/test/ui/associated-types/defaults-cyclic-fail-2.stderr delete mode 100644 src/test/ui/associated-types/defaults-cyclic-fail.stderr create mode 100644 src/test/ui/associated-types/defaults-cyclic-pass-1.rs create mode 100644 src/test/ui/associated-types/defaults-cyclic-pass-2.rs delete mode 100644 src/test/ui/associated-types/defaults-cyclic-pass.rs diff --git a/src/test/ui/associated-types/defaults-cyclic-fail.rs b/src/test/ui/associated-types/defaults-cyclic-fail-1.rs similarity index 65% rename from src/test/ui/associated-types/defaults-cyclic-fail.rs rename to 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) -fn main() { - // Check that the overridden type propagates to the other - let _a: ::A = 0u8; - let _b: ::B = 0u8; +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 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 `::B` + --> $DIR/defaults-cyclic-fail-1.rs:30:6 + | +LL | impl Tr for bool { + | ^^ + +error[E0275]: overflow evaluating the requirement `::B` + --> $DIR/defaults-cyclic-fail-1.rs:37:6 + | +LL | impl Tr for usize { + | ^^ + +error[E0275]: overflow evaluating the requirement `::B` + --> $DIR/defaults-cyclic-fail-1.rs:32:5 + | +LL | type A = Box; + | ^^^^^^^^^^^^^^^^^^^^^^ + +error[E0275]: overflow evaluating the requirement `::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; + type B = Box; +} + +// ...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; + //~^ 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 `::B` + --> $DIR/defaults-cyclic-fail-2.rs:32:6 + | +LL | impl Tr for bool { + | ^^ + +error[E0275]: overflow evaluating the requirement `::B` + --> $DIR/defaults-cyclic-fail-2.rs:39:6 + | +LL | impl Tr for usize { + | ^^ + +error[E0275]: overflow evaluating the requirement `::B` + --> $DIR/defaults-cyclic-fail-2.rs:34:5 + | +LL | type A = Box; + | ^^^^^^^^^^^^^^^^^^^^^^ + +error[E0275]: overflow evaluating the requirement `::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 `::B` - --> $DIR/defaults-cyclic-fail.rs:24:6 - | -LL | impl Tr for bool { - | ^^ - -error[E0275]: overflow evaluating the requirement `::B` - --> $DIR/defaults-cyclic-fail.rs:26:5 - | -LL | type A = Box; - | ^^^^^^^^^^^^^^^^^^^^^^ - -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 _: ::A = 0u8; + let _: ::B = 0u8; + + let _: ::A = (); + let _: ::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; + type B = Box; + + 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 _: ::A = 0u8; + let _: ::B = Box::new(0u8); + + let _: ::A = Vec::<()>::new(); + let _: ::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() {}