Skip to content

Move #[naked] attribute check to attribute parsing stage - #162530

Open
RichardTjokroutomo wants to merge 13 commits into
rust-lang:mainfrom
RichardTjokroutomo:check-attr-naked
Open

RichardTjokroutomo wants to merge 13 commits into
rust-lang:mainfrom
RichardTjokroutomo:check-attr-naked

Conversation

@RichardTjokroutomo

@RichardTjokroutomo RichardTjokroutomo commented Sep 9, 2026 •

Copy link
Copy Markdown

View all comments

Following #161482's idea to add target_item field to FinalizeCheckContext, replace target_item with ast_target, which is an enum that contains all possible types of target Item (obtained by grepping all functions that call lower_attrs()).

This change is needed as methods defined under traits & impls are represented as ast::AssocItem. Lastly, move check_naked to the callback returned by NakedParser::deferred_finalize_check().

Part of #153101. r?@JonathanBrouwer

@rustbot

rustbot commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

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

cc @jdonszelmann, @JonathanBrouwer

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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 9, 2026
@rustbot

rustbot commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project has assigned @nnethercote (or someone else) to review your changes, you should hear from them (or someone else) within the next two weeks.

Please see the contribution instructions and our LLM policy for more information.

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 76 candidates
  • Random selection from 22 candidates

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@RichardTjokroutomo RichardTjokroutomo changed the title move check_naked() from check_attr.rs to codegen_attrs.rs Move #[naked] attribute check to attribute parsing stage Sep 10, 2026
@rustbot

This comment has been minimized.

Comment thread compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs
Comment thread compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs
Comment thread compiler/rustc_ast/src/ast.rs Outdated
Comment thread compiler/rustc_ast_lowering/src/lib.rs Outdated
@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 Sep 11, 2026
@rustbot

rustbot commented Sep 11, 2026

Copy link
Copy Markdown
Collaborator

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

@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rustbot

This comment has been minimized.

@rustbot

rustbot commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator

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.

@RichardTjokroutomo

Copy link
Copy Markdown
Author

I just read the LLM guidelines and found out disclosure is needed only if a part of the PR (code, PR desc, etc) is generated by LLM.

Since I only use it to learn the codebase, I'll remove the disclosure.

Comment thread compiler/rustc_attr_ir/src/target.rs Outdated
WherePredicate(&'a WherePredicate),

/// Used when it is not possible to get detailed information about the target.
None,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah that makes sense, we can have a 'AstTarget::None` for this case then to keep things simple

Comment thread compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs Outdated
Comment thread compiler/rustc_ast_lowering/src/block.rs Outdated
@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 Oct 7, 2026
@JonathanBrouwer

Copy link
Copy Markdown
Member

I just read the LLM guidelines and found out disclosure is needed only if a part of the PR (code, PR desc, etc) is generated by LLM.

Yeah as long as reviewers are not seeing any AI generated output you don't need to disclose.
Disclosure of that is still allowed tho ofc :)

Signed-off-by: Richard Tjokroutomo <richard.tjokro2@gmail.com>
&l.attrs,
l.span,
Target::Statement,
rustc_attr_ir::target::AstTarget::None,

@JonathanBrouwer JonathanBrouwer Oct 7, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why can't this be AstTarget::Statement?

View changes since the review

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Sorry... should've checked the caller function

&attrs,
span,
Target::Expression,
rustc_attr_ir::target::AstTarget::None,

@JonathanBrouwer JonathanBrouwer Oct 7, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why can't this be AstTarget::Expression?

View changes since the review

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I didn't check caller functions, sorry....

Comment thread compiler/rustc_ast_lowering/src/lib.rs Outdated
&param.attrs,
param.span,
Target::Param,
AstTarget::None,

@JonathanBrouwer JonathanBrouwer Oct 7, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why can't this be AstTarget::Pram?

View changes since the review

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Sorry... I was being careless..

Comment thread compiler/rustc_ast_lowering/src/lib.rs Outdated
&f.attrs,
f.span,
Target::ExprField,
AstTarget::Expression(expr),

@JonathanBrouwer JonathanBrouwer Oct 7, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think this is correct

View changes since the review

