Skip to content

#[derive(Debug)] on #[repr(packed)] enum causes internal compiler error #133025

Closed

Description

@urinacon

Code

#[derive(Debug)]
#[repr(packed)]
enum COption<T> {
    None,
    Some(T),
}

fn main() {
}

Meta

rustc --version --verbose:

rustc 1.82.0 (f6e511eec 2024-10-15) (Fedora 1.82.0-1.fc40)
binary: rustc
commit-hash: f6e511eec7342f59a25f7c0534f1dbea00d01b14
commit-date: 2024-10-15
host: x86_64-unknown-linux-gnu
release: 1.82.0
LLVM version: 18.1.8

Error output

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<dyn Any>
stack backtrace:
   0:     0x7fd20cb85b78 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h1ceeeb1b55e290c2
   1:     0x7fd20c582b9b - core::fmt::write::hb3a48913f78b0dae
   2:     0x7fd20cb78ba3 - <unknown>
   3:     0x7fd20cb887ea - <unknown>
   4:     0x7fd20cb8842c - std::panicking::default_hook::h49089136d7ad7532
   5:     0x7fd20a1425ad - <unknown>
   6:     0x7fd20cb891e6 - std::panicking::rust_panic_with_hook::ha43241025fb228f0
   7:     0x7fd20a18c221 - <unknown>
   8:     0x7fd20a17c246 - <unknown>
   9:     0x7fd20a17bfc6 - <unknown>
  10:     0x7fd20a19a8e1 - <rustc_errors[9a66caa3f8a65bb2]::diagnostic::BugAbort as rustc_errors[9a66caa3f8a65bb2]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  11:     0x7fd20a92c36d - <unknown>
  12:     0x7fd20a96b188 - <unknown>
  13:     0x7fd20a96bada - <unknown>
  14:     0x7fd20a9570db - <unknown>
  15:     0x7fd20a94dd57 - <unknown>
  16:     0x7fd20be2d539 - <unknown>
  17:     0x7fd20bf150eb - rustc_mir_transform[ec94f2ac466ce048]::mir_built
  18:     0x7fd20c1c6467 - <unknown>
  19:     0x7fd20ac4e640 - <unknown>
  20:     0x7fd20ac3cb28 - <unknown>
  21:     0x7fd20ad4ed98 - <unknown>
  22:     0x7fd20bd63e17 - rustc_mir_build[b87ccf4b6ee18353]::check_unsafety::check_unsafety
  23:     0x7fd20c1b87f7 - <unknown>
  24:     0x7fd20ac4dd90 - <unknown>
  25:     0x7fd20ac3714e - <unknown>
  26:     0x7fd20ad5d45f - <unknown>
  27:     0x7fd20baa8cbb - <unknown>
  28:     0x7fd20c8bd509 - rustc_interface[73b4cfe22fadb0e6]::passes::analysis
  29:     0x7fd20ca728b7 - <unknown>
  30:     0x7fd20ac4d70f - <unknown>
  31:     0x7fd20ac06129 - <unknown>
  32:     0x7fd20ad49194 - <unknown>
  33:     0x7fd20c7b0ee4 - <unknown>
  34:     0x7fd20c7ad945 - <unknown>
  35:     0x7fd20c7b3dd0 - <unknown>
  36:     0x7fd20cb952ab - <unknown>
  37:     0x7fd2094a66d7 - start_thread
  38:     0x7fd20952a60c - __clone3
  39:                0x0 - <unknown>

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 `<impl at src/main.rs:1:10: 1:15>::fmt`
#1 [check_unsafety] unsafety-checking `<impl at src/main.rs:1:10: 1:15>::fmt`
end of query stack
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<dyn Any>
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 `<impl at src/main.rs:1:10: 1:15>::fmt`
#1 [check_unsafety] unsafety-checking `<impl at src/main.rs:1:10: 1:15>::fmt`
#2 [analysis] running analysis passes on this crate
end of query stack

Activity

  1. added
    C-bugCategory: This is a bug.
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Nov 14, 2024
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Nov 14, 2024
  3. added
    E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Nov 14, 2024
  4. Noratrieb commented on Nov 14, 2024

    @Noratrieb
    Member
    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.

  5. zachs18 commented on Nov 14, 2024

    @zachs18
    Contributor

    This appears to have regressed in 1.78.0 on stable (1.77.0 does not ICE), or nightly-2024-02-09.

    bisection

    Bisection determined this regressed in nightly-2024-02-09, but there's no CI artifacts from that far back, so I'm not sure which PR led to the ICE.

    Bisected with cargo bisect-rustc --start=1.77.0 --end=1.78.0 --regress ice

    searched toolchains nightly-2024-02-01 through nightly-2024-03-16
    
    
    ********************************************************************************
    Regression in nightly-2024-02-09
    ********************************************************************************
    
    fetching https://static.rust-lang.org/dist/2024-02-08/channel-rust-nightly-git-commit-hash.txt
    nightly manifest 2024-02-08: 40 B / 40 B [=====================================================================] 100.00 % 846.46 KB/s converted 2024-02-08 to 8ace7ea1f7cbba7b4f031e66c54ca237a0d65de6
    fetching https://static.rust-lang.org/dist/2024-02-09/channel-rust-nightly-git-commit-hash.txt
    nightly manifest 2024-02-09: 40 B / 40 B [=====================================================================] 100.00 % 521.58 KB/s converted 2024-02-09 to 98aa3624be70462d6a25ed5544333e3df62f4c66
    looking for regression commit between 2024-02-08 and 2024-02-09
    fetching (via remote github) commits from max(8ace7ea1f7cbba7b4f031e66c54ca237a0d65de6, 2024-02-06) to 98aa3624be70462d6a25ed5544333e3df62f4c66
    ending github query because we found starting sha: 8ace7ea1f7cbba7b4f031e66c54ca237a0d65de6
    get_commits_between returning commits, len: 9
      commit[0] 2024-02-07: Auto merge of #120748 - Nadrieril:rollup-dj0qwv5, r=Nadrieril
      commit[1] 2024-02-08: Auto merge of #120381 - fee1-dead-contrib:reconstify-add, r=compiler-errors
      commit[2] 2024-02-08: Auto merge of #120521 - reitermarkus:generic-nonzero-constructors, r=dtolnay
      commit[3] 2024-02-08: Auto merge of #120558 - oli-obk:missing_impl_item_ice, r=estebank
      commit[4] 2024-02-08: Auto merge of #120579 - GuillaumeGomez:prevent-running-unneeded-code, r=notriddle
      commit[5] 2024-02-08: Auto merge of #120550 - oli-obk:track_errors8, r=estebank
      commit[6] 2024-02-08: Auto merge of #120767 - matthiaskrgr:rollup-0k8ib1c, r=matthiaskrgr
      commit[7] 2024-02-08: Auto merge of #120544 - BoxyUwU:enter_forall, r=lcnr
      commit[8] 2024-02-08: Auto merge of #120807 - matthiaskrgr:rollup-1pf3glu, r=matthiaskrgr
    ERROR: no CI builds available between 8ace7ea1f7cbba7b4f031e66c54ca237a0d65de6 and 98aa3624be70462d6a25ed5544333e3df62f4c66 within last 167 days
  6. matthiaskrgr commented on Nov 14, 2024

    @matthiaskrgr
    Member

    Duplicate of #120873 I think

  7. Noratrieb commented on Nov 14, 2024

    @Noratrieb
    Member

    don't think so

  8. matthiaskrgr commented on Nov 14, 2024

    @matthiaskrgr
    Member

    What difference do you see?
    The stacktrace of

    #[derive(Debug)]
    #[repr(packed)]
    enum COption<T> {
        None,
        Some(T),
    }
    
    fn main() {
    }

    is identical to #120873 (comment)

    #[repr(packed)]
    
    struct Dealigned<T>(u8, T);
    
    #[derive(PartialEq)]
    #[repr(C)]
    struct Dealigned<T>(u8, T);
  9. Noratrieb commented on Nov 14, 2024

    @Noratrieb
    Member

    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.

  10. added
    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
    on Nov 17, 2024
  11. el-ev commented on Dec 26, 2024

    @el-ev
    Contributor

    Introduced by eab2adb.

  12. moxian commented on Mar 11, 2025

    @moxian
    Contributor

    Both this and #120873 bisect same way to nightly-2024-02-09
    Even though the ICE has been triggerable since 2017 (#120873 (comment))

    Either way,
    @rustbot label: -E-needs-bisection

  13. removed
    E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc
    on Mar 11, 2025
  14. self-assigned this
    on Sep 10, 2026
  15. added 2 commits that reference this issue on Sep 13, 2026
  16. added a commit that references this issue on Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-repr-packedArea: the naughtiest reprC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions