]> git.proxmox.com Git - rustc.git/blob - src/test/ui/specialization/non-defaulted-item-fail.rs
New upstream version 1.46.0~beta.2+dfsg1
[rustc.git] / src / test / ui / specialization / non-defaulted-item-fail.rs
1 #![feature(specialization, associated_type_defaults)]
2 //~^ WARN the feature `specialization` is incomplete
3
4 // Test that attempting to override a non-default method or one not in the
5 // parent impl causes an error.
6
7 trait Foo {
8 type Ty = ();
9 const CONST: u8 = 123;
10 fn foo(&self) -> bool { true }
11 }
12
13 // Specialization tree for Foo:
14 //
15 // Box<T> Vec<T>
16 // / \ / \
17 // Box<i32> Box<i64> Vec<()> Vec<bool>
18
19 impl<T> Foo for Box<T> {
20 type Ty = bool;
21 const CONST: u8 = 0;
22 fn foo(&self) -> bool { false }
23 }
24
25 // Allowed
26 impl Foo for Box<i32> {}
27
28 // Can't override a non-`default` fn
29 impl Foo for Box<i64> {
30 type Ty = Vec<()>;
31 //~^ error: `Ty` specializes an item from a parent `impl`, but that item is not marked `default`
32 const CONST: u8 = 42;
33 //~^ error: `CONST` specializes an item from a parent `impl`, but that item is not marked `default`
34 fn foo(&self) -> bool { true }
35 //~^ error: `foo` specializes an item from a parent `impl`, but that item is not marked `default`
36 }
37
38
39 // Doesn't mention the item = provided body/value is used and the method is final.
40 impl<T> Foo for Vec<T> {}
41
42 // Allowed
43 impl Foo for Vec<()> {}
44
45 impl Foo for Vec<bool> {
46 type Ty = Vec<()>;
47 //~^ error: `Ty` specializes an item from a parent `impl`, but that item is not marked `default`
48 const CONST: u8 = 42;
49 //~^ error: `CONST` specializes an item from a parent `impl`, but that item is not marked `default`
50 fn foo(&self) -> bool { true }
51 //~^ error: `foo` specializes an item from a parent `impl`, but that item is not marked `default`
52 }
53
54 fn main() {}