]> git.lizzy.rs Git - rust.git/blob - src/test/ui/traits/alias/no-duplicates.rs
Rollup merge of #100953 - joshtriplett:write-docs, r=Mark-Simulacrum
[rust.git] / src / test / ui / traits / alias / no-duplicates.rs
1 // The purpose of this test is to demonstrate that duplicating object safe traits
2 // that are not auto traits is rejected with trait aliases even though one could
3 // reasonably accept this.
4
5 #![feature(trait_alias)]
6
7 use std::marker::Unpin;
8
9 // Some arbitrary object-safe trait:
10 trait Obj {}
11
12 // Nest a few levels deep:
13 trait _0 = Obj;
14 trait _1 = _0;
15
16 type _T00 = dyn _0 + _0;
17 //~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
18
19 type _T01 = dyn _1 + _0;
20 //~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
21
22 type _T02 = dyn _1 + _1;
23 //~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
24
25 type _T03 = dyn Obj + _1;
26 //~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
27
28 type _T04 = dyn _1 + Obj;
29 //~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
30
31 // Nest some more and in weird ways:
32
33 trait _2 = _0 + _1;
34 trait _3 = Obj;
35 trait _4 = _3;
36
37 type _T10 = dyn _2 + _3;
38 //~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
39
40 type _T11 = dyn _3 + _2;
41 //~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
42
43 type _T12 = dyn Obj + _2;
44 //~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
45
46 type _T13 = dyn _2 + Obj;
47 //~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
48
49 type _T14 = dyn _1 + _3;
50 //~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
51
52 type _T15 = dyn _3 + _1;
53 //~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
54
55 type _T16 = dyn _1 + _4;
56 //~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
57
58 type _T17 = dyn _4 + _1;
59 //~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
60
61 // Include auto traits:
62
63 trait _5 = Obj + Send;
64
65 type _T20 = dyn _5 + _5;
66 //~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
67
68 type _T21 = dyn Obj + _5;
69 //~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
70
71 type _T22 = dyn _5 + Obj;
72 //~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
73
74 type _T23 = dyn _5 + Send + Sync + Obj;
75 //~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
76
77 // Also nest:
78
79 trait _6 = _5 + _5; // ==> Obj + Send + Obj + Send
80
81 type _T30 = dyn _6;
82 //~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
83
84 type _T31 = dyn _6 + Send;
85 //~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
86
87 type _T32 = dyn Send + _6;
88 //~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
89
90 // Nest some more:
91
92 trait _7 = _5 + Sync;
93 trait _8 = Unpin + _7;
94
95 type _T40 = dyn _8 + Obj;
96 //~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
97
98 type _T41 = dyn Obj + _8;
99 //~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
100
101 type _T42 = dyn _8 + _4;
102 //~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
103
104 type _T43 = dyn _4 + _8;
105 //~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
106
107 type _T44 = dyn _4 + Send + Sync + _8;
108 //~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
109
110 // Take higher ranked types into account.
111
112 // Note that `'a` and `'b` are intentionally different to make sure we consider
113 // them semantically the same.
114 trait ObjL<'l> {}
115 trait _9 = for<'a> ObjL<'a>;
116 trait _10 = for<'b> ObjL<'b>;
117 type _T50 = dyn _9 + _10;
118 //~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
119
120 trait ObjT<T> {}
121 trait _11 = ObjT<for<'a> fn(&'a u8)>;
122 trait _12 = ObjT<for<'b> fn(&'b u8)>;
123 type _T60 = dyn _11 + _12;
124 //~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
125
126 fn main() {}