Skip to content

ICE: builtin derive created an unaligned reference #129779

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Robbepop opened this issue Aug 30, 2024 · 2 comments
Closed

ICE: builtin derive created an unaligned reference #129779

Robbepop opened this issue Aug 30, 2024 · 2 comments
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Robbepop
Copy link
Contributor

I tried this code:

#[derive(PartialEq)]
#[repr(packed)]
pub enum Foo {
    Bar,
    Baz(i32),
}

I expected to see this happen: Proper compiler error stating that #[repr(packed)] cannot be applied to enum.

Instead, this happened: The following ICE:

error[E0517]: attribute should be applied to a struct or union
   --> crates/ir/src/primitive.rs:562:8
    |
562 |   #[repr(packed)]
    |          ^^^^^^
563 | / pub enum Foo {
564 | |     Bar,
565 | |     Baz(i32),
566 | | }
    | |_- not a struct or union

error: internal compiler error: compiler/rustc_mir_transform/src/check_packed_ref.rs:50:21: builtin derive created an unaligned reference
   --> crates/ir/src/primitive.rs:565:9
    |
561 | #[derive(PartialEq)]
    |          --------- in this derive macro expansion
...
565 |     Baz(i32),
    |         ^^^
    |
    = note: this error: internal compiler error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)

Meta

The bug also happens on the nightly Rust compiler version.

rustc 1.80.1 (3f5fd8dd4 2024-08-06)
binary: rustc
commit-hash: 3f5fd8dd41153bc5fdca9427e9e05be2c767ba23
commit-date: 2024-08-06
host: aarch64-apple-darwin
release: 1.80.1
LLVM version: 18.1.7

Backtrace:

thread 'rustc' panicked at compiler/rustc_mir_transform/src/check_packed_ref.rs:50:21:
Box<dyn Any>
stack backtrace:
   0:        0x105608c1c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h41035ce174e31160
   1:        0x10564d87c - core::fmt::write::h7e946826fce7616b
   2:        0x1055ff088 - std::io::Write::write_fmt::he3645adfefb23e4a
   3:        0x105608a74 - std::sys_common::backtrace::print::h2efe9ae66fda73dc
   4:        0x10560b080 - std::panicking::default_hook::{{closure}}::hd27200b4fbd3bf40
   5:        0x10560ad4c - std::panicking::default_hook::hb8656334461229c8
   6:        0x10ec8f380 - <alloc[9bfd1da98798fc47]::boxed::Box<rustc_driver_impl[1ef2360f78401c14]::install_ice_hook::{closure#0}> as core[cec0bd9d2fc86fa9]::ops::function::Fn<(&dyn for<'a, 'b> core[cec0bd9d2fc86fa9]::ops::function::Fn<(&'a core[cec0bd9d2fc86fa9]::panic::panic_info::PanicInfo<'b>,), Output = ()> + core[cec0bd9d2fc86fa9]::marker::Sync + core[cec0bd9d2fc86fa9]::marker::Send, &core[cec0bd9d2fc86fa9]::panic::panic_info::PanicInfo)>>::call
   7:        0x10560ba6c - std::panicking::rust_panic_with_hook::h10171cf76e1aed15
   8:        0x10ed18f88 - std[4ec0ba9e3c6d748b]::panicking::begin_panic::<rustc_errors[841c19fe687cbd93]::ExplicitBug>::{closure#0}
   9:        0x10ed18e24 - std[4ec0ba9e3c6d748b]::sys_common::backtrace::__rust_end_short_backtrace::<std[4ec0ba9e3c6d748b]::panicking::begin_panic<rustc_errors[841c19fe687cbd93]::ExplicitBug>::{closure#0}, !>
  10:        0x112d8590c - std[4ec0ba9e3c6d748b]::panicking::begin_panic::<rustc_errors[841c19fe687cbd93]::ExplicitBug>
  11:        0x10ed28144 - <rustc_errors[841c19fe687cbd93]::diagnostic::BugAbort as rustc_errors[841c19fe687cbd93]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:        0x10fa98034 - <rustc_errors[841c19fe687cbd93]::DiagCtxt>::span_bug::<rustc_span[22cad54eabbc67cf]::span_encoding::Span, alloc[9bfd1da98798fc47]::string::String>
  13:        0x10faa107c - rustc_middle[2867706b5eb6f7f9]::util::bug::opt_span_bug_fmt::<rustc_span[22cad54eabbc67cf]::span_encoding::Span>::{closure#0}
  14:        0x10faa10b0 - rustc_middle[2867706b5eb6f7f9]::ty::context::tls::with_opt::<rustc_middle[2867706b5eb6f7f9]::util::bug::opt_span_bug_fmt<rustc_span[22cad54eabbc67cf]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  15:        0x10faa02a4 - rustc_middle[2867706b5eb6f7f9]::ty::context::tls::with_context_opt::<rustc_middle[2867706b5eb6f7f9]::ty::context::tls::with_opt<rustc_middle[2867706b5eb6f7f9]::util::bug::opt_span_bug_fmt<rustc_span[22cad54eabbc67cf]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  16:        0x112e49f8c - rustc_middle[2867706b5eb6f7f9]::util::bug::span_bug_fmt::<rustc_span[22cad54eabbc67cf]::span_encoding::Span>
  17:        0x10f9c5304 - <rustc_mir_transform[ff5c24210d5f1369]::check_packed_ref::PackedRefChecker as rustc_middle[2867706b5eb6f7f9]::mir::visit::Visitor>::visit_place
  18:        0x10f9c4f14 - <rustc_mir_transform[ff5c24210d5f1369]::check_packed_ref::CheckPackedRef as rustc_mir_transform[ff5c24210d5f1369]::pass_manager::MirLint>::run_lint
  19:        0x10fa91cb8 - rustc_mir_transform[ff5c24210d5f1369]::pass_manager::run_passes_inner
  20:        0x10fb59498 - rustc_mir_transform[ff5c24210d5f1369]::mir_built
  21:        0x10ff28f64 - rustc_query_impl[9b9172b7a4c3de5d]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9b9172b7a4c3de5d]::query_impl::mir_built::dynamic_query::{closure#2}::{closure#0}, rustc_middle[2867706b5eb6f7f9]::query::erase::Erased<[u8; 8usize]>>
  22:        0x10ffe46dc - <rustc_query_impl[9b9172b7a4c3de5d]::query_impl::mir_built::dynamic_query::{closure#2} as core[cec0bd9d2fc86fa9]::ops::function::FnOnce<(rustc_middle[2867706b5eb6f7f9]::ty::context::TyCtxt, rustc_span[22cad54eabbc67cf]::def_id::LocalDefId)>>::call_once
  23:        0x10fed5b48 - rustc_query_system[a56a14b00b0e8ff6]::query::plumbing::try_execute_query::<rustc_query_impl[9b9172b7a4c3de5d]::DynamicConfig<rustc_query_system[a56a14b00b0e8ff6]::query::caches::VecCache<rustc_span[22cad54eabbc67cf]::def_id::LocalDefId, rustc_middle[2867706b5eb6f7f9]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[9b9172b7a4c3de5d]::plumbing::QueryCtxt, true>
  24:        0x110093de8 - rustc_query_impl[9b9172b7a4c3de5d]::query_impl::mir_built::get_query_incr::__rust_end_short_backtrace
  25:        0x10f909ae0 - rustc_mir_build[eed3693f0e304215]::check_unsafety::check_unsafety
  26:        0x10ff246b0 - rustc_query_impl[9b9172b7a4c3de5d]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9b9172b7a4c3de5d]::query_impl::check_unsafety::dynamic_query::{closure#2}::{closure#0}, rustc_middle[2867706b5eb6f7f9]::query::erase::Erased<[u8; 0usize]>>
  27:        0x11000e960 - <rustc_query_impl[9b9172b7a4c3de5d]::query_impl::check_unsafety::dynamic_query::{closure#2} as core[cec0bd9d2fc86fa9]::ops::function::FnOnce<(rustc_middle[2867706b5eb6f7f9]::ty::context::TyCtxt, rustc_span[22cad54eabbc67cf]::def_id::LocalDefId)>>::call_once
  28:        0x10fece580 - rustc_query_system[a56a14b00b0e8ff6]::query::plumbing::try_execute_query::<rustc_query_impl[9b9172b7a4c3de5d]::DynamicConfig<rustc_query_system[a56a14b00b0e8ff6]::query::caches::VecCache<rustc_span[22cad54eabbc67cf]::def_id::LocalDefId, rustc_middle[2867706b5eb6f7f9]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[9b9172b7a4c3de5d]::plumbing::QueryCtxt, true>
  29:        0x11009b9f4 - rustc_query_impl[9b9172b7a4c3de5d]::query_impl::check_unsafety::get_query_incr::__rust_end_short_backtrace
  30:        0x10f422344 - std[4ec0ba9e3c6d748b]::panicking::try::<(), core[cec0bd9d2fc86fa9]::panic::unwind_safe::AssertUnwindSafe<rustc_data_structures[961a954d878499e9]::sync::parallel::disabled::par_for_each_in<&[rustc_span[22cad54eabbc67cf]::def_id::LocalDefId], <rustc_middle[2867706b5eb6f7f9]::hir::map::Map>::par_body_owners<rustc_interface[6917c625c882dc9d]::passes::run_required_analyses::{closure#1}::{closure#0}>::{closure#0}>::{closure#0}::{closure#0}::{closure#0}>>
  31:        0x10f3d7c34 - <rustc_data_structures[961a954d878499e9]::sync::parallel::ParallelGuard>::run::<(), rustc_data_structures[961a954d878499e9]::sync::parallel::disabled::par_for_each_in<&[rustc_span[22cad54eabbc67cf]::def_id::LocalDefId], <rustc_middle[2867706b5eb6f7f9]::hir::map::Map>::par_body_owners<rustc_interface[6917c625c882dc9d]::passes::run_required_analyses::{closure#1}::{closure#0}>::{closure#0}>::{closure#0}::{closure#0}::{closure#0}>
  32:        0x10f42048c - <rustc_session[6e72d4e14abb7feb]::session::Session>::time::<(), rustc_interface[6917c625c882dc9d]::passes::run_required_analyses::{closure#1}>
  33:        0x10f3f7284 - rustc_interface[6917c625c882dc9d]::passes::analysis
  34:        0x10ff28c10 - rustc_query_impl[9b9172b7a4c3de5d]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9b9172b7a4c3de5d]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[2867706b5eb6f7f9]::query::erase::Erased<[u8; 1usize]>>
  35:        0x11004ab84 - <rustc_query_impl[9b9172b7a4c3de5d]::query_impl::analysis::dynamic_query::{closure#2} as core[cec0bd9d2fc86fa9]::ops::function::FnOnce<(rustc_middle[2867706b5eb6f7f9]::ty::context::TyCtxt, ())>>::call_once
  36:        0x10fe8f690 - rustc_query_system[a56a14b00b0e8ff6]::query::plumbing::try_execute_query::<rustc_query_impl[9b9172b7a4c3de5d]::DynamicConfig<rustc_query_system[a56a14b00b0e8ff6]::query::caches::SingleCache<rustc_middle[2867706b5eb6f7f9]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[9b9172b7a4c3de5d]::plumbing::QueryCtxt, true>
  37:        0x110090730 - rustc_query_impl[9b9172b7a4c3de5d]::query_impl::analysis::get_query_incr::__rust_end_short_backtrace
  38:        0x10ecac4d8 - <rustc_middle[2867706b5eb6f7f9]::ty::context::GlobalCtxt>::enter::<rustc_driver_impl[1ef2360f78401c14]::run_compiler::{closure#0}::{closure#1}::{closure#3}, core[cec0bd9d2fc86fa9]::result::Result<(), rustc_span[22cad54eabbc67cf]::ErrorGuaranteed>>
  39:        0x10ec975a4 - <rustc_interface[6917c625c882dc9d]::interface::Compiler>::enter::<rustc_driver_impl[1ef2360f78401c14]::run_compiler::{closure#0}::{closure#1}, core[cec0bd9d2fc86fa9]::result::Result<core[cec0bd9d2fc86fa9]::option::Option<rustc_interface[6917c625c882dc9d]::queries::Linker>, rustc_span[22cad54eabbc67cf]::ErrorGuaranteed>>
  40:        0x10ec596b8 - <scoped_tls[1950327f1bf28942]::ScopedKey<rustc_span[22cad54eabbc67cf]::SessionGlobals>>::set::<rustc_interface[6917c625c882dc9d]::util::run_in_thread_with_globals<rustc_interface[6917c625c882dc9d]::interface::run_compiler<core[cec0bd9d2fc86fa9]::result::Result<(), rustc_span[22cad54eabbc67cf]::ErrorGuaranteed>, rustc_driver_impl[1ef2360f78401c14]::run_compiler::{closure#0}>::{closure#1}, core[cec0bd9d2fc86fa9]::result::Result<(), rustc_span[22cad54eabbc67cf]::ErrorGuaranteed>>::{closure#0}::{closure#0}::{closure#0}, core[cec0bd9d2fc86fa9]::result::Result<(), rustc_span[22cad54eabbc67cf]::ErrorGuaranteed>>
  41:        0x10ec96f18 - rustc_span[22cad54eabbc67cf]::create_session_globals_then::<core[cec0bd9d2fc86fa9]::result::Result<(), rustc_span[22cad54eabbc67cf]::ErrorGuaranteed>, rustc_interface[6917c625c882dc9d]::util::run_in_thread_with_globals<rustc_interface[6917c625c882dc9d]::interface::run_compiler<core[cec0bd9d2fc86fa9]::result::Result<(), rustc_span[22cad54eabbc67cf]::ErrorGuaranteed>, rustc_driver_impl[1ef2360f78401c14]::run_compiler::{closure#0}>::{closure#1}, core[cec0bd9d2fc86fa9]::result::Result<(), rustc_span[22cad54eabbc67cf]::ErrorGuaranteed>>::{closure#0}::{closure#0}::{closure#0}>
  42:        0x10ec8dd58 - std[4ec0ba9e3c6d748b]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[6917c625c882dc9d]::util::run_in_thread_with_globals<rustc_interface[6917c625c882dc9d]::interface::run_compiler<core[cec0bd9d2fc86fa9]::result::Result<(), rustc_span[22cad54eabbc67cf]::ErrorGuaranteed>, rustc_driver_impl[1ef2360f78401c14]::run_compiler::{closure#0}>::{closure#1}, core[cec0bd9d2fc86fa9]::result::Result<(), rustc_span[22cad54eabbc67cf]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[cec0bd9d2fc86fa9]::result::Result<(), rustc_span[22cad54eabbc67cf]::ErrorGuaranteed>>
  43:        0x10ec6459c - <<std[4ec0ba9e3c6d748b]::thread::Builder>::spawn_unchecked_<rustc_interface[6917c625c882dc9d]::util::run_in_thread_with_globals<rustc_interface[6917c625c882dc9d]::interface::run_compiler<core[cec0bd9d2fc86fa9]::result::Result<(), rustc_span[22cad54eabbc67cf]::ErrorGuaranteed>, rustc_driver_impl[1ef2360f78401c14]::run_compiler::{closure#0}>::{closure#1}, core[cec0bd9d2fc86fa9]::result::Result<(), rustc_span[22cad54eabbc67cf]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[cec0bd9d2fc86fa9]::result::Result<(), rustc_span[22cad54eabbc67cf]::ErrorGuaranteed>>::{closure#2} as core[cec0bd9d2fc86fa9]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  44:        0x105614588 - std::sys::pal::unix::thread::Thread::new::thread_start::hb184f2abd415aef7
  45:        0x187025f94 - __pthread_joiner_wake

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.80.1 (3f5fd8dd4 2024-08-06) running on aarch64-apple-darwin

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked -C incremental=[REDACTED]

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [mir_built] building MIR for `primitive::<impl at crates/ir/src/primitive.rs:561:10: 561:19>::eq`
#1 [check_unsafety] unsafety-checking `primitive::<impl at crates/ir/src/primitive.rs:561:10: 561:19>::eq`
end of query stack
For more information about this error, try `rustc --explain E0517`.
@Robbepop Robbepop added the C-bug Category: This is a bug. label Aug 30, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 30, 2024
@matthiaskrgr
Copy link
Member

duplicate of #120873

@saethlin saethlin added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Aug 30, 2024
@saethlin
Copy link
Member

Ergo, closing

@saethlin saethlin closed this as not planned Won't fix, can't repro, duplicate, stale Aug 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants