Skip to content

Move check_rustc_pub_transparent into the attribute parser#158496

Open
obeis wants to merge 2 commits into
rust-lang:mainfrom
obeis:move-check-rustc-pub-transparen
Open

Move check_rustc_pub_transparent into the attribute parser#158496
obeis wants to merge 2 commits into
rust-lang:mainfrom
obeis:move-check-rustc-pub-transparen

Conversation

@obeis

@obeis obeis commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Updates #153101

Verify the #[repr(transparent)] requirement in RustcPubTransparentParser::finalize_check, replacing check_rustc_pub_transparent in rustc_passes.

r? @JonathanBrouwer

@rustbot

rustbot commented Jun 27, 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 Jun 27, 2026
@obeis obeis force-pushed the move-check-rustc-pub-transparen branch from 4756680 to 36e0436 Compare June 27, 2026 18:57
@rustbot

rustbot commented Jun 27, 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.

@obeis obeis force-pushed the move-check-rustc-pub-transparen branch from 36e0436 to a5834bd Compare June 27, 2026 19:19
.filter_map(|attr| attr.args.as_ref()?.as_list())
.flat_map(|list| list.mixed())
.filter_map(|item| item.meta_item())
.any(|meta| meta.path().word_is(sym::transparent))

@JonathanBrouwer JonathanBrouwer Jun 27, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmmm I don't really like that we're duplicating some of the Repr parsing logic here.
How hard would it be to get access to the parsed repr attribute here?

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I see two ways to handle this:

  1. Extract a helper function:that holds the iteration logic currently inlined in lint_helpers.rs. I'd move it next to the repr parser in repr.rs so the logic lives in one place.
  2. Add the parsed attributes to FinalizeContext, so we can match on AttributeKind::Repr directly instead of re-walking the raw attribute args.
    I think the second approach is much cleaner, since it avoids re-parsing entirely.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I prefer #2 strongly but the parsed attributes are only available after finalization, I think it's possible to work around that tho

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 27, 2026
@rustbot

rustbot commented Jun 27, 2026

Copy link
Copy Markdown
Collaborator

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

@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jun 27, 2026
obeis added 2 commits June 28, 2026 14:52
the parsed attributes of an item were only fully populated after all
finalizers had run, so `finalize_check` (run during finalization) could
only inspect attribute *paths* via `FinalizeContext::all_attrs`, not the
parsed `AttributeKind`s.

split finalization into two passes: first run all finalizers to produce
the parsed attributes, then run the cross-attribute checks. The checks are
deferred via a new `AttributeParser::deferred_finalize_check`, and can now
inspect the fully parsed attributes through a new
`FinalizeContext::parsed_attrs` field.
the check that `#[rustc_pub_transparent]` is only applied to
`#[repr(transparent)]` types needs to see the parsed `Repr` attribute, so
it now lives in `RustcPubTransparentParser::finalize_check`, using the
freshly available `FinalizeContext::parsed_attrs`.
@obeis obeis force-pushed the move-check-rustc-pub-transparen branch from a5834bd to b6b2e9c Compare June 28, 2026 17:31
@obeis obeis requested a review from JonathanBrouwer June 28, 2026 17:33
@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 Jun 28, 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.

3 participants