-
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
Support an explicit annotation for marker traits #53693
Conversation
3ed26ac
to
a8b137f
Compare
ca490fe
to
fcd94f9
Compare
I think this is functional and sound, but it's missing the "this trait would be impossible to implement" error when defining a trait without default implementations for its items. I'd appreciate advice on where that should go, as well as any other feedback on how I've been going about this. |
@scottmcm this is confusing to me. I thought a marker trait had no items -- not "items with defaults". |
@nikomatsakis See #29864 (comment) for some context. But yes, it's an extension beyond the RFC, so I'm fine not implementing that for now. I do still need advice on where to put the "has no items" valuation check, though. (Once I know where I can figure out how to get the item list.) |
@scottmcm I see. That seems like an ok extension, actually, but in that case I don't know what this is referring to...
...oh, I see, I thought you meant some fancy check designed to prove that the trait is imposible to implement. But actually you just mean that you want to report an error if you label a trait as In that case, I think we should do that .. hmm .. either in WF or in coherence. Coherence seems like -- today -- it is focused on checking properties of impls so maybe wfcheck would be a better place. Basically extending this function: rust/src/librustc_typeck/check/wfcheck.rs Lines 305 to 311 in 70a21e8
We should probably do a quick lang-team FCP here too. |
@rfcbot fcp merge This PR modifies the special treatment of marker traits in two ways. First, you have to declare the traits explicitly, by writing Seems reasonable to me. |
Team member @nikomatsakis has proposed to merge this. The next step is review by the rest of the tagged teams:
Concerns:
Once a majority of reviewers approve (and none object), 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. |
@rfcbot concern vague I'm 👍 on having a I'm not so convinced that redefining marker trait to include traits with default items and then adding additional checks that those are never overriden is a good idea. It comes at a nontrivial cost of complexity for users in terms of understanding the meaning and mechanics of both default methods and marker traits. The motivation doesn't seem that strong to me. |
I very much agree that the incoherency should be opt-in rather than be implicit. However; this was not discussed in the RFC (unless I somehow missed that but I did look at every comment...) and this could use some more elaborate and detailed justification. @rfcbot concern needs-rfc In addition; I am not so sure about the concrete syntax here. The choice of using an attribute rather than some keyword as a prefix to the trait (e.g. @rfcbot concern concrete-syntax |
To elaborate a bit: I'm fine with landing this PR and using |
I agree with @Centril and @withoutboats - this seems like a big change and marker traits with default methods adds considerably to the complexity of the feature, as well as making |
@bors r- |
- Check for valid attributes more reliably - Don't bloat the error index for boring errors - Do use real error codes for the interesting ones
c991f11
to
3932249
Compare
@nikomatsakis Ok, how about something like this:
But both features continue to work and are unstable, so it's surprising to me that we'd relnote them at all. |
@bors r+ I'm not sure if we usually relnote unstable features. Seems like a nice thing to do. |
📌 Commit 3932249 has been approved by |
Support an explicit annotation for marker traits From the tracking issue for rust-lang/rfcs#1268: > It seems obvious that we should make a `#[marker]` annotation. ~ #29864 (comment) This PR allows you to put `#[marker]` on a trait, at which point: - [x] The trait must not have any items ~~All of the trait's items must have defaults~~ - [x] Any impl of the trait must be empty (not override any items) - [x] But impls of the trait are allowed to overlap r? @nikomatsakis
☀️ Test successful - status-appveyor, status-travis |
From the tracking issue for rust-lang/rfcs#1268:
This PR allows you to put
#[marker]
on a trait, at which point:All of the trait's items must have defaultsr? @nikomatsakis