]> git.lizzy.rs Git - rust.git/blob - src/test/ui/specialization/specialization-no-default.rs
Rollup merge of #57107 - mjbshaw:thread_local_test, r=nikomatsakis
[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 ////////////////////////////////////////////////////////////////////////////////
7 // Test 1: one layer of specialization, multiple methods, missing `default`
8 ////////////////////////////////////////////////////////////////////////////////
9
10 trait Foo {
11     fn foo(&self);
12     fn bar(&self);
13 }
14
15 impl<T> Foo for T {
16     fn foo(&self) {}
17     fn bar(&self) {}
18 }
19
20 impl Foo for u8 {}
21 impl Foo for u16 {
22     fn foo(&self) {} //~ ERROR E0520
23 }
24 impl Foo for u32 {
25     fn bar(&self) {} //~ ERROR E0520
26 }
27
28 ////////////////////////////////////////////////////////////////////////////////
29 // Test 2: one layer of specialization, missing `default` on associated type
30 ////////////////////////////////////////////////////////////////////////////////
31
32 trait Bar {
33     type T;
34 }
35
36 impl<T> Bar for T {
37     type T = u8;
38 }
39
40 impl Bar for u8 {
41     type T = (); //~ ERROR E0520
42 }
43
44 ////////////////////////////////////////////////////////////////////////////////
45 // Test 3a: multiple layers of specialization, missing interior `default`
46 ////////////////////////////////////////////////////////////////////////////////
47
48 trait Baz {
49     fn baz(&self);
50 }
51
52 impl<T> Baz for T {
53     default fn baz(&self) {}
54 }
55
56 impl<T: Clone> Baz for T {
57     fn baz(&self) {}
58 }
59
60 impl Baz for i32 {
61     fn baz(&self) {} //~ ERROR E0520
62 }
63
64 ////////////////////////////////////////////////////////////////////////////////
65 // Test 3b: multiple layers of specialization, missing interior `default`,
66 // redundant `default` in bottom layer.
67 ////////////////////////////////////////////////////////////////////////////////
68
69 trait Redundant {
70     fn redundant(&self);
71 }
72
73 impl<T> Redundant for T {
74     default fn redundant(&self) {}
75 }
76
77 impl<T: Clone> Redundant for T {
78     fn redundant(&self) {}
79 }
80
81 impl Redundant for i32 {
82     default fn redundant(&self) {} //~ ERROR E0520
83 }
84
85 fn main() {}