Test interactions with specialization
This commit is contained in:
parent
de447eb9f2
commit
1e3c020063
2 changed files with 73 additions and 0 deletions
46
src/test/ui/associated-types/defaults-specialization.rs
Normal file
46
src/test/ui/associated-types/defaults-specialization.rs
Normal file
|
@ -0,0 +1,46 @@
|
|||
// compile-fail
|
||||
|
||||
#![feature(associated_type_defaults, specialization)]
|
||||
|
||||
trait Tr {
|
||||
type Ty = u8;
|
||||
|
||||
fn make() -> Self::Ty;
|
||||
}
|
||||
|
||||
struct A<T>(T);
|
||||
// In a `default impl`, assoc. types are defaulted as well,
|
||||
// so their values can't be assumed.
|
||||
default impl<T> Tr for A<T> {
|
||||
fn make() -> u8 { 0 }
|
||||
//~^ ERROR method `make` has an incompatible type for trait
|
||||
}
|
||||
|
||||
struct B<T>(T);
|
||||
// Explicitly defaulting the type does the same.
|
||||
impl<T> Tr for B<T> {
|
||||
default type Ty = bool;
|
||||
|
||||
fn make() -> bool { true }
|
||||
//~^ ERROR method `make` has an incompatible type for trait
|
||||
}
|
||||
|
||||
struct C<T>(T);
|
||||
// Only the method is defaulted, so this is fine.
|
||||
impl<T> Tr for C<T> {
|
||||
type Ty = bool;
|
||||
|
||||
default fn make() -> bool { true }
|
||||
}
|
||||
|
||||
// Defaulted method *can* assume the type, if the default is kept.
|
||||
struct D<T>(T);
|
||||
impl<T> Tr for D<T> {
|
||||
default fn make() -> u8 { 0 }
|
||||
}
|
||||
|
||||
impl Tr for D<bool> {
|
||||
fn make() -> u8 { 255 }
|
||||
}
|
||||
|
||||
fn main() {}
|
27
src/test/ui/associated-types/defaults-specialization.stderr
Normal file
27
src/test/ui/associated-types/defaults-specialization.stderr
Normal file
|
@ -0,0 +1,27 @@
|
|||
error[E0053]: method `make` has an incompatible type for trait
|
||||
--> $DIR/defaults-specialization.rs:15:18
|
||||
|
|
||||
LL | fn make() -> Self::Ty;
|
||||
| -------- type in trait
|
||||
...
|
||||
LL | fn make() -> u8 { 0 }
|
||||
| ^^ expected associated type, found u8
|
||||
|
|
||||
= note: expected type `fn() -> <A<T> as Tr>::Ty`
|
||||
found type `fn() -> u8`
|
||||
|
||||
error[E0053]: method `make` has an incompatible type for trait
|
||||
--> $DIR/defaults-specialization.rs:24:18
|
||||
|
|
||||
LL | fn make() -> Self::Ty;
|
||||
| -------- type in trait
|
||||
...
|
||||
LL | fn make() -> bool { true }
|
||||
| ^^^^ expected associated type, found bool
|
||||
|
|
||||
= note: expected type `fn() -> <B<T> as Tr>::Ty`
|
||||
found type `fn() -> bool`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0053`.
|
Loading…
Add table
Add a link
Reference in a new issue