-
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
syntax: allow setting attributes for deriving impls #20236
Conversation
r? @huonw (rust_highfive has picked a reviewer for you, use r? to override) |
r? @aturon |
I'm not sure I'm in favour of using |
It is restrictive, but it works for what we need now. The approach in #13054 can't work if you want impls to possibly have different stability levels. |
In the future we could extend it to have a list of any amount of actual attributes, ie |
Eh. Not really in favour of strings at all. Also what if we want to add other things?
|
I briefly considered something like that but I consider it ugly. |
I'll implement whatever, I just want to knock this off my to-do list. |
@cmr Thanks for doing this! I tend to agree with @huonw though that we're going to want the ability to set arbitrary attributes, with their own syntax. I'd be fine with doing something more limited for now, as long as there's a clear migration path toward a more general version later. I don't really know much about the limitations of the syntax here. It'd be awesome, for example, to be able to write: #[deriving(
#[stable]
#[cfg(test)]
Clone
)] |
I agree with @aturon and @huonw here that this may not be the final syntax we want, and if so we may want to put it behind a feature gate for now. I believe that @aturon's suggestion should in theory be possible with @nikomatsakis's desire for attributes to be "just token trees", but that may be aways away. |
I'll change this to use huon's suggested syntax and put it behind a feature
|
This extends the derive DSL from A := derive '(' N ')' N := ident | ident ',' N to A := derive '(' T ')' T := N | N ',' N N := ident | ident '(' attributes '(' meta_seq ') ') That is, a form like #[derive(Clone, Ord(attributes(unstable, cfg(not(windows)))))] Will apply `#[unstable]` and `#[cfg(not(windows))]` to the derived `Ord` impl. Closes #18969
I don't think that this should land without a feature gate for now, this is an extension to a pretty core aspect of the language which hasn't been discussed much here or in rust-lang/rfcs. |
Whoops, forgot the feature gate. On Thu, Jan 1, 2015 at 11:17 PM, Alex Crichton notifications@github.com
|
Going to leave this for now to focus on more important changes for the alpha. |
The approach this takes is to extend the deriving DSL to accept the form
TRAIT = VALUE
, whereVALUE
is one of the stability names, and theappropriate attribute will be inserted into the AST of the generated impl.
Closes #18969