Comment thread compiler/rustc_attr_ir/src/target.rs Outdated
#[derive(Clone, Copy, Debug)]
pub enum AstTarget<'a> {
// Target types that may correspond to different kinds of items.
Delegation { target: DelegationAstTarget<'a>, mac: bool },

@JonathanBrouwer JonathanBrouwer Oct 7, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also here I'm leaning towards that we don't need the fields of this, and it adds a lot of complexity

View changes since the review

Comment thread compiler/rustc_attr_ir/src/target.rs Outdated
pub fn from_ast_item(kind: &'a ast::ItemKind) -> Self {
match kind {
ast::ItemKind::ExternCrate(..) => AstTarget::ExternCrate(kind),
ast::ItemKind::Use(..) => AstTarget::Use(kind),

@JonathanBrouwer JonathanBrouwer Oct 7, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd prefer if we map each ItemKind to its field where reasonable.
Like have AstTarget::Use take a UseTree rather than a ast::ItemKind.

View changes since the review

Comment thread compiler/rustc_attr_ir/src/target.rs Outdated
Union(&'a ItemKind),
Trait(&'a ItemKind),
TraitAlias(&'a ItemKind),
Impl { item: &'a ItemKind, of_trait: bool },

@JonathanBrouwer JonathanBrouwer Oct 7, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need this of_trait field? That should already be stored in the Impl right?

View changes since the review

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

yeah. It's irrelevant now after the most recent commit

Signed-off-by: Richard Tjokroutomo <richard.tjokro2@gmail.com>
Signed-off-by: Richard Tjokroutomo <richard.tjokro2@gmail.com>
@RichardTjokroutomo

Copy link
Copy Markdown
Author

@JonathanBrouwer I think everything is correct now. Let's just wait for CI results...

Previously there were a lot of changes when making AstTarget map 1-1 with Target, so TBH, at some point I stopped giving full attention when passing AstTarget as argument of various functions. I'm really sorry for this, but thankfully you catched them before merging

@RichardTjokroutomo

Copy link
Copy Markdown
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 Oct 8, 2026
@JonathanBrouwer

Copy link
Copy Markdown
Member

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 9, 2026
@rust-bors

This comment has been minimized.

Comment thread compiler/rustc_attr_ir/src/target.rs Outdated
Closure(&'a Closure),
Expression(&'a Expr),
ForLoop(&'a ForLoop),
Loop,

@JonathanBrouwer JonathanBrouwer Oct 9, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are these targets (ForLoop, Loop, While, Break) ever produced?
If not lets remove them, and accept that this is a mismatch with Target

View changes since the review

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you also check for the other AstTargets if they're used?

@RichardTjokroutomo RichardTjokroutomo Oct 9, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

If not lets remove them, and accept that this is a mismatch with Target

So we won't be replacing Target with AstTarget?

For now, there's only one case where we absolutely need AstTarget::None, and I think it is possible to replace it since AstTarget::MacroCall no longer carry detailed info of the AST target.

I also think that we can remove the fields of the enum types that we don't need (e.g. ForLoop), so we can still replace Target with AstTarget in the future. Just my thoughts though. I'm fine with removing them.

Could you also check for the other AstTargets if they're used?

Most are unused. They were only added since we wanted to make AstTarget map 1-1 with Target.
Edit: turns out not that many.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@JonathanBrouwer what are your thoughts?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

For now, I'm gonna go ahead with your suggestion and remove all unused AstTarget types on a new commit. If you have different thoughts we can always hard reset to previous commit :)

Comment thread compiler/rustc_attr_ir/src/target.rs Outdated
Field(&'a FieldDef),
GenericParam(&'a GenericParam),
LifetimeParam(&'a GenericParam),
Local(&'a Local),

@JonathanBrouwer JonathanBrouwer Oct 9, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is Local still used?

View changes since the review

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

No. It's only there to make 1-1 matching

ExternAbi::Rust
})
});
abi.symbol_unescaped.as_str().parse().unwrap_or_else(|_| {

@JonathanBrouwer JonathanBrouwer Oct 9, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What happened to the indent here?

It would be nice if you could self-review (go through the diff of the PR) your changes to at least catch these kind of things, before submitting it for review

View changes since the review

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Oops.

Sorry, I thought the CI tests everything including tidiness, so I assumed if all checks pass then everything is good.

target_span,
target,
None,
rustc_attr_ir::target::AstTarget::None,

@JonathanBrouwer JonathanBrouwer Oct 9, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: I'd prefer if everywhere (not just here) we could import AstTarget and make this AstTarget::None
(don't import the variants)

View changes since the review

@rust-bors

rust-bors Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: b2e91b7 (b2e91b7f17cefe008d1fa62606cc5049d9b68899)
Base parent: 76c9095 (76c90957b7e422c4b9c45192b0197214d7de5a54)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (b2e91b7): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up.

@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This perf run didn't have relevant results for this metric.

Max RSS (memory usage)

This perf run didn't have relevant results for this metric.

Cycles

Results (secondary 2.7%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.7% [2.1%, 3.4%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 490.84s -> 489.964s (-0.18%)
Artifact size: 406.48 MiB -> 406.53 MiB (0.01%)

Signed-off-by: Richard Tjokroutomo <richard.tjokro2@gmail.com>
Signed-off-by: Richard Tjokroutomo <richard.tjokro2@gmail.com>
@RichardTjokroutomo

Copy link
Copy Markdown
Author

@rustbot ready

This branch has not been deployed

No deployments
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.

7 participants