summaryrefslogtreecommitdiffstats
path: root/src/test/ui/traits/object/auto-dedup.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/traits/object/auto-dedup.rs
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/traits/object/auto-dedup.rs')
-rw-r--r--src/test/ui/traits/object/auto-dedup.rs46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/test/ui/traits/object/auto-dedup.rs b/src/test/ui/traits/object/auto-dedup.rs
new file mode 100644
index 000000000..39d25eb7f
--- /dev/null
+++ b/src/test/ui/traits/object/auto-dedup.rs
@@ -0,0 +1,46 @@
+// run-pass
+
+#![allow(unused_assignments)]
+
+// Test that duplicate auto trait bounds in trait objects don't create new types.
+#[allow(unused_assignments)]
+use std::marker::Send as SendAlias;
+
+// A dummy trait for the non-auto trait.
+trait Trait {}
+
+// A dummy struct to implement `Trait` and `Send`.
+struct Struct;
+
+impl Trait for Struct {}
+
+// These three functions should be equivalent.
+fn takes_dyn_trait_send(_: Box<dyn Trait + Send>) {}
+fn takes_dyn_trait_send_send(_: Box<dyn Trait + Send + Send>) {}
+fn takes_dyn_trait_send_sendalias(_: Box<dyn Trait + Send + SendAlias>) {}
+
+impl dyn Trait + Send + Send {
+ fn do_nothing(&self) {}
+}
+
+fn main() {
+ // 1. Moving into a variable with more `Send`s and back.
+ let mut dyn_trait_send = Box::new(Struct) as Box<dyn Trait + Send>;
+ let dyn_trait_send_send: Box<dyn Trait + Send + Send> = dyn_trait_send;
+ dyn_trait_send = dyn_trait_send_send;
+
+ // 2. Calling methods with different number of `Send`s.
+ let dyn_trait_send = Box::new(Struct) as Box<dyn Trait + Send>;
+ takes_dyn_trait_send_send(dyn_trait_send);
+
+ let dyn_trait_send_send = Box::new(Struct) as Box<dyn Trait + Send + Send>;
+ takes_dyn_trait_send(dyn_trait_send_send);
+
+ // 3. Aliases to the trait are transparent.
+ let dyn_trait_send = Box::new(Struct) as Box<dyn Trait + Send>;
+ takes_dyn_trait_send_sendalias(dyn_trait_send);
+
+ // 4. Calling an impl that duplicates an auto trait.
+ let dyn_trait_send = Box::new(Struct) as Box<dyn Trait + Send>;
+ dyn_trait_send.do_nothing();
+}