Skip to content

Implement argument-dependent target checking for the #[repr] parser#157215

Open
JonathanBrouwer wants to merge 5 commits into
rust-lang:mainfrom
JonathanBrouwer:repr-target-checking3
Open

Implement argument-dependent target checking for the #[repr] parser#157215
JonathanBrouwer wants to merge 5 commits into
rust-lang:mainfrom
JonathanBrouwer:repr-target-checking3

Conversation

@JonathanBrouwer
Copy link
Copy Markdown
Contributor

Fixes some of #156499
Fixes some of #153101
Alternative approach to #156569, which was suggested in the comments here: #156569 (review)

How do you feel about this approach?
r? @mejrs

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 31, 2026

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

cc @jdonszelmann

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann

@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 May 31, 2026
@JonathanBrouwer JonathanBrouwer force-pushed the repr-target-checking3 branch from 7758293 to d58ea4a Compare May 31, 2026 19:27
@jdonszelmann
Copy link
Copy Markdown
Contributor

I like this approach of using ManuallyChecked and asserting whether it was! Good solution :3

Copy link
Copy Markdown
Contributor

@mejrs mejrs left a comment

Choose a reason for hiding this comment

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

Ugh, #[repr] gives me a headache.

Anyway, the implementation looks good generally.

What is the plan going forward? I imagine a series of prs like:

  • macrocall checking for the other attrs in #156499
  • some kind of "this attribute does nothing even if this macro call expands into a valid target" note on the warning
  • a PR to raise the lint level to deny by default for repr attrs on macro calls and do something about the repr(simd) thing

View changes since this review

Comment thread compiler/rustc_attr_parsing/src/attributes/repr.rs Outdated
Comment thread compiler/rustc_attr_parsing/src/attributes/repr.rs
@@ -1,8 +1,10 @@
#### Note: this error code is no longer emitted by the compiler.

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.

Same with the other PR, please direct to the new error code.

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.

There is no new error code, the new diagnostic doesn't have one :p.
Added a comment saying this

Comment thread compiler/rustc_attr_parsing/src/attributes/repr.rs Outdated
Comment thread compiler/rustc_attr_parsing/src/target_checking.rs Outdated
Comment on lines +1208 to 1211
let (reprs, _first_attr_span) =
find_attr!(attrs, Repr { reprs, first_span } => (reprs.as_slice(), Some(*first_span)))
.unwrap_or((&[], None));

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.

Suggested change
let (reprs, _first_attr_span) =
find_attr!(attrs, Repr { reprs, first_span } => (reprs.as_slice(), Some(*first_span)))
.unwrap_or((&[], None));
let reprs = find_attr!(attrs, Repr { reprs, .. } => reprs.as_slice()).unwrap_or(&[]);

Also do we still need to keep first_span in the AttributeKind::Repr?

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.

Yes we do sadly :c
It is still used for a few diagnostics later, I might try moving those in a followup PR

@rust-bors

This comment has been minimized.

@JonathanBrouwer
Copy link
Copy Markdown
Contributor Author

(still need to actually push my changes that fixed your review comments, blocked on #157291)

@JonathanBrouwer
Copy link
Copy Markdown
Contributor Author

What is the plan going forward? I imagine a series of prs like:
* macrocall checking for the other attrs in #156499
* some kind of "this attribute does nothing even if this macro call expands into a valid target" note on the warning
* a PR to raise the lint level to deny by default for repr attrs on macro calls and do something about the repr(simd) thing

The first one was already my plan indeed, the other two also sound like great ideas :)

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 2, 2026
…cking, r=mejrs

Clean up attribute target checking diagnostics

Split off from me trying to process your review comments in rust-lang#157215

Thanks to @GuillaumeGomez for making this possible <3

r? @mejrs
@mejrs mejrs 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 Jun 2, 2026
rust-timer added a commit that referenced this pull request Jun 2, 2026
Rollup merge of #157291 - JonathanBrouwer:cleanup-target-checking, r=mejrs

Clean up attribute target checking diagnostics

Split off from me trying to process your review comments in #157215

Thanks to @GuillaumeGomez for making this possible <3

r? @mejrs
@JonathanBrouwer JonathanBrouwer force-pushed the repr-target-checking3 branch from d58ea4a to 2a8fee0 Compare June 2, 2026 17:48
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Jun 2, 2026

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
Contributor Author

@rustbot ready
I think I processed all your feedback :)

@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 2, 2026
Copy link
Copy Markdown
Contributor

@mejrs mejrs left a comment

Choose a reason for hiding this comment

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

r=me with ci green

View changes since this review

Comment on lines +148 to +149
Warn(Target::MacroCall),
]), // FIXME: This is not feature gated (!!)
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.

one line off, but this fixme should be removed soon anyway 🤷

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.

4 participants