Skip to content

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

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

RichardTjokroutomo wants to merge 12 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

This comment has been minimized.

Signed-off-by: Richard Tjokroutomo <richard.tjokro2@gmail.com>
Signed-off-by: Richard Tjokroutomo <richard.tjokro2@gmail.com>
Signed-off-by: Richard Tjokroutomo <richard.tjokro2@gmail.com>
Signed-off-by: Richard Tjokroutomo <richard.tjokro2@gmail.com>
…functions calling lower_attrs()

Signed-off-by: Richard Tjokroutomo <richard.tjokro2@gmail.com>
Signed-off-by: Richard Tjokroutomo <richard.tjokro2@gmail.com>
Signed-off-by: Richard Tjokroutomo <richard.tjokro2@gmail.com>
Signed-off-by: Richard Tjokroutomo <richard.tjokro2@gmail.com>
@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>
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

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.

6 participants