Skip to content

Expand diagnostic for attributes on macro calls#158106

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
mejrs:note_maccall
Jun 20, 2026
Merged

Expand diagnostic for attributes on macro calls#158106
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
mejrs:note_maccall

Conversation

@mejrs

@mejrs mejrs commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

As far as I am aware there are no attributes that do something when used on macro invocations.

r? @JonathanBrouwer

@rustbot

rustbot commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 18, 2026
@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jun 18, 2026

#[derive(Subdiagnostic)]
pub(crate) enum OnMacroCall {
#[warning("this representation attribute is ignored")]

@JonathanBrouwer JonathanBrouwer Jun 19, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the repr attribute special cased?

View changes since the review

@mejrs mejrs Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a particular dangerous mistake because people assume that it acts on the macro expension. It is one of those things where you think you know what it does but are wrong.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm I'm not sure I really like that special case, I think the extra warning message is not really helping the user understand it better, the note you added should be enough

pub(crate) enum OnMacroCall {
#[warning("this representation attribute is ignored")]
#[note(
"attributes on macro invocations do nothing even if the macro expands to what would be a valid target for the attribute"

@JonathanBrouwer JonathanBrouwer Jun 19, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not true, the cfg and cfg_attr attribute do work, and I'm expecting proc macro attributes to also work but not sure.
Maybe change it to
"this attribute does nothing on macro invocations..."

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I forgot about the active attributes.

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 19, 2026
@rustbot

rustbot commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jun 19, 2026

@JonathanBrouwer JonathanBrouwer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me with green ci

View changes since this review

@JonathanBrouwer

Copy link
Copy Markdown
Contributor

@bors r+ rollup

@rust-bors

rust-bors Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 8a50cd6 has been approved by JonathanBrouwer

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 19, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 19, 2026
Expand diagnostic for attributes on macro calls

As far as I am aware there are no attributes that do something when used on macro invocations.

r? @JonathanBrouwer
rust-bors Bot pushed a commit that referenced this pull request Jun 19, 2026
Rollup of 3 pull requests

Successful merges:

 - #149267 (fix: clarify that fs::rename on unix accepts targets that don't exist)
 - #158106 (Expand diagnostic for attributes on macro calls)
 - #158125 (add a test for the `getrandom` fallback)
@rust-bors rust-bors Bot merged commit b98c554 into rust-lang:main Jun 20, 2026
13 checks passed
@rustbot rustbot added this to the 1.98.0 milestone Jun 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants