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 7 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

@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.

Signed-off-by: Jonathan Brouwer <[email protected]>
Signed-off-by: Jonathan Brouwer <[email protected]>
Signed-off-by: Jonathan Brouwer <[email protected]>
Signed-off-by: Jonathan Brouwer <[email protected]>
@JonathanBrouwer
Copy link
Contributor Author

^ Rebased

@jdonszelmann
Copy link
Contributor

Discussed with @oli-obk, we're going to do a crater run for this one because it's technically a breaking change.
First a try build, no need to rebase until crater's done which will take a bit :)

@bors try

bors added a commit that referenced this pull request Jul 11, 2025
Port the proc macro attributes to the new attribute parsing infrastructure

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`
@bors
Copy link
Collaborator

bors commented Jul 11, 2025

⌛ Trying commit f8c757f with merge 360f8e6...

@jdonszelmann
Copy link
Contributor

@traviscross what's the proper way to notify T-lang on this? What label, and could you add that?

@bors
Copy link
Collaborator

bors commented Jul 11, 2025

☀️ Try build successful - checks-actions
Build commit: 360f8e6 (360f8e61048079e513337f716e2015067717b98e)

@traviscross
Copy link
Contributor

traviscross commented Jul 11, 2025

@traviscross what's the proper way to notify T-lang on this? What label, and could you add that?

@rustbot labels +I-lang-nominated +T-lang
cc @rust-lang/lang

@rustbot rustbot added the I-lang-nominated Nominated for discussion during a lang team meeting. label Jul 11, 2025
@traviscross traviscross added P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang T-lang Relevant to the language team labels Jul 11, 2025
@JonathanBrouwer
Copy link
Contributor Author

JonathanBrouwer commented Jul 11, 2025

For reference for the lang team: #142838 (comment)

Could someone start crater? I don't think I have permission to do that

@traviscross
Copy link
Contributor

@craterbot check

@craterbot
Copy link
Collaborator

👌 Experiment pr-143607 created and queued.
🤖 Automatically detected try build 360f8e6
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) I-lang-nominated Nominated for discussion during a lang team meeting. P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang S-waiting-on-crater Status: Waiting on a crater run to be completed. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants