-
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
[EXPERIMENT] disable orphan check for marker traits #96766
Conversation
This seems very wrong to me from a user perspective. I would certainly not expect anyone but my crate to be able to implement a trait for a type of my crate, unless they defined they trait. I could have functions exposed in my crate that specifically require the marker trait to exist and then not implemented it for some local types, expecting them to never get passed to said functions. Of course I can emulate that with regular trait hierarchies, but that's annoying |
I do think this needs some further evaluation. In @rust-lang/lang we've talked about possibilities like allowing duplicate implementations of a third-party trait for a third-party type, as long as the implementations were identical (e.g. created by a standalone derive, or implemented using only default method implementations, etc). Marker traits do create some cases where I could imagine not wanting that. |
I'm strongly against disabling the orphan check here, because it mixes poorly with negative impls. If any random crate can have (That's particularly true for
I think this is all the more reason to not do this. I think |
@scottmcm I agree with you that the semantics of marker traits mean we likely shouldn't do this. How would you reconcile that with the general idea of being able to merge duplicate trait impls from multiple crates, which does seem like a positive for non-marker traits? |
@joshtriplett As I said in the meeting where I first heard about it, I'm skeptical about that idea in general, since it means that every If it's an extra opt-in on the trait to allow that, then |
You know what, I feel strongly enough about this that I'm going to put forward a motion. @rfcbot fcp close @lcnr mentions in the OP that they'd prefer not to make this change, and I agree. So let's take the opportunity here to, as the OP said, "officially decid[e] that we don't want this". (I have this as a T-lang FCP because I don't think the bot can do a traits team pFCP, but if anyone on @rust-lang/wg-traits wants to put a concern on here, ping me and I'll add one on your behalf.) |
Team member @scottmcm has proposed to close this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
@scottmcm First of all: completely valid approach. Second, seeking some clarification: it sounds like you're making the case that, if we do have a mechanism to disable the orphan check, it should be opt-in, rather than opt-out or universal? You're not seeking, at this time, to say that we should never have such a mechanism for this, but you are seeking consensus that we should never have an opt-out or universal mechanism for this? (Also, I personally would want such an opt-in on the type, not just on the trait.) |
I think all I'm saying for the purpose of this issue is that whatever we do shouldn't be tied to the That's compatible with doing it for everything, with doing it for nothing, with having an opt-out, or with having an opt-in. It's just not saying that |
@scottmcm If we're just aiming for consensus on "this behavior shouldn't be conditional on |
@rfcbot fcp reviewed I wrote up some thoughts here that seem relevant. In short, if we were to remove orphan rules from marker traits, you also couldn't have negative impls for them (or at least, you can't add those negative impls except for a fresh trait or fresh type), because you can't know whether downstream crates may have implemented them. @scottmcm also notes that it may be useful to denote |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
The final comment period, with a disposition to close, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. |
thanks! |
closes #67919, either by landing this or by officially deciding that we don't want this.
I very much prefer to not land this change.
The reasoning for this was given by @Centril in #67919
The original RFC from 2015 seems to imply that the orphan rules should be relaxed, but it was generally light on details. The impact this has on coherence was not mentioned there.
As downstream crates can now implement marker traits for arbitrary types, all
MyType: MarkerTrait
bounds have to either hold or are ambiguous. We can never prove thatT: MarkerTrait
does not hold. This prevents the snippet in theforbidden-fruit
test.While I am completely forbidding negative impls for marker traits here, we could allow them in the crate defining the marker trait. They still would be forbidden for impls of foreign marker traits for local types though.
cc #68004 (comment)
Mostly opened this to get a general consensus from @rust-lang/wg-traits that this is something we do not want ^^
r? @ghost