Skip to content

turn aligned-in-packed error into lint - #162160

Open
RalfJung wants to merge 1 commit into
rust-lang:mainfrom
RalfJung:aligned-in-packed
Open

turn aligned-in-packed error into lint#162160
RalfJung wants to merge 1 commit into
rust-lang:mainfrom
RalfJung:aligned-in-packed

Conversation

@RalfJung

@RalfJung RalfJung commented Sep 1, 2026

Copy link
Copy Markdown
Member

Fixes #80926:
The aligned-in-packed check ignores the fact that generics exist, so it can trivially be bypassed. Acknowledge that by downgrading the hard error to a lint. The lint also only fires for repr(C) types, because that's the only case where that is a problem: the type may not actually match what the C compiler for the target does, if that C compiler is MSVC. This is tied up with rust-lang/rfcs#3845 and the general tension around repr(C) as a repr for predictable stable layout vs C compatibility. The error doesn't really help to make fixing the mess any easier though, so let's de-fang it.

Also fixes rust-lang/rfcs#3060; see that issue for a usecase that's made unnecessarily hard by the status quo.

Three years ago, the t-lang vibes seem to have been "yes let's downgrade this to a lint, that's kind of what it already is anyway".

Questions for t-lang:

  • Are you still on-board with this?
  • How should the lint be called? I went with aligned_fields_in_packed.
  • When exactly should it fire? I currently require the outer packed type, the inner aligned type, and all the types in between to be repr(C). For Rust types I see no reason at all to forbid this combination, we can just define whatever we want for the layout there and IMO the current behavior makes a lot of sense.
  • What should the default lint level be? I went with "deny" since it was a hard error after all.

Cc @rust-lang/opsem

@RalfJung RalfJung added needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. I-lang-nominated Nominated for discussion during a lang team meeting. labels Sep 1, 2026
@rustbot rustbot added 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 1, 2026
@rustbot

rustbot commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

r? @mu001999

rustbot has assigned @mu001999.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 75 candidates
  • Random selection from 21 candidates

@mu001999 mu001999 added S-waiting-on-t-lang Status: Awaiting decision from T-lang and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 2, 2026
@traviscross traviscross added P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang I-lang-radar Items that are on lang's radar and will need eventual work or consideration. labels Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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. P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang S-waiting-on-t-lang Status: Awaiting decision from T-lang 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.

Aligned-in-packed restriction can be circumvented with generic parameters Aligned structs in packed structs

4 participants