Skip to content

move #[macro_export] on declarative macro check to rustc_attr_parsing - #163314

Open
darkraider01 wants to merge 4 commits into
rust-lang:mainfrom
darkraider01:check-macro-export
Open

darkraider01 wants to merge 4 commits into
rust-lang:mainfrom
darkraider01:check-macro-export

Conversation

@darkraider01

@darkraider01 darkraider01 commented Sep 25, 2026 •

Copy link
Copy Markdown

Summary:
Moves the declarvative mactor #[macro_export] check to attribute parsing in rustc_attr_parsing, which makes target_item available in the SharedContext so that the parser can check for !macro_def.macro_rules. Also removes the old check from rustc_passes::check_attr.
Tests:

./x test tests/ui/attributes/macro_export_on_decl_macro.rs
Part of rust-lang/rust#153101.

@rustbot

rustbot commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

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

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 25, 2026
@rustbot

rustbot commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project has assigned @oli-obk (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 77 candidates
  • Random selection from 22 candidates

@oli-obk

oli-obk commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

For which parts of this PR did you use an LLM?

@oli-obk oli-obk 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 25, 2026
@darkraider01

Copy link
Copy Markdown
Author

i used codex sol 6 for giving it implementation steps, and how to approach, and code written part is by me since it wouldnt edit the codebase . Reviewed it via codex and asked it to make a PR description. So thats the llm usage in this pr

@oli-obk

oli-obk commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Please read our LLM policy and edit your PR to be within the rules.

@darkraider01

Copy link
Copy Markdown
Author

sorry, updated the PR description, its the only part which it LLM touched by itself.

@rust-bors

This comment has been minimized.

@rustbot

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

@JonathanBrouwer

Copy link
Copy Markdown
Member

r? me

@rustbot rustbot assigned JonathanBrouwer and unassigned oli-obk Sep 30, 2026
@JonathanBrouwer JonathanBrouwer 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 30, 2026

let attr_span = cx.attr_span;
if cx.target == Target::MacroDef
&& let Some(item) = cx.target_item

@JonathanBrouwer JonathanBrouwer Sep 30, 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 would silently not emit anything if target_item is None, which should never happen. Can you make it panic instead?

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.

the resolver’s early pass uses ShouldEmit::Nothing and passes no target_item and the guard skips that pass because an unconditional unwrap caused an ICE. The normal lint-emitting path still panics if target_item is unexpectedly missing.

@JonathanBrouwer JonathanBrouwer Sep 30, 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 think the real problem is then that finalize_checks is even being called when ShouldEmit::Nothing is active.
Could you fix that and panic if target_item is None?
@rustbot author

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.

that deferred checks now skip the resolver’s ShouldEmit::Nothing pass, and that the normal path still panics if target_item is unexpectedly missing.

pub(crate) target: Target,

/// The AST item these attributes were applied to, when the target is an item.
pub(crate) target_item: Option<&'p rustc_ast::ast::Item>,

@JonathanBrouwer JonathanBrouwer Sep 30, 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'm not sure how I feel about moving target_item here, I think it's unneccesary. Can you move it back, and place the lint emitting code in the finalize_check function?

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.

target_item is back in FinalizeCheckContext, and the unecessary SharedContext changes were removed. The lint check now runs in finalize_check.

@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 30, 2026
@rustbot

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

@darkraider01

darkraider01 commented Sep 30, 2026 •

Copy link
Copy Markdown
Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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-author Status: This is awaiting some action (such as code changes or more information) from the author. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 30, 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-author Status: This is awaiting some action (such as code changes or more information) from the author. 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