about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-07-28 10:41:00 +0000
committerbors <bors@rust-lang.org>2023-07-28 10:41:00 +0000
commite4c98caffe505630f8531fbb73949b40db918a48 (patch)
treef213a36bfeeaac02bd4801280b36a09e71e6da03 /tests
parentaafd75a9c510b0e91746b891eb4ebade43899af5 (diff)
parent37159345a74797316deb0b6f911d48b7243bba77 (diff)
downloadrust-e4c98caffe505630f8531fbb73949b40db918a48.tar.gz
rust-e4c98caffe505630f8531fbb73949b40db918a48.zip
Auto merge of #113312 - Ddystopia:auto-trait-fun, r=lcnr
discard default auto trait impls if explicit ones exist (rebase of #85048)

Rebase of #85048
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/auto-traits/issue-83857-ub.rs31
-rw-r--r--tests/ui/auto-traits/issue-83857-ub.stderr22
-rw-r--r--tests/ui/generator/auto-trait-regions.rs6
-rw-r--r--tests/ui/impl-trait/auto-trait-leak0
-rw-r--r--tests/ui/impl-trait/recursive-auto-trait.rs10
5 files changed, 66 insertions, 3 deletions
diff --git a/tests/ui/auto-traits/issue-83857-ub.rs b/tests/ui/auto-traits/issue-83857-ub.rs
new file mode 100644
index 00000000000..0a8865295c6
--- /dev/null
+++ b/tests/ui/auto-traits/issue-83857-ub.rs
@@ -0,0 +1,31 @@
+#![allow(suspicious_auto_trait_impls)]
+
+struct Always<T, U>(T, U);
+unsafe impl<T, U> Send for Always<T, U> {}
+struct Foo<T, U>(Always<T, U>);
+
+trait False {}
+unsafe impl<U: False> Send for Foo<u32, U> {}
+
+trait WithAssoc {
+    type Output;
+}
+impl<T: Send> WithAssoc for T {
+    type Output = Self;
+}
+impl WithAssoc for Foo<u32, ()> {
+    type Output = Box<i32>;
+}
+
+fn generic<T, U>(v: Foo<T, U>, f: fn(<Foo<T, U> as WithAssoc>::Output) -> i32) {
+    //~^ ERROR `Foo<T, U>` cannot be sent between threads safely
+    f(foo(v));
+}
+
+fn foo<T: Send>(x: T) -> <T as WithAssoc>::Output {
+    x
+}
+
+fn main() {
+    generic(Foo(Always(0, ())), |b| *b);
+}
diff --git a/tests/ui/auto-traits/issue-83857-ub.stderr b/tests/ui/auto-traits/issue-83857-ub.stderr
new file mode 100644
index 00000000000..d2aef17e7f8
--- /dev/null
+++ b/tests/ui/auto-traits/issue-83857-ub.stderr
@@ -0,0 +1,22 @@
+error[E0277]: `Foo<T, U>` cannot be sent between threads safely
+  --> $DIR/issue-83857-ub.rs:20:38
+   |
+LL | fn generic<T, U>(v: Foo<T, U>, f: fn(<Foo<T, U> as WithAssoc>::Output) -> i32) {
+   |                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Foo<T, U>` cannot be sent between threads safely
+   |
+   = help: the trait `Send` is not implemented for `Foo<T, U>`
+note: required for `Foo<T, U>` to implement `WithAssoc`
+  --> $DIR/issue-83857-ub.rs:13:15
+   |
+LL | impl<T: Send> WithAssoc for T {
+   |         ----  ^^^^^^^^^     ^
+   |         |
+   |         unsatisfied trait bound introduced here
+help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
+   |
+LL | fn generic<T, U>(v: Foo<T, U>, f: fn(<Foo<T, U> as WithAssoc>::Output) -> i32) where Foo<T, U>: Send {
+   |                                                                                +++++++++++++++++++++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/generator/auto-trait-regions.rs b/tests/ui/generator/auto-trait-regions.rs
index fd13e41319f..350f3cc34ce 100644
--- a/tests/ui/generator/auto-trait-regions.rs
+++ b/tests/ui/generator/auto-trait-regions.rs
@@ -26,7 +26,7 @@ fn assert_foo<T: Foo>(f: T) {}
 fn main() {
     // Make sure 'static is erased for generator interiors so we can't match it in trait selection
     let x: &'static _ = &OnlyFooIfStaticRef(No);
-    let gen = || {
+    let gen = move || {
         let x = x;
         yield;
         assert_foo(x);
@@ -36,7 +36,7 @@ fn main() {
 
     // Allow impls which matches any lifetime
     let x = &OnlyFooIfRef(No);
-    let gen = || {
+    let gen = move || {
         let x = x;
         yield;
         assert_foo(x);
@@ -44,7 +44,7 @@ fn main() {
     assert_foo(gen); // ok
 
     // Disallow impls which relates lifetimes in the generator interior
-    let gen = || {
+    let gen = move || {
         let a = A(&mut true, &mut true, No);
         //~^ temporary value dropped while borrowed
         //~| temporary value dropped while borrowed
diff --git a/tests/ui/impl-trait/auto-trait-leak b/tests/ui/impl-trait/auto-trait-leak
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/tests/ui/impl-trait/auto-trait-leak
diff --git a/tests/ui/impl-trait/recursive-auto-trait.rs b/tests/ui/impl-trait/recursive-auto-trait.rs
new file mode 100644
index 00000000000..d7b68144ff6
--- /dev/null
+++ b/tests/ui/impl-trait/recursive-auto-trait.rs
@@ -0,0 +1,10 @@
+// check-pass
+fn is_send<T: Send>(_: T) {}
+fn foo() -> impl Send {
+    if false {
+        is_send(foo());
+    }
+    ()
+}
+
+fn main() {}