From d3be26d6a8eaf3b5a7c22ba2324ef0751835ce26 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Fri, 14 Jun 2019 21:59:11 +0200 Subject: [PATCH] Improve test --- .../defaults-specialization.rs | 18 +++++++++++ .../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 Tr for A { //~^ ERROR method `make` has an incompatible type for trait } +struct A2(T); +// ...same, but in the method body +default impl Tr for A2 { + fn make() -> Self::Ty { 0u8 } + //~^ ERROR mismatched types +} + struct B(T); // Explicitly defaulting the type does the same. impl Tr for B { @@ -25,6 +34,15 @@ impl Tr for B { //~^ ERROR method `make` has an incompatible type for trait } +struct B2(T); +// ...same, but in the method body +impl Tr for B2 { + default type Ty = bool; + + fn make() -> Self::Ty { true } + //~^ ERROR mismatched types +} + struct C(T); // Only the method is defaulted, so this is fine. impl Tr for C { 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() -> 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 ` as Tr>::Ty` because of return type + | + = note: expected type ` as Tr>::Ty` + found type `u8` -For more information about this error, try `rustc --explain E0053`. +error[E0308]: mismatched types + --> $DIR/defaults-specialization.rs:42:29 + | +LL | fn make() -> Self::Ty { true } + | -------- ^^^^ expected associated type, found bool + | | + | expected ` as Tr>::Ty` because of return type + | + = note: expected type ` as Tr>::Ty` + found type `bool` + +error: aborting due to 4 previous errors + +Some errors have detailed explanations: E0053, E0308. +For more information about an error, try `rustc --explain E0053`.