-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
auto trait candidate selection is unsound #84857
Comments
modifying main to the following this unsoundness exists since version 1.0 fn main() {
fn deref(b: Box<i32>) -> i32 {
*b
}
generic(Foo(Always(0, ())), deref);
} |
Using e.g. @rustbot label A-traits, T-compiler |
I think there was some discussion previously in wg-traits that an implicit impl should never be considered if there is an explicit impl. And I think that makes sense and would fix this. It isn't fully backwards compatible though, but I'm unsure how often that would get run into in practice. |
Assigning priority as discussed as part of the Prioritization Working Group procedure and removing @rustbot label -I-prioritize +P-high |
a more beautiful example ✨ https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=7dcd002a139a2c2d18b2651aeca8a7c0 |
Work seems to be ongoing in #93367, including a lint that fires today, so at least people are aware of the issue, I hope. |
The current status here is that there's a lint (#93367) which warns on impls which will change behavior due to the fix. Actually landing the fix breaks some crates and keeping the behavior of I just saw that @kornelski actually rewrote imagequant to silence the lint in ImageOptim/libimagequant@d69cbfd in a way which does not rely on So maybe we don't actually have to land the new solver for this. Going to mentor someone to:
Please open a thread in #t-types on zulip if you get stuck |
Hello, can I give it a try? |
fixed by #113312 |
There are two impls of
Send
forFoo
, the explicitimpl<U: False> Send for Foo<u32, U>
and the implicit one if all fields areSend
. The implicit one always holds in this example.Candidate selection only acknowledges the existence of the implicit impl if the explicit one is known to not apply even when ignoring where bounds.
For
Foo<T, U>: Send
candidate selection can't useimpl<U: False> Send for Foo<u32, U>
, becauseFoo<T, U>
is more generic thanFoo<u32, U>
. So we use the implicit impl which always applies.For
Foo<u32, ()>
the explicit impl does apply, ignoring where bounds. This impl gets rejected however, as(): False
does not hold. As we don't consider the implicit impl in this case we therefore acceptimpl WithAssoc for Foo<u32, ()>
during coherence.We now have two arbitrary overlapping impls which is unsound.
The text was updated successfully, but these errors were encountered: