-
Notifications
You must be signed in to change notification settings - Fork 13.3k
forbid conditional, negative impls #79098
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
This comment has been minimized.
This comment has been minimized.
Example of us enforcing a similar rule for drop check: Note that the |
Relevant code in drop-check is here: rust/compiler/rustc_typeck/src/check/dropck.rs Lines 34 to 35 in 244a73c
|
@spastorino do you plan to look into this? (If so, I can assign it to you.) As we said in our call, the obvious next step is to refactor the We will want to extend it, also, because I don't want you to be able to do things like impl<A, B> !Send for (A, B) where A: Copy { } In other words, we can kind of define what the "type parameters and predicates" are for other types like tuple types, |
This is blocking stabilization of negative impls, although we could opt to just stabilize negative impls for non-auto-traits. |
i am currently looking into reworking while I am at it I could just write #74648 take 2 |
Negative conditional impls enables the following pattern as well. Figured I should put this here |
What's the disagreement? According to the RFC:
Aside: does As I mentioned in #13231, |
We currently permit negative impls (feature-gated, #68318) for both auto- and regular traits. However, the semantics of negative impls are somewhat unresolved. The current trait checker's implementation in particular does not work well with "conditional" negative impls -- in other words, negative impls that do not apply to all instances of a type. Further, the semantics of such impls when combined with auto traits are not fully agreed upon.
Consider:
The question is, does
Bar<Box<T>>
implementFoo
? There is some disagreement about what would be expected here.As a temporary step, the plan is to forbid impls of this kind using similar logic to what we use for
Drop
impls. There was a PR in this direction #74648.Another similar step would be to forbid negative impls for traits that have multiple generic parameters:
There is no particular reason that we can't support multiple parameters, but I suspect that the drop logic is not designed to handle cases like this.
Related issues:
negative_impls
andauto_traits
experimental features allow trait impls to overlap #74629The text was updated successfully, but these errors were encountered: