-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
defaulted traits ought to be have more restrictive coherence rules #22978
Comments
triage: P-backcompat-lang (1.0 Beta) |
@nikomatsakis Apologies for dredging up a very old issue, but I'm looking into writing diagnostics in this area and I wanted to check to be certain: in your example:
Should the final line be |
Yes, that is a typo. It should be Foo not Send. Niko -------- Original message -------- From: Alisdair Owens [email protected] Date:09/04/2015 14:26 (GMT-05:00) To: rust-lang/rust [email protected] Cc: Niko Matsakis [email protected] Subject: Re: [rust] defaulted traits ought to be have more restrictive
coherence rules (#22978) struct A { } — |
Fab, thanks! |
We initially had some rules that prevented explicit impls for defaulted traits for anything except for nominal types. In other words, if (in crate A) I have:
then it was illegal to do (in any crate)
struct SomeType { } impl Foo for (SomeType,) { }
. However, that seemed too strict, because one wants to be able to do things likeimpl !Foo for *mut A { }
, and since (currently) positive and negative impls basically follow the same rules, it seemed strange to permit one and not the other. So we removed this logic.But we got it wrong. The current rules do not guarantee coherence well enough to avoid inconsistent conclusions. In particular, I can define in crate A a generic fn like:
This function can conclude that
(X,Y) : Foo
because it applies the default rule for the tuple and the components implementFoo
.But now in crate B I can do:
In other words, A and B are
Foo
, but not the pair(A,B)
. Uh oh!I think what the rules ought to be is that, outside the crate where the trait was defined, we can only define an impl for a defaulted trait if the self-type is a
ty_struct
orty_enum
and the type itself was defined in the current crate.cc @flaper87
The text was updated successfully, but these errors were encountered: