diff options
| author | Jonas Schievink <jonasschievink@gmail.com> | 2019-06-14 21:59:11 +0200 |
|---|---|---|
| committer | Jonas Schievink <jonasschievink@gmail.com> | 2020-02-21 19:41:21 +0100 |
| commit | d3be26d6a8eaf3b5a7c22ba2324ef0751835ce26 (patch) | |
| tree | 98d58d19c1f9136fd2ccb75b9a5b5bda7aed97e7 | |
| parent | 1e3c02006372ca68d07d32493660583cc1c9e12c (diff) | |
| download | rust-d3be26d6a8eaf3b5a7c22ba2324ef0751835ce26.tar.gz rust-d3be26d6a8eaf3b5a7c22ba2324ef0751835ce26.zip | |
Improve test
| -rw-r--r-- | src/test/ui/associated-types/defaults-specialization.rs | 18 | ||||
| -rw-r--r-- | src/test/ui/associated-types/defaults-specialization.stderr | 31 |
2 files changed, 45 insertions, 4 deletions
diff --git a/src/test/ui/associated-types/defaults-specialization.rs b/src/test/ui/associated-types/defaults-specialization.rs index c8aab8fb3ec..e3a5db0960c 100644 --- a/src/test/ui/associated-types/defaults-specialization.rs +++ b/src/test/ui/associated-types/defaults-specialization.rs @@ -1,3 +1,5 @@ +//! Tests the interaction of associated type defaults and specialization. + // compile-fail #![feature(associated_type_defaults, specialization)] @@ -16,6 +18,13 @@ default impl<T> Tr for A<T> { //~^ ERROR method `make` has an incompatible type for trait } +struct A2<T>(T); +// ...same, but in the method body +default impl<T> Tr for A2<T> { + fn make() -> Self::Ty { 0u8 } + //~^ ERROR mismatched types +} + struct B<T>(T); // Explicitly defaulting the type does the same. impl<T> Tr for B<T> { @@ -25,6 +34,15 @@ impl<T> Tr for B<T> { //~^ ERROR method `make` has an incompatible type for trait } +struct B2<T>(T); +// ...same, but in the method body +impl<T> Tr for B2<T> { + default type Ty = bool; + + fn make() -> Self::Ty { true } + //~^ ERROR mismatched types +} + struct C<T>(T); // Only the method is defaulted, so this is fine. impl<T> Tr for C<T> { diff --git a/src/test/ui/associated-types/defaults-specialization.stderr b/src/test/ui/associated-types/defaults-specialization.stderr index 0e6711780f8..2b2adfdb7c9 100644 --- a/src/test/ui/associated-types/defaults-specialization.stderr +++ b/src/test/ui/associated-types/defaults-specialization.stderr @@ -1,5 +1,5 @@ error[E0053]: method `make` has an incompatible type for trait - --> $DIR/defaults-specialization.rs:15:18 + --> $DIR/defaults-specialization.rs:17:18 | LL | fn make() -> Self::Ty; | -------- type in trait @@ -11,7 +11,7 @@ LL | fn make() -> u8 { 0 } found type `fn() -> u8` error[E0053]: method `make` has an incompatible type for trait - --> $DIR/defaults-specialization.rs:24:18 + --> $DIR/defaults-specialization.rs:33:18 | LL | fn make() -> Self::Ty; | -------- type in trait @@ -22,6 +22,29 @@ LL | fn make() -> bool { true } = note: expected type `fn() -> <B<T> as Tr>::Ty` found type `fn() -> bool` -error: aborting due to 2 previous errors +error[E0308]: mismatched types + --> $DIR/defaults-specialization.rs:24:29 + | +LL | fn make() -> Self::Ty { 0u8 } + | -------- ^^^ expected associated type, found u8 + | | + | expected `<A2<T> as Tr>::Ty` because of return type + | + = note: expected type `<A2<T> as Tr>::Ty` + found type `u8` + +error[E0308]: mismatched types + --> $DIR/defaults-specialization.rs:42:29 + | +LL | fn make() -> Self::Ty { true } + | -------- ^^^^ expected associated type, found bool + | | + | expected `<B2<T> as Tr>::Ty` because of return type + | + = note: expected type `<B2<T> as Tr>::Ty` + found type `bool` + +error: aborting due to 4 previous errors -For more information about this error, try `rustc --explain E0053`. +Some errors have detailed explanations: E0053, E0308. +For more information about an error, try `rustc --explain E0053`. |
