-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #113312 - Ddystopia:auto-trait-fun, r=lcnr
- Loading branch information
Showing
8 changed files
with
146 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// check-pass | ||
fn is_send<T: Send>(_: T) {} | ||
fn foo() -> impl Send { | ||
if false { | ||
is_send(foo()); | ||
} | ||
() | ||
} | ||
|
||
fn main() {} |