3 #![allow(unused_assignments)]
5 // Test that duplicate auto trait bounds in trait objects don't create new types.
6 #[allow(unused_assignments)]
7 use std::marker::Send as SendAlias;
9 // A dummy trait for the non-auto trait.
12 // A dummy struct to implement `Trait` and `Send`.
15 impl Trait for Struct {}
17 // These three functions should be equivalent.
18 fn takes_dyn_trait_send(_: Box<dyn Trait + Send>) {}
19 fn takes_dyn_trait_send_send(_: Box<dyn Trait + Send + Send>) {}
20 fn takes_dyn_trait_send_sendalias(_: Box<dyn Trait + Send + SendAlias>) {}
22 impl dyn Trait + Send + Send {
23 fn do_nothing(&self) {}
27 // 1. Moving into a variable with more `Send`s and back.
28 let mut dyn_trait_send = Box::new(Struct) as Box<dyn Trait + Send>;
29 let dyn_trait_send_send: Box<dyn Trait + Send + Send> = dyn_trait_send;
30 dyn_trait_send = dyn_trait_send_send;
32 // 2. Calling methods with different number of `Send`s.
33 let dyn_trait_send = Box::new(Struct) as Box<dyn Trait + Send>;
34 takes_dyn_trait_send_send(dyn_trait_send);
36 let dyn_trait_send_send = Box::new(Struct) as Box<dyn Trait + Send + Send>;
37 takes_dyn_trait_send(dyn_trait_send_send);
39 // 3. Aliases to the trait are transparent.
40 let dyn_trait_send = Box::new(Struct) as Box<dyn Trait + Send>;
41 takes_dyn_trait_send_sendalias(dyn_trait_send);
43 // 4. Calling an impl that duplicates an auto trait.
44 let dyn_trait_send = Box::new(Struct) as Box<dyn Trait + Send>;
45 dyn_trait_send.do_nothing();