]> git.lizzy.rs Git - rust.git/blob - tests/ui/traits/object/auto-dedup.rs
Auto merge of #106646 - Amanieu:ilp32-object, r=Mark-Simulacrum
[rust.git] / tests / ui / traits / object / auto-dedup.rs
1 // run-pass
2
3 #![allow(unused_assignments)]
4
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;
8
9 // A dummy trait for the non-auto trait.
10 trait Trait {}
11
12 // A dummy struct to implement `Trait` and `Send`.
13 struct Struct;
14
15 impl Trait for Struct {}
16
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>) {}
21
22 impl dyn Trait + Send + Send {
23     fn do_nothing(&self) {}
24 }
25
26 fn main() {
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;
31
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);
35
36     let dyn_trait_send_send = Box::new(Struct) as Box<dyn Trait + Send + Send>;
37     takes_dyn_trait_send(dyn_trait_send_send);
38
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);
42
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();
46 }