2019-09-18 17:54:47 -05:00
|
|
|
#![feature(specialization, associated_type_defaults)]
|
2019-09-18 17:37:28 -05:00
|
|
|
|
|
|
|
// Test that attempting to override a non-default method or one not in the
|
2019-09-18 17:54:47 -05:00
|
|
|
// parent impl causes an error.
|
2019-09-18 17:37:28 -05:00
|
|
|
|
|
|
|
trait Foo {
|
2019-09-18 17:54:47 -05:00
|
|
|
type Ty = ();
|
|
|
|
const CONST: u8 = 123;
|
2019-09-18 17:37:28 -05:00
|
|
|
fn foo(&self) -> bool { true }
|
|
|
|
}
|
|
|
|
|
|
|
|
// Specialization tree for Foo:
|
|
|
|
//
|
|
|
|
// Box<T> Vec<T>
|
|
|
|
// / \ / \
|
|
|
|
// Box<i32> Box<i64> Vec<()> Vec<bool>
|
|
|
|
|
|
|
|
impl<T> Foo for Box<T> {
|
2019-09-18 17:54:47 -05:00
|
|
|
type Ty = bool;
|
|
|
|
const CONST: u8 = 0;
|
2019-09-18 17:37:28 -05:00
|
|
|
fn foo(&self) -> bool { false }
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allowed
|
|
|
|
impl Foo for Box<i32> {}
|
|
|
|
|
|
|
|
// Can't override a non-`default` fn
|
|
|
|
impl Foo for Box<i64> {
|
2019-09-18 17:54:47 -05:00
|
|
|
type Ty = Vec<()>;
|
|
|
|
//~^ error: `Ty` specializes an item from a parent `impl`, but that item is not marked `default`
|
|
|
|
const CONST: u8 = 42;
|
|
|
|
//~^ error: `CONST` specializes an item from a parent `impl`, but that item is not marked `default`
|
2019-09-18 17:37:28 -05:00
|
|
|
fn foo(&self) -> bool { true }
|
2019-09-18 17:42:50 -05:00
|
|
|
//~^ error: `foo` specializes an item from a parent `impl`, but that item is not marked `default`
|
2019-09-18 17:37:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-18 17:54:47 -05:00
|
|
|
// Doesn't mention the item = provided body/value is used and the method is final.
|
2019-09-18 17:37:28 -05:00
|
|
|
impl<T> Foo for Vec<T> {}
|
|
|
|
|
|
|
|
// Allowed
|
|
|
|
impl Foo for Vec<()> {}
|
|
|
|
|
|
|
|
impl Foo for Vec<bool> {
|
2019-09-18 17:54:47 -05:00
|
|
|
type Ty = Vec<()>;
|
|
|
|
//~^ error: `Ty` specializes an item from a parent `impl`, but that item is not marked `default`
|
|
|
|
const CONST: u8 = 42;
|
|
|
|
//~^ error: `CONST` specializes an item from a parent `impl`, but that item is not marked `default`
|
2019-09-18 17:37:28 -05:00
|
|
|
fn foo(&self) -> bool { true }
|
2019-09-18 17:42:50 -05:00
|
|
|
//~^ error: `foo` specializes an item from a parent `impl`, but that item is not marked `default`
|
2019-09-18 17:37:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {}
|