Skip to content

lint against repeated repr attributes - #157036

Open
ettolrach wants to merge 15 commits into
rust-lang:mainfrom
ettolrach:disallow-repeated-reprs
Open

lint against repeated repr attributes#157036
ettolrach wants to merge 15 commits into
rust-lang:mainfrom
ettolrach:disallow-repeated-reprs

Conversation

@ettolrach

@ettolrach ettolrach commented May 27, 2026

Copy link
Copy Markdown

View all comments

fixes #156029 by adding a lint against repeated repr attributes.

r? scottmcm

@rustbot rustbot added 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. labels May 27, 2026
@rust-log-analyzer

This comment has been minimized.

@traviscross traviscross added T-lang Relevant to the language team needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. I-lang-radar Items that are on lang's radar and will need eventual work or consideration. labels May 27, 2026
@scottmcm

Copy link
Copy Markdown
Member

Wearing my lang hat but not speaking as team consensus (since we've not talked about it):

I think you should start with the "obviously good" version, and we can do future PRs later to expand it or to update severity. Concretely, thus, I'd say it should be a warning (because if it's inert it doesn't need to be deny) when you have a clearly-unnecessary one that wasn't emitted from a macro, or something like that.

(Our bar in the compiler for deny-by-default is pretty high. My personal heuristic is whether it's worth running your unit tests despite the warning, and an inert extra attribute doesn't need to block that.)

We can then look at impacts and ratchet it up over time or over an edition, but those decisions can be made later and don't need to block you making a useful lint in the meantime.


I'm a bad reviewer for lint stuff code-wise, though, so let's try
r? JonathanBrouwer

@rustbot rustbot assigned JonathanBrouwer and unassigned scottmcm May 30, 2026
@traviscross

Copy link
Copy Markdown
Contributor

+1 to what @scottmcm said on how best to approach this.

@rust-bors

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@ettolrach
ettolrach marked this pull request as ready for review June 6, 2026 17:03
@rustbot

rustbot commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator

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

cc @jdonszelmann, @JonathanBrouwer

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

This comment has been minimized.

@rustbot rustbot added the has-merge-commits PR has merge commits, merge with caution. label Jun 6, 2026
@ettolrach
ettolrach force-pushed the disallow-repeated-reprs branch from ae3cdee to 314903c Compare June 6, 2026 17:28
@rustbot rustbot removed the has-merge-commits PR has merge commits, merge with caution. label Jun 6, 2026
@jdonszelmann

Copy link
Copy Markdown
Contributor

r? jdonszelmann
I don't mind giving this one a look :)

@rust-bors

This comment has been minimized.

@ettolrach
ettolrach force-pushed the disallow-repeated-reprs branch from 75cb11a to fd1a979 Compare June 21, 2026 19:30
@rustbot

This comment has been minimized.

@jdonszelmann

Copy link
Copy Markdown
Contributor

Like this it looks good!

@bors r+ rollup

@rust-bors

rust-bors Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

📋 This PR cannot be approved because it currently has the following label: needs-fcp.

@jdonszelmann

jdonszelmann commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

welp, fair enough @rust-lang/lang feel free to do an FCP on this one, r=me after that

@rustbot

This comment has been minimized.

@ettolrach
ettolrach force-pushed the disallow-repeated-reprs branch from ae3abc4 to 80cde70 Compare July 28, 2026 10:05
@rustbot

rustbot commented Jul 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.

@ettolrach
ettolrach force-pushed the disallow-repeated-reprs branch from 80cde70 to d1a8d0d Compare July 28, 2026 10:10
@ettolrach
ettolrach force-pushed the disallow-repeated-reprs branch from d1a8d0d to 224a101 Compare July 28, 2026 10:16
@ettolrach

Copy link
Copy Markdown
Author

@jdonszelmann you've still got requested changes here (just in the UI, i did do the thing you wanted me to). it also doesn't look like this ping worked, so i guess i'll try it myself? though i don't think it'll go through. @rust-lang/lang

@scottmcm scottmcm added I-lang-nominated Nominated for discussion during a lang team meeting. I-lang-easy-decision Issue: The decision needed by the team is conjectured to be easy; this does not imply nomination labels Jul 28, 2026
@scottmcm

Copy link
Copy Markdown
Member

(Nominating to look at in triage tomorrow; sorry for the delay)

This adds a new repeated_reprs lint as warn-by-default that triggers on things like

#[repr(transparent)]
#[repr(transparent)]

Hopefully this is an easy accept because we'd talked about doing this in a previous meeting 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) I-lang-easy-decision Issue: The decision needed by the team is conjectured to be easy; this does not imply nomination I-lang-nominated Nominated for discussion during a lang team meeting. I-lang-radar Items that are on lang's radar and will need eventual work or consideration. needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. 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. T-lang Relevant to the language team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

#[repr()] attribute has inconsistent handling of duplicates.

7 participants