FCW on expressions in doc attributes on macro calls - #160904
Conversation
63a2f0f to
f705d49
Compare
This comment has been minimized.
This comment has been minimized.
f705d49 to
11ac310
Compare
This comment has been minimized.
This comment has been minimized.
11ac310 to
478a22c
Compare
This comment has been minimized.
This comment has been minimized.
478a22c to
65407a3
Compare
This comment has been minimized.
This comment has been minimized.
65407a3 to
9b15145
Compare
This comment has been minimized.
This comment has been minimized.
9b15145 to
dd5debd
Compare
This comment has been minimized.
This comment has been minimized.
dd5debd to
1953f77
Compare
This comment has been minimized.
This comment has been minimized.
1953f77 to
3888e00
Compare
|
Some changes occurred in compiler/rustc_attr_parsing cc @jdonszelmann, @JonathanBrouwer These commits modify the If this was unintentional then you should revert the changes before this PR is merged. |
3888e00 to
8c0900d
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
8c0900d to
9fdd707
Compare
|
@JonathanBrouwer this is ready for review now |
This comment has been minimized.
This comment has been minimized.
9fdd707 to
254ea39
Compare
This comment has been minimized.
This comment has been minimized.
254ea39 to
623360c
Compare
|
☔ The latest upstream changes (presumably #161043) made this pull request unmergeable. Please resolve the merge conflicts by rebasing. |
| impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { | ||
| fn visit_attribute(&mut self, attr: &ast::Attribute) { | ||
| // Check unstable flavors of the `#[doc]` attribute. | ||
| if attr.has_name(sym::doc) { |
There was a problem hiding this comment.
Is it possible to move the "move of feature gating" out of this PR?
That part seems unrelated and doesn't need to be part of the T-lang decision, if I understand correctly this is not observable right?
| let a = 1; | ||
| let b = 1; | ||
| let sum = a + b; | ||
| assert_eq!(sum, 2); |
There was a problem hiding this comment.
Could you also add an example without a macro call in it here? That is a stronger regression test
|
I'm leaning towards making this an error immediately, we can just wait for the crater queue. |
Recently I discovered that, since Rust 1.94, doc attributes on macro invocations can have arbitrary expressions in them:
As part of the attribute parsing rework this was accidentally allowed. Note that doc attributes (or any doc comment) on macro invocations do nothing, because documentation for macro invocations is not rendered - this emits a lint saying macros must produce doc comments as part of their expansion.
With this PR, it now emits a FCW, like #57571. As this is so niche it's probable this could go straight to an error but there's quite a crater queue so I'd rather do this now and try turning it into an error later.
Note that
#[doc = mac!()]is included in this. While this is allowed everywhere else as normally attribute parsing only sees it after its expansion, it is not expanded here, but we do need to check attributes here since we can't check them later as they're lost by then.I don't think it is worth trying to make particular case work - this would involve checking that the expression would expand to a string literal:
This change would also make it consistent with all other key-value attributes. For an example, the following are allowed
but this is not:
This PR implements some non-visible changes as well
r? @JonathanBrouwer