Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign up#[cfg_attr] expanding to multiple attributes #2539
Conversation
Havvy
added some commits
Sep 10, 2018
Centril
added
the
T-lang
label
Sep 11, 2018
Centril
self-assigned this
Sep 11, 2018
This comment has been minimized.
This comment has been minimized.
|
Usually we wait a bit before the debate settles, but in this case this seems to me a very small change with obvious wins to ergonomics, for those it matters to, with few, if any, drawbacks. @rfcbot merge |
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Sep 11, 2018
•
|
Team member @Centril has proposed to merge this. The next step is review by the rest of the tagged teams:
No concerns currently listed. 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
added
proposed-final-comment-period
disposition-merge
labels
Sep 11, 2018
This comment has been minimized.
This comment has been minimized.
|
Oh, cc @petrochenkov who asked me to open an RFC for this. |
This comment has been minimized.
This comment has been minimized.
|
I kind of wish the predicate was syntactically distinguished but I don't think its possible without introducing a novel syntax pattern that attributes don't have or being a breaking change (or having a weird exception for when there's only 1 attribute). |
This comment has been minimized.
This comment has been minimized.
|
@withoutboats I sorta agree here; but given the status quo, I think there's already an understanding that the second bit is the attribute-to-apply, so it is natural to assume that what follows also are attributes; therefore, there shouldn't be much new to learn. |
This comment has been minimized.
This comment has been minimized.
|
I wondered about |
This comment has been minimized.
This comment has been minimized.
|
I'd be okay with requiring square brackets there. Though if we do that, is |
This comment has been minimized.
This comment has been minimized.
First, I wanted the RFC to specify some kind of attribute syntax before stating that attributes can be put into a comma-separated list, because right now there's no official documentation on what the syntax is and whether it can be put into a list. Until very recently attributes accepted arbitrary token streams, so Right now the implemented syntax is
Everything from that list (with exception of key-value for now) can be passed to attribute proc macros without any feature gates. So, this RFC may want to specify what is implemented as supported syntax, or it may stay more conservative and only guarantee that token streams supported by attributes must never contain the comma token |
This comment has been minimized.
This comment has been minimized.
|
Second, |
This comment has been minimized.
This comment has been minimized.
ExpHP
commented
Sep 12, 2018
•
|
Small or not, I don't get the push for insta-FCP? There's a question in design space about whether to support 0 attributes. The proposal clearly takes the stance that it should not. I would object to it as well, because it feels like a potential footgun. (you can write the condition, get distracted, come back and forget to add the rest). However, supporting 0 arguments would be useful for macros and codegen, and would seem to be consistent with many of other rust's decisions:
|
This comment has been minimized.
This comment has been minimized.
|
For the delimited The problematic case here would be an attribute such as To me, there are three ways that can be solved.
Personally, I think the attribute I wrote looks weird, so I'd rather go for option 2. As for also doing it for attribute syntax in general, that's a bigger change, but you are right that it's basically the same change. Heck, just changing the meaning of But if we're going to do that, we're going to have to cancel the FCP. |
This comment has been minimized.
This comment has been minimized.
|
@ExpHP This RFC gives no opinion on it. I considered on that point, and decided to punt. I think we should allow it, but issue a warning if it's found like that in non-macro-generated code. Although this means that |
This comment has been minimized.
This comment has been minimized.
|
@Havvy |
This comment has been minimized.
This comment has been minimized.
|
With the change to more precisely specify attribute syntax, I think this is ready to merge. |
This comment has been minimized.
This comment has been minimized.
|
Recent updates: Two changes have been made to this RFC today. The first outlined the restrictions on future attribute syntax that is a byproduct of this RFC. The second was a material change to allow zero attributes in the list and trailing commas. I will not be expanding this RFC to also affect general syntax attribute, but rather leave that to its own RFC. It has more drawbacks, and is scope creep. |
kennytm
reviewed
Sep 14, 2018
| * `cfg_attr(predicate, attr)` | ||
| * `cfg_attr(predicate, attr_1, attr_2)` | ||
| * `cfg_attr(predicate, attr,)` | ||
| * `cfg_attr(preciate, attr_1, attr_2,)` |
This comment has been minimized.
This comment has been minimized.
rfcbot
added
proposed-final-comment-period
disposition-merge
labels
Sep 14, 2018
petrochenkov
referenced this pull request
Sep 24, 2018
Closed
[1.30 beta] Regression in cfg attribute parsing #54463
This comment has been minimized.
This comment has been minimized.
|
For the record, I am in favor of the general idea, and supportive of basically any of the various options that been proposed. Happy to let the thread reach a consensus on the minor points. I would mildly favor permitting zero attributes: it seems like the sort of thing that a code generator might want to be able to do. It seems like just adding more arguments to |
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Sep 25, 2018
|
|
rfcbot
added
final-comment-period
and removed
proposed-final-comment-period
labels
Sep 25, 2018
petrochenkov
reviewed
Sep 25, 2018
| * `cfg_attr(predicate, attr_1, attr_2)` | ||
| * `cfg_attr(predicate, attr,)` | ||
| * `cfg_attr(predicate, attr_1, attr_2,)` | ||
| * `cfg_attr(predicate)` |
This comment has been minimized.
This comment has been minimized.
petrochenkov
Sep 25, 2018
Contributor
Nit: this is better prohibited for uniformity.
Imagine any other syntax for the predicate/attrs separator, e.g. cfg_attr(predicate: attr1, attr2), then empty attribute list would look like cfg_attr(predicate:) with cfg_attr(predicate) being invalid, i.e. the first comma is not like the others.
This comment has been minimized.
This comment has been minimized.
Centril
Sep 25, 2018
Contributor
We usually go for zero-or-more instead of one-or-more in most places where we allow -or-more? so I'm not sure restricting this to one-or-more is the uniform thing to do here?
This comment has been minimized.
This comment has been minimized.
petrochenkov
Sep 26, 2018
Contributor
I mean cfg_attr(predicate, /* no attrs */) - OK, cfg_attr(predicate /* no attrs */) - ERROR, i.e. zero-or-more exactly.
This comment has been minimized.
This comment has been minimized.
Centril
Sep 26, 2018
Contributor
Oh; I see now :)
I have no strong feelings here.
Are there any future compat hazards with allowing the omission of the , ?
I don't think macros benefit from omitting ,.
This comment has been minimized.
This comment has been minimized.
scottmcm
Sep 26, 2018
Member
I think I agree here. Allowing cfg_attr(p) is like allowing both leading and trailing commas; we don't need it, and blocking it simplifies the grammar.
This comment has been minimized.
This comment has been minimized.
Centril
Sep 26, 2018
Contributor
@Havvy can you make the restriction based on @petrochenkov's and @scottmcm's comments?
We can always relax in the future if we feel so inclined but for now we can be more conservative here until we have a good justification to do something else.
This comment has been minimized.
This comment has been minimized.
Havvy
added some commits
Sep 26, 2018
This comment has been minimized.
This comment has been minimized.
|
I added a commit that specifies that the emitted warning for |
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Oct 5, 2018
|
The final comment period, with a disposition to merge, as per the review above, is now complete. |
rfcbot
added
finished-final-comment-period
and removed
final-comment-period
labels
Oct 5, 2018
Havvy
referenced this pull request
Oct 6, 2018
Merged
Implement RFC 2539: cfg_attr with multiple attributes #54862
Centril
referenced this pull request
Oct 7, 2018
Open
Tracking issue for RFC 2539, "#[cfg_attr] expanding to multiple attributes" #54881
Centril
merged commit 0125668
into
rust-lang:master
Oct 7, 2018
This comment has been minimized.
This comment has been minimized.
|
Huzzah! This RFC has been merged! Tracking issue: rust-lang/rust#54881 |
Havvy
deleted the
Havvy:cfg_attr_multi
branch
Oct 8, 2018
Manishearth
added a commit
to Manishearth/rust
that referenced
this pull request
Oct 10, 2018
Manishearth
added a commit
to Manishearth/rust
that referenced
this pull request
Oct 10, 2018
Centril
added
A-cfg
A-attributes
labels
Nov 23, 2018
ordovicia
reviewed
Jan 5, 2019
|
|
||
| ## Warning When Zero Attributes | ||
|
|
||
| This RFC allows `#[cfg_attr(predicate)]`. This is so that macros can generate |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Centril
Jan 5, 2019
Contributor
Yeah, the RFC states that #[cfg_attr(predicate)] is not permitted before this. A fix PR would be welcome.
Havvy commentedSep 11, 2018
•
edited by Centril
#[cfg_attr(predicate, attr1, attr2, ...)]expands to each attribute instead of only taking one attribute.To @Centril for a quick review of the RFC before publishing.