Skip to content

Simplify attribute_groups #140539

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

Merged
merged 4 commits into from
May 26, 2025
Merged

Conversation

nnethercote
Copy link
Contributor

It's more complicated than it needs to be.

r? @jdonszelmann

@rustbot rustbot added 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. labels May 1, 2025
@rustbot
Copy link
Collaborator

rustbot commented May 1, 2025

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann

@nnethercote nnethercote force-pushed the simplify-attribute_groups branch from 923fc5e to e1ab116 Compare May 1, 2025 08:54
Copy link
Contributor

@jdonszelmann jdonszelmann left a comment

Choose a reason for hiding this comment

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

This is not a full review, was just skimming through, but I don't think simplifying the parsers to take one symbol is that nice since attributes can be namespaced. We don't do this a whole lot right now, but I wish we did more. Diagnostics attributes use this for example.

$(
{
thread_local! {
static STATE_OBJECT: RefCell<$names> = RefCell::new(<$names>::default());
};

for (k, v) in <$names>::ATTRIBUTES {
accepts.entry(*k).or_default().push(Box::new(|cx, args| {
let old = accepts.insert(*k, Box::new(|cx, args| {
Copy link
Contributor

Choose a reason for hiding this comment

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

fair, used to be a vec I think but this is better

@@ -33,7 +33,7 @@ pub(crate) mod transparency;
pub(crate) mod util;

type AcceptFn<T> = fn(&mut T, &AcceptContext<'_>, &ArgParser<'_>);
type AcceptMapping<T> = &'static [(&'static [rustc_span::Symbol], AcceptFn<T>)];
type AcceptMapping<T> = &'static [(Symbol, AcceptFn<T>)];
Copy link
Contributor

Choose a reason for hiding this comment

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

We can't do this. There are attributes that require more than one symbol in its path, and doing this would mean we can't parse those anymore, which would be a shame. None of the first few parsers I built use this feature, but I think it is an important one

Copy link
Member

@jieyouxu jieyouxu May 8, 2025

Choose a reason for hiding this comment

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

Like namespaced attributes?

EDIT: as examples: #[diagnostic::{do_not_recommend,on_unimplemented}]

Copy link
Contributor

Choose a reason for hiding this comment

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

precisely

@jdonszelmann
Copy link
Contributor

we briefly discussed this during rustweek I believe, but coming back to this: I'm happy to accept all the comment changes and some more, but none of the symbol slice -> single symbol changes.

@jieyouxu
Copy link
Member

@rustbot author (re. direction)

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 19, 2025
@rustbot
Copy link
Collaborator

rustbot commented May 19, 2025

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

There only needs to be one `Fn` per symbol, not multiple.
Some are too long (> 100 chars), some are too short, some are missing
full stops, some are missing upper-case letters at the start of
sentences.
In several files they are entirely unnecessary, with the relevant names
already imported. And in a few I have added the necessary `use` item.
@nnethercote nnethercote force-pushed the simplify-attribute_groups branch from e1ab116 to 354b1cb Compare May 19, 2025 23:29
@nnethercote
Copy link
Contributor Author

@jdonszelmann: I have removed the commit that changed the symbol slice to a single symbol. I have added a new commit that removes some unnecessary/undesirable rustc_span:: qualifiers.

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 19, 2025
@jdonszelmann
Copy link
Contributor

perfect! @bors r+

@bors
Copy link
Collaborator

bors commented May 25, 2025

📌 Commit 354b1cb has been approved by jdonszelmann

It is now in the queue for this repository.

@bors bors 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-review Status: Awaiting review from the assignee but also interested parties. labels May 25, 2025
@jdonszelmann
Copy link
Contributor

@bors rollup

jhpratt added a commit to jhpratt/rust that referenced this pull request May 25, 2025
…ups, r=jdonszelmann

Simplify `attribute_groups`

It's more complicated than it needs to be.

r? `@jdonszelmann`
bors added a commit that referenced this pull request May 26, 2025
Rollup of 9 pull requests

Successful merges:

 - #134696 (Implement `normalize_lexically`)
 - #138744 (Add methods to TCP and UDP sockets to modify hop limit (refresh of #94678))
 - #140539 (Simplify `attribute_groups`)
 - #140863 ([rustdoc] Unify type aliases rendering with other ADT)
 - #140936 (Clarify WTF-8 safety docs)
 - #140952 (Specify that split_ascii_whitespace uses the same definition as is_ascii_whitespace)
 - #141472 (Attempt to improve the `std::fs::create_dir_all` docs related to atomicity)
 - #141502 (ci: move PR job x86_64-gnu-tools to codebuild)
 - #141559 (const-check: stop recommending the use of rustc_allow_const_fn_unstable)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request May 26, 2025
Rollup of 8 pull requests

Successful merges:

 - #134696 (Implement `normalize_lexically`)
 - #140539 (Simplify `attribute_groups`)
 - #140863 ([rustdoc] Unify type aliases rendering with other ADT)
 - #140936 (Clarify WTF-8 safety docs)
 - #140952 (Specify that split_ascii_whitespace uses the same definition as is_ascii_whitespace)
 - #141472 (Attempt to improve the `std::fs::create_dir_all` docs related to atomicity)
 - #141502 (ci: move PR job x86_64-gnu-tools to codebuild)
 - #141559 (const-check: stop recommending the use of rustc_allow_const_fn_unstable)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 761e546 into rust-lang:master May 26, 2025
6 checks passed
@rustbot rustbot added this to the 1.89.0 milestone May 26, 2025
rust-timer added a commit that referenced this pull request May 26, 2025
Rollup merge of #140539 - nnethercote:simplify-attribute_groups, r=jdonszelmann

Simplify `attribute_groups`

It's more complicated than it needs to be.

r? ``@jdonszelmann``
@nnethercote nnethercote deleted the simplify-attribute_groups branch May 26, 2025 07:45
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.

5 participants