Skip to content

Port the proc macro attributes to the new attribute parsing infrastructure #143607

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

JonathanBrouwer
Copy link
Contributor

@JonathanBrouwer JonathanBrouwer commented Jul 7, 2025

Ports #[proc_macro], #[proc_macro_attribute], #[proc_macro_derive] and #[rustc_builtin_macro] to the new attribute parsing infrastructure for #131229 (comment)

I've split this PR into commits for reviewability, and left some comments to clarify things
I did 4 related attributes in one PR because they share a lot of their code and logic, and doing them separately is kind of annoying as I need to leave both the old and new parsing in place then.

r? @oli-obk
cc @jdonszelmann

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 7, 2025

// Not a built-in macro
None => (None, helper_attrs),
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The logic here should be equivalent to the logic above, other than that this is a bit more readable and that we use the already parsed attribute rather than parsing it from scratch

@@ -57,7 +57,7 @@
// see gated-link-args.rs
// see issue-43106-gating-of-macro_escape.rs for crate-level; but non crate-level is below at "2700"
// (cannot easily test gating of crate-level #[no_std]; but non crate-level is below at "2600")
#![proc_macro_derive()] //~ WARN `#[proc_macro_derive]` only has an effect
#![proc_macro_derive(Test)] //~ WARN `#[proc_macro_derive]` only has an effect
Copy link
Contributor Author

@JonathanBrouwer JonathanBrouwer Jul 7, 2025

Choose a reason for hiding this comment

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

Note that a breaking change happened here! The code before this change would now produce an error.

Previously a proc_macro_derive applied to the crate could have any arguments it wants, it was not checked. This PR fixes this bug, and this now errors.

I discussed this privately with @jdonszelmann, and she said this is fine to change, though we can consider doing a crater run for this just to make sure if you wish.

@JonathanBrouwer JonathanBrouwer marked this pull request as ready for review July 7, 2025 19:16
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 7, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 7, 2025

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann

Some changes occurred in compiler/rustc_passes/src/check_attr.rs

cc @jdonszelmann

Some changes occurred in compiler/rustc_attr_data_structures

cc @jdonszelmann

@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Jul 7, 2025

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@jdonszelmann
Copy link
Contributor

This could use a little squash I think

@jdonszelmann
Copy link
Contributor

Not everything, but some commits are a bit small

@JonathanBrouwer
Copy link
Contributor Author

JonathanBrouwer commented Jul 8, 2025

@jdonszelmann I've squashed things down a bit. I'm experimenting a bit with what commit size is best for reviewability, this was clearly too much of a good thing :P

Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
@JonathanBrouwer
Copy link
Contributor Author

r? @jdonszelmann
@rustbot ready

@rustbot rustbot assigned jdonszelmann and unassigned oli-obk Jul 8, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 8, 2025

jdonszelmann is not on the review rotation at the moment.
They may take a while to respond.

@bors
Copy link
Collaborator

bors commented Jul 8, 2025

☔ The latest upstream changes (presumably #143645) made this pull request unmergeable. Please resolve the merge conflicts.

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-review Status: Awaiting review from the assignee but also interested parties. 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.

6 participants