Open urinacon opened 3 days ago
error[E0517]: attribute should be applied to a struct or union
--> src/main.rs:2:8
|
2 | #[repr(packed)]
| ^^^^^^
3 | / enum COption<T> {
4 | | None,
5 | | Some(T),
6 | | }
| |_- not a struct or union
For more information about this error, try `rustc --explain E0517`.
repr(packed)
on enums is not allowed. I suspect the easiest fix is to make the derive macro error or expand to nothing when it sees repr(packed). alternatively, the MIR transform could just ignore enums.
This appears to have regressed in 1.78.0 on stable (1.77.0 does not ICE), or nightly-2024-02-09
.
Duplicate of https://github.com/rust-lang/rust/issues/120873 I think
don't think so
What difference do you see? The stacktrace of
#[derive(Debug)]
#[repr(packed)]
enum COption<T> {
None,
Some(T),
}
fn main() {
}
is identical to https://github.com/rust-lang/rust/issues/120873#issue-2128275994
#[repr(packed)]
struct Dealigned<T>(u8, T);
#[derive(PartialEq)]
#[repr(C)]
struct Dealigned<T>(u8, T);
Yes, it's the exact same check firing. But I think the check is firing for entirely different reasons. It could be the same but I'd be surprised. It's nice to have the links between the two issues because they are similar but I certainly wouldn't close this.
Code
Meta
rustc --version --verbose
:Error output
Backtrace
``` error: internal compiler error: compiler/rustc_mir_transform/src/check_packed_ref.rs:49:21: builtin derive created an unaligned reference --> src/main.rs:5:10 | 1 | #[derive(Debug)] | ----- in this derive macro expansion ... 5 | Some(T), | ^ | = note: this error: internal compiler error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) thread 'rustc' panicked at compiler/rustc_mir_transform/src/check_packed_ref.rs:49:21: Box
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md
note: rustc 1.82.0 (f6e511eec 2024-10-15) (Fedora 1.82.0-1.fc40) running on x86_64-unknown-linux-gnu
note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]
note: some of the compiler flags provided by cargo are hidden
query stack during panic:
#0 [mir_built] building MIR for `::fmt`
#1 [check_unsafety] unsafety-checking `::fmt`
#2 [analysis] running analysis passes on this crate
end of query stack
```