]> git.lizzy.rs Git - rust.git/blob - src/test/ui/traits/wf-object/no-duplicates.rs
Rollup merge of #82179 - mbartlett21:patch-5, r=joshtriplett
[rust.git] / src / test / ui / traits / wf-object / 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 even though one could reasonably accept this.
3
4 // Some arbitrary object-safe trait:
5 trait Obj {}
6
7 // Demonstrate that recursive expansion of trait aliases doesn't affect stable behavior:
8 type _0 = dyn Obj + Obj;
9 //~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
10
11 // Some variations:
12
13 type _1 = dyn Send + Obj + Obj;
14 //~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
15
16 type _2 = dyn Obj + Send + Obj;
17 //~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
18
19 type _3 = dyn Obj + Send + Send; // But it is OK to duplicate auto traits.
20
21 // Take higher ranked types into account.
22
23 // Note that `'a` and `'b` are intentionally different to make sure we consider
24 // them semantically the same.
25 trait ObjL<'l> {}
26 type _4 = dyn for<'a> ObjL<'a> + for<'b> ObjL<'b>;
27 //~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
28
29 trait ObjT<T> {}
30 type _5 = dyn ObjT<for<'a> fn(&'a u8)> + ObjT<for<'b> fn(&'b u8)>;
31 //~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
32
33 fn main() {}