Skip to content

Conversation

@JonathanBrouwer
Copy link
Contributor

This PR moves attribute safety checking to be done during attribute parsing. The cfg and cfg_attr attribute no longer need special-cased safety checking, yay!

This PR is a part 1 of 2, in the second part I'd like to define attribute safety in the attribute parsers rather than getting the information from BUILTIN_ATTRIBUTE_MAP, but to keep PRs reviewable lets do that separately.

Fixes #148453 by reordering the diagnostics. The "cannot find attribute" diagnostic now appears first, but both diagnostics still appear.

r? @jdonszelmann

@rustbot
Copy link
Collaborator

rustbot commented Dec 1, 2025

Some changes occurred in compiler/rustc_attr_parsing

cc @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 Dec 1, 2025
@rust-log-analyzer

This comment has been minimized.

@JonathanBrouwer
Copy link
Contributor Author

:c
@rustbot author

@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 Dec 1, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 1, 2025

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

@bors
Copy link
Collaborator

bors commented Dec 2, 2025

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

@rustbot
Copy link
Collaborator

rustbot commented Dec 2, 2025

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.

#[rustc_clean(cfg = "cfail5")]
#[rustc_clean(cfg = "cfail6")]
#[no_mangle]
#[unsafe(no_mangle)]
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 extra unsafe is necessary because without it these tests produces a lint, meaning fail2 and cfail5 are not clean. This was not previously a problem because the lint was emitted early, while it is now stored in the hir.

@JonathanBrouwer
Copy link
Contributor Author

@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 Dec 2, 2025
@jdonszelmann
Copy link
Contributor

@rustbot author

@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 Dec 3, 2025
@JonathanBrouwer
Copy link
Contributor Author

@rustbot ready

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

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Dec 4, 2025

📌 Commit 1d204fc 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 Dec 4, 2025
bors added a commit that referenced this pull request Dec 4, 2025
Rollup of 9 pull requests

Successful merges:

 - #147224 (Emscripten: Turn wasm-eh on by default)
 - #149405 (Recover on misspelled item keyword)
 - #149443 (Tidying up UI tests [6/N])
 - #149524 (Move attribute safety checking to attribute parsing)
 - #149593 (powf, powi: point out SNaN non-determinism)
 - #149605 (Use branch name instead of HEAD when unshallowing)
 - #149612 (Apply the `bors` environment also to the `outcome` job)
 - #149623 (Don't require a normal tool build of clippy/rustfmt when running their test steps)
 - #149627 (Point to the item that is incorrectly annotated with `#[diagnostic::on_const]`)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 0c95abb into rust-lang:main Dec 5, 2025
11 checks passed
@rustbot rustbot added this to the 1.93.0 milestone Dec 5, 2025
rust-timer added a commit that referenced this pull request Dec 5, 2025
Rollup merge of #149524 - JonathanBrouwer:move_attr_safety, r=jdonszelmann

Move attribute safety checking to attribute parsing

This PR moves attribute safety checking to be done during attribute parsing. The `cfg` and `cfg_attr` attribute no longer need special-cased safety checking, yay!

This PR is a part 1 of 2, in the second part I'd like to define attribute safety in the attribute parsers rather than getting the information from BUILTIN_ATTRIBUTE_MAP, but to keep PRs reviewable lets do that separately.

Fixes #148453 by reordering the diagnostics. The "cannot find attribute" diagnostic now appears first, but both diagnostics still appear.

r? `@jdonszelmann`
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Dec 5, 2025
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#147224 (Emscripten: Turn wasm-eh on by default)
 - rust-lang/rust#149405 (Recover on misspelled item keyword)
 - rust-lang/rust#149443 (Tidying up UI tests [6/N])
 - rust-lang/rust#149524 (Move attribute safety checking to attribute parsing)
 - rust-lang/rust#149593 (powf, powi: point out SNaN non-determinism)
 - rust-lang/rust#149605 (Use branch name instead of HEAD when unshallowing)
 - rust-lang/rust#149612 (Apply the `bors` environment also to the `outcome` job)
 - rust-lang/rust#149623 (Don't require a normal tool build of clippy/rustfmt when running their test steps)
 - rust-lang/rust#149627 (Point to the item that is incorrectly annotated with `#[diagnostic::on_const]`)

r? `@ghost`
`@rustbot` modify labels: rollup
@panstromek
Copy link
Contributor

perf triage:

Hey, looks like this PR caused a regression in #149646, is this expected/justified? Should we revert?

perf results for this PR: #149646 (comment)

@JonathanBrouwer
Copy link
Contributor Author

JonathanBrouwer commented Dec 8, 2025

This seems to be specifically a regression for incremental. My guess is this is caused by the lints now being stashed in the HIR, which is hashed for incremental.
I'll take a look to see if there's anything I can do to fix this.

@JonathanBrouwer
Copy link
Contributor Author

The regression is caused by that we now lower spans of attribute paths. We didn't do this before and not doing this is wrong.
Most of the regression can be solved by removing the spans of the individual components of attribute paths entirely, see #149790 (comment)
Still need to make this into a functional PR tho :)

@jdonszelmann
Copy link
Contributor

well actually

@jdonszelmann
Copy link
Contributor

this might be a real regression haha. take a look at this pr: #148863. it seems that lowering spans simply isn't always worth it weirdly

@jdonszelmann
Copy link
Contributor

still trying to come up with a good strategy, but lowering spans takes time, sometimes more than just recompiling the thing. I actually deliberately skipped attr paths in that pr since so many spans in attributes aren't lowered (like whole tokenstreams worth of them) that lowering them would be a giant regression haha

@jdonszelmann
Copy link
Contributor

cc: @oli-obk I guess we need to come up with a policy here: do we want to prefer correctness in incremental and lower all spans we can find regardless of the runtime cost or do we want to look for places not to lower spans for some perf wins haha

@jdonszelmann
Copy link
Contributor

I guess the real solution is to make span lowering faster. I'll look into it.

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.

"attr is not an unsafe attribute" diagnostic is emitted even if the attribute doesn't exist

6 participants