-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Tweak where_clauses_object_safety lint to allow auto traits #66122
Tweak where_clauses_object_safety lint to allow auto traits #66122
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
While it is true that:
it also seems to me that this is complicating the type system by introducing more places in the typing rules where distinctions are drawn between regular traits and auto traits. Some language team discussion might be in order. |
Hmm. I spent a bit of time reading into the history of this lint. It feels very related to the other dyn-trait-related soundness hole we are working on. I agree with @Centril that I'd prefer not to "special case" auto traits here -- in fact, I'm not sure I understand yet why they are safe, even, because I've not brought this back into cache sufficiently. |
This comment has been minimized.
This comment has been minimized.
Yes, it's really unsound. We can't remove the check there, since it may not be possible to codegen the method if it uses a trait implementation that doesn't exist. |
Okay I see what I was missing. Thanks for clearing that up! Given my PR would allow the below it shouldn't be merged in it's current form; I'll have a closer look over the next week. #![feature(optin_builtin_traits)]
trait Trait {
fn foo(&self) where Self: Auto {}
}
impl Trait for () {}
auto trait Auto {}
trait Nobody {}
impl<T> Auto for T where T: Nobody {}
impl Auto for dyn Trait {}
fn main() {
<dyn Trait>::foo(&())
} |
Rather than "forbid traits" or "forbid non-auto traits", it seems this lint should be "forbid traits that are implemented on |
Ping from triage: |
This tweaks the lint of #51443 to not fire when all the bounds are auto traits.
Auto traits do not impact vtables, and as discussed in that issue, the lint firing in cases like this is a false positive.
This example currently errors, but succeeds with this commit:
(Playground)
Errors: