]> git.lizzy.rs Git - rust.git/blob - src/test/ui/specialization/specialization-no-default.rs
57346b26d24ec2d8e85544aee516d8261e75dd1d
[rust.git] / src / test / ui / specialization / specialization-no-default.rs
1 #![feature(specialization)]
2
3 // Check a number of scenarios in which one impl tries to override another,
4 // without correctly using `default`.
5
6 // Test 1: one layer of specialization, multiple methods, missing `default`
7
8 trait Foo {
9     fn foo(&self);
10     fn bar(&self);
11 }
12
13 impl<T> Foo for T {
14     fn foo(&self) {}
15     fn bar(&self) {}
16 }
17
18 impl Foo for u8 {}
19 impl Foo for u16 {
20     fn foo(&self) {} //~ ERROR E0520
21 }
22 impl Foo for u32 {
23     fn bar(&self) {} //~ ERROR E0520
24 }
25
26 // Test 2: one layer of specialization, missing `default` on associated type
27
28 trait Bar {
29     type T;
30 }
31
32 impl<T> Bar for T {
33     type T = u8;
34 }
35
36 impl Bar for u8 {
37     type T = (); //~ ERROR E0520
38 }
39
40 // Test 3a: multiple layers of specialization, missing interior `default`
41
42 trait Baz {
43     fn baz(&self);
44 }
45
46 impl<T> Baz for T {
47     default fn baz(&self) {}
48 }
49
50 impl<T: Clone> Baz for T {
51     fn baz(&self) {}
52 }
53
54 impl Baz for i32 {
55     fn baz(&self) {} //~ ERROR E0520
56 }
57
58 // Test 3b: multiple layers of specialization, missing interior `default`,
59 // redundant `default` in bottom layer.
60
61 trait Redundant {
62     fn redundant(&self);
63 }
64
65 impl<T> Redundant for T {
66     default fn redundant(&self) {}
67 }
68
69 impl<T: Clone> Redundant for T {
70     fn redundant(&self) {}
71 }
72
73 impl Redundant for i32 {
74     default fn redundant(&self) {} //~ ERROR E0520
75 }
76
77 fn main() {}