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