-
Notifications
You must be signed in to change notification settings - Fork 13.3k
discard default auto trait impls if explicit ones exist (rebase of #85048) #113312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3adedc9
b5b3f33
944f237
3715934
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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> {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would be worth a comment explaining what is being tested: that the manual There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure how much explanation makes sense here, though a "Tests that we don't incorrectly allow overlap between a builtin auto trait impl and a user written one. See #83857 for more details." would be good here. |
||
|
||
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); | ||
} |
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`. |
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() {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, this is wrong for opaque types 😅 we need to always emit consider
AutoImplCandidate
s for them if they don't also have aProjectionCandidate
. This is a bit of a mess in the old solver.The issue is that we consider all impls to potentially apply for opaque types, but we should instead actually leak their underlying type and check whether it implements the auto trait
cc @compiler-errors given that we've recently talked about auto traits and opaques :>