Skip to content

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

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

Move #[naked] attribute check to attribute parsing stage#162530
RichardTjokroutomo wants to merge 2 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, add target_associated_item as an additional field. Lastly, move check_naked to the callback returned by NakedParser::deferred_finalize_check().

Part of #153101. r?@JonathanBrouwer

LLM disclosure: I wrote the code by hand & took inspiration from #161482. However, I did use LLM to learn how attribute checking is done in Rustc.

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

};

let ItemKind::Fn(fn_item) = &item.kind else {
return;

@JonathanBrouwer JonathanBrouwer Sep 11, 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.

This should never fail right? So please make this panic

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.

After implementing panic, through the failing CI I just found out that methods defined under traits & impls are represented as associated item instead of normal item.... lucky...

MethodKind::Trait { body: true } | MethodKind::TraitImpl | MethodKind::Inherent,
) => {
let Some(item) = cx.target_item else {
return;

@JonathanBrouwer JonathanBrouwer Sep 11, 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.

/// - support unwinding with `-Cpanic=unwind`, unlike `extern "C"`
/// - often diverge from the C ABI
/// - are subject to change between compiler versions
pub fn is_rustic_abi(self) -> bool {

@JonathanBrouwer JonathanBrouwer Sep 11, 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.

Can we avoid duplicating this logic?
Perhaps by parsing the abi into a ExternAbi instead?

View changes since the review

@RichardTjokroutomo RichardTjokroutomo Sep 11, 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.

I don't think we can. I originally tried to convert it to ExternAbi, but I couldn't compile as it creates circular dependency (haven't checked deeper as to why, though).

Then I saw similar check for CanonAbi, and I thought since the logic is already duplicated elsewhere, perhaps I can also add similar method to Extern.

target_span: Span,
target_hir_id: HirId,
target: Target,
target_item: Option<&ast::Item>,

@JonathanBrouwer JonathanBrouwer Sep 11, 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.

Please rebase on #161482 after it is merged

View changes since the review

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

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

rustbot commented Sep 11, 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.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@RichardTjokroutomo
RichardTjokroutomo force-pushed the check-attr-naked branch 2 times, most recently from 7afc73b to 07f3466 Compare September 11, 2026 14:43
@rust-log-analyzer

This comment has been minimized.

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

5 participants