Files
rust/compiler/rustc_error_codes
Jonathan Brouwer 300ef7ae5b Rollup merge of #162160 - RalfJung:aligned-in-packed, r=mu001999
turn aligned-in-packed error into lint

Fixes https://github.com/rust-lang/rust/issues/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 https://github.com/rust-lang/rfcs/pull/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 https://github.com/rust-lang/rfcs/issues/3060; see that issue for a usecase that's made unnecessarily hard by the status quo.

[Three years ago](https://github.com/rust-lang/rust/issues/80926#issuecomment-1716238277), 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
2026-09-14 15:16:00 +02:00
..