-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Labels
-Zvalidate-mirUnstable option: MIR validationUnstable option: MIR validationC-bugCategory: This is a bug.Category: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
auto-reduced (treereduce-rust):
//@compile-flags: -Zvalidate-mir
enum Single {
Both,
Front,
Back,
}
fn main() {
let _val: Single = unsafe { std::mem::transmute::<(), Single>(()) };
}
original:
#[allow(dead_code)]
enum Single {
Both,
Front,
Back
}
fn main() {
let _val: Single = unsafe { std::mem::transmute::<(), Single>(()) };
}
Version information
rustc 1.91.0-nightly (8df154bff 2025-08-23)
binary: rustc
commit-hash: 8df154bffddcb6bbb543ad69aff971795c5adbc2
commit-date: 2025-08-23
host: x86_64-unknown-linux-gnu
release: 1.91.0-nightly
LLVM version: 21.1.0
Possibly related line of code:
rust/compiler/rustc_mir_transform/src/check_enums.rs
Lines 255 to 267 in 8df154b
match size.bytes() { | |
1 => tcx.types.u8, | |
2 => tcx.types.u16, | |
4 => tcx.types.u32, | |
8 => tcx.types.u64, | |
16 => tcx.types.u128, | |
invalid => bug!("Found discriminant with invalid size, has {} bytes", invalid), | |
} | |
}; | |
let (cast_kind, discr_ty_bits) = if discr.size.bytes() < op_size.bytes() { | |
// The discriminant is less wide than the operand, cast the operand into | |
// [MaybeUninit; N] and then index into it. |
Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zvalidate-mir
Program output
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> /tmp/icemaker_global_tempdir.04D9S6j216F0/rustc_testrunner_tmpdir_reporting.N3eUhcnKj0fr/mvce.rs:8:33
|
8 | let _val: Single = unsafe { std::mem::transmute::<(), Single>(()) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: source type: `()` (0 bits)
= note: target type: `Single` (8 bits)
error: internal compiler error: compiler/rustc_mir_transform/src/check_enums.rs:261:24: Found discriminant with invalid size, has 0 bytes
thread 'rustc' (1218568) panicked at compiler/rustc_mir_transform/src/check_enums.rs:261:24:
Box<dyn Any>
stack backtrace:
0: 0x7fc647a65de3 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h8ee9afd01992c0ca
1: 0x7fc648201a98 - core::fmt::write::hfc0f7d2ec3afcf13
2: 0x7fc647a1a463 - std::io::Write::write_fmt::h1808bd8f2dd858a5
3: 0x7fc647a2b4a2 - std::sys::backtrace::BacktraceLock::print::h9d7baa74bc3f6b8a
4: 0x7fc647a31329 - std::panicking::default_hook::{{closure}}::he40de9e29b072647
5: 0x7fc647a30e53 - std::panicking::default_hook::h8e4b76f299931446
6: 0x7fc646a89b55 - std[213c558d849d7d91]::panicking::update_hook::<alloc[8c4e956626d831dd]::boxed::Box<rustc_driver_impl[11d3a6ec691753b1]::install_ice_hook::{closure#1}>>::{closure#0}
7: 0x7fc647a317de - std::panicking::panic_with_hook::h549e3fb761993e77
8: 0x7fc646ac6a81 - std[213c558d849d7d91]::panicking::begin_panic::<rustc_errors[cc6c12e856929c31]::ExplicitBug>::{closure#0}
9: 0x7fc646aba316 - std[213c558d849d7d91]::sys::backtrace::__rust_end_short_backtrace::<std[213c558d849d7d91]::panicking::begin_panic<rustc_errors[cc6c12e856929c31]::ExplicitBug>::{closure#0}, !>
10: 0x7fc646ab7e29 - std[213c558d849d7d91]::panicking::begin_panic::<rustc_errors[cc6c12e856929c31]::ExplicitBug>
11: 0x7fc646ad21b1 - <rustc_errors[cc6c12e856929c31]::diagnostic::BugAbort as rustc_errors[cc6c12e856929c31]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
12: 0x7fc64707c7da - rustc_middle[659b03de131b3a39]::util::bug::opt_span_bug_fmt::<rustc_span[779f303ab57b8d65]::span_encoding::Span>::{closure#0}
13: 0x7fc64707c83a - rustc_middle[659b03de131b3a39]::ty::context::tls::with_opt::<rustc_middle[659b03de131b3a39]::util::bug::opt_span_bug_fmt<rustc_span[779f303ab57b8d65]::span_encoding::Span>::{closure#0}, !>::{closure#0}
14: 0x7fc64706b45b - rustc_middle[659b03de131b3a39]::ty::context::tls::with_context_opt::<rustc_middle[659b03de131b3a39]::ty::context::tls::with_opt<rustc_middle[659b03de131b3a39]::util::bug::opt_span_bug_fmt<rustc_span[779f303ab57b8d65]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
15: 0x7fc6440e1340 - rustc_middle[659b03de131b3a39]::util::bug::bug_fmt
16: 0x7fc6495a7739 - rustc_mir_transform[d3b79acc3196c9f4]::check_enums::insert_discr_cast_to_u128
17: 0x7fc648f99d61 - <rustc_mir_transform[d3b79acc3196c9f4]::check_enums::CheckEnums as rustc_mir_transform[d3b79acc3196c9f4]::pass_manager::MirPass>::run_pass
18: 0x7fc648209436 - rustc_mir_transform[d3b79acc3196c9f4]::run_optimization_passes
19: 0x7fc648de75e6 - rustc_mir_transform[d3b79acc3196c9f4]::optimized_mir
20: 0x7fc648de7239 - rustc_query_impl[d1909fe17814b3af]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d1909fe17814b3af]::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}, rustc_middle[659b03de131b3a39]::query::erase::Erased<[u8; 8usize]>>
21: 0x7fc648227ab9 - rustc_query_system[672d1867d8a3a753]::query::plumbing::try_execute_query::<rustc_query_impl[d1909fe17814b3af]::DynamicConfig<rustc_query_system[672d1867d8a3a753]::query::caches::DefIdCache<rustc_middle[659b03de131b3a39]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[d1909fe17814b3af]::plumbing::QueryCtxt, false>
22: 0x7fc648226f9b - rustc_query_impl[d1909fe17814b3af]::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace
23: 0x7fc6452ce84b - <rustc_middle[659b03de131b3a39]::ty::context::TyCtxt>::instance_mir
24: 0x7fc6484067b1 - rustc_interface[ac200cc1ac94b679]::passes::analysis
25: 0x7fc64840538b - rustc_query_impl[d1909fe17814b3af]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d1909fe17814b3af]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[659b03de131b3a39]::query::erase::Erased<[u8; 0usize]>>
26: 0x7fc6492bda20 - rustc_query_system[672d1867d8a3a753]::query::plumbing::try_execute_query::<rustc_query_impl[d1909fe17814b3af]::DynamicConfig<rustc_query_system[672d1867d8a3a753]::query::caches::SingleCache<rustc_middle[659b03de131b3a39]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[d1909fe17814b3af]::plumbing::QueryCtxt, false>
27: 0x7fc6492bd676 - rustc_query_impl[d1909fe17814b3af]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
28: 0x7fc64949b94b - rustc_interface[ac200cc1ac94b679]::passes::create_and_enter_global_ctxt::<core[7df29245c2304c2]::option::Option<rustc_interface[ac200cc1ac94b679]::queries::Linker>, rustc_driver_impl[11d3a6ec691753b1]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
29: 0x7fc6493e9adf - rustc_interface[ac200cc1ac94b679]::interface::run_compiler::<(), rustc_driver_impl[11d3a6ec691753b1]::run_compiler::{closure#0}>::{closure#1}
30: 0x7fc649365e38 - std[213c558d849d7d91]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[ac200cc1ac94b679]::util::run_in_thread_with_globals<rustc_interface[ac200cc1ac94b679]::util::run_in_thread_pool_with_globals<rustc_interface[ac200cc1ac94b679]::interface::run_compiler<(), rustc_driver_impl[11d3a6ec691753b1]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
31: 0x7fc649365b1c - <<std[213c558d849d7d91]::thread::Builder>::spawn_unchecked_<rustc_interface[ac200cc1ac94b679]::util::run_in_thread_with_globals<rustc_interface[ac200cc1ac94b679]::util::run_in_thread_pool_with_globals<rustc_interface[ac200cc1ac94b679]::interface::run_compiler<(), rustc_driver_impl[11d3a6ec691753b1]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[7df29245c2304c2]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
32: 0x7fc64936bacd - std::sys::pal::unix::thread::Thread::new::thread_start::h543657e01047c55a
33: 0x7fc642a969cb - <unknown>
34: 0x7fc642b1aa4c - <unknown>
35: 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: please make sure that you have updated to the latest nightly
note: rustc 1.91.0-nightly (8df154bff 2025-08-23) running on x86_64-unknown-linux-gnu
note: compiler flags: -Z validate-mir -Z dump-mir-dir=dir
query stack during panic:
#0 [optimized_mir] optimizing MIR for `main`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0512`.
Metadata
Metadata
Assignees
Labels
-Zvalidate-mirUnstable option: MIR validationUnstable option: MIR validationC-bugCategory: This is a bug.Category: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.