rust-lang / rust-lang/rust

[ICE]: `intern_const_alloc_for_constprop` called on allocation with nested provenance

Open
#160,750 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-mir-opt A-mir-opt-GVN C-bug I-ICE needs-triage requires-nightly T-compiler
Dominant language
Rust
Stars
119k
Forks
16.2k
PR merge metrics
PR metrics pending

Description

snippet:

//@compile-flags: -Zmir-opt-level=5
fn main() {
    let x: Option<Box<[u8]>> = unsafe { std::mem::transmute((43u8, &42u8)) };
}

Version information

rustc 1.99.0-nightly (49c80b5a0 2026-08-08)
binary: rustc
commit-hash: 49c80b5a0db8abd63315c04ff34f58629e388281
commit-date: 2026-08-08
host: x86_64-unknown-linux-gnu
release: 1.99.0-nightly
LLVM version: 23.1.0

Possibly related line of code:
https://github.com/rust-lang/rust/blob/49c80b5a0db8abd63315c04ff34f58629e388281/compiler/rustc_const_eval/src/interpret/intern.rs#L368-L380

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zmir-opt-level=5

Program output

warning: unused variable: `x`
 --> /tmp/icemaker_global_tempdir.qHk9ASUjuYuq/rustc_testrunner_tmpdir_reporting.dtbuEOlDpqio/mvce.rs:2:9
  |
2 |     let x: Option<Box<[u8]>> = unsafe { std::mem::transmute((43u8, &42u8)) };
  |         ^ help: if this is intentional, prefix it with an underscore: `_x`
  |
  = note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default


thread 'rustc' (2623455) panicked at /rustc-dev/49c80b5a0db8abd63315c04ff34f58629e388281/compiler/rustc_const_eval/src/interpret/intern.rs:374:9:
`intern_const_alloc_for_constprop` called on allocation with nested provenance
stack backtrace:
   0:     0x7f0584d06146 - <<std[999cce9698cb2e30]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[611a668b6db07504]::fmt::Display>::fmt
   1:     0x7f058541190f - core[611a668b6db07504]::fmt::write
   2:     0x7f0584d1b06c - <std[999cce9698cb2e30]::sys::stdio::unix::Stderr as core[611a668b6db07504]::io::write::Write>::write_fmt
   3:     0x7f0584cd91ba - std[999cce9698cb2e30]::panicking::default_hook::{closure#0}
   4:     0x7f0584cf9ed3 - std[999cce9698cb2e30]::panicking::default_hook
   5:     0x7f0583c3feaa - std[999cce9698cb2e30]::panicking::update_hook::<alloc[9c4b63ad13971f33]::boxed::Box<rustc_driver_impl[1d9b9be3672627fe]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7f0584cfa372 - std[999cce9698cb2e30]::panicking::panic_with_hook
   7:     0x7f0584cd92a4 - std[999cce9698cb2e30]::panicking::panic_handler::{closure#0}
   8:     0x7f0584cd1669 - std[999cce9698cb2e30]::sys::backtrace::__rust_end_short_backtrace::<std[999cce9698cb2e30]::panicking::panic_handler::{closure#0}, !>
   9:     0x7f0584cdac4d - __rustc[a528db767ab46065]::rust_begin_unwind
  10:     0x7f05819c926c - core[611a668b6db07504]::panicking::panic_fmt
  11:     0x7f05860c7926 - <rustc_mir_transform[d22efaeeee5c0fb3]::gvn::VnState as rustc_middle[842db40099f2c7a0]::mir::visit::MutVisitor>::visit_assign
  12:     0x7f05860b9753 - <rustc_mir_transform[d22efaeeee5c0fb3]::gvn::GVN as rustc_mir_transform[d22efaeeee5c0fb3]::pass_manager::MirPass>::run_pass
  13:     0x7f0585407eef - rustc_mir_transform[d22efaeeee5c0fb3]::pass_manager::run_passes_inner
  14:     0x7f0585af5769 - rustc_mir_transform[d22efaeeee5c0fb3]::optimized_mir
  15:     0x7f0585af494b - rustc_query_impl[e0a7c844c3569b46]::query_impl::optimized_mir::invoke_provider_fn::__rust_begin_short_backtrace
  16:     0x7f0585452bfd - rustc_query_impl[e0a7c844c3569b46]::execution::try_execute_query::<rustc_middle[842db40099f2c7a0]::query::caches::DefIdCache<rustc_middle[842db40099f2c7a0]::query::erase::ErasedData<[u8; 8usize]>>, false>
  17:     0x7f058545230e - rustc_query_impl[e0a7c844c3569b46]::query_impl::optimized_mir::execute_query_non_incr::__rust_end_short_backtrace
  18:     0x7f05859b5d53 - <rustc_middle[842db40099f2c7a0]::ty::context::TyCtxt>::instance_mir
  19:     0x7f05859bac0b - rustc_monomorphize[57d9639682b12d5d]::collector::items_of_instance
  20:     0x7f05859bab91 - rustc_query_impl[e0a7c844c3569b46]::query_impl::items_of_instance::invoke_provider_fn::__rust_begin_short_backtrace
  21:     0x7f05860a06a0 - rustc_query_impl[e0a7c844c3569b46]::execution::try_execute_query::<rustc_middle[842db40099f2c7a0]::query::caches::DefaultCache<(rustc_middle[842db40099f2c7a0]::ty::instance::Instance, rustc_middle[842db40099f2c7a0]::mono::CollectionMode), rustc_middle[842db40099f2c7a0]::query::erase::ErasedData<[u8; 32usize]>>, false>
  22:     0x7f05860a0303 - rustc_query_impl[e0a7c844c3569b46]::query_impl::items_of_instance::execute_query_non_incr::__rust_end_short_backtrace
  23:     0x7f058647b9e9 - rustc_monomorphize[57d9639682b12d5d]::collector::collect_items_rec
  24:     0x7f0586482076 - rustc_monomorphize[57d9639682b12d5d]::collector::collect_crate_mono_items::{closure#1}::{closure#0}
  25:     0x7f058648297c - rustc_monomorphize[57d9639682b12d5d]::partitioning::collect_and_partition_mono_items
  26:     0x7f05865ac330 - rustc_query_impl[e0a7c844c3569b46]::query_impl::collect_and_partition_mono_items::invoke_provider_fn::__rust_begin_short_backtrace
  27:     0x7f05865abc6d - rustc_query_impl[e0a7c844c3569b46]::execution::try_execute_query::<rustc_middle[842db40099f2c7a0]::query::caches::SingleCache<rustc_middle[842db40099f2c7a0]::query::erase::ErasedData<[u8; 24usize]>>, false>
  28:     0x7f05865ab953 - rustc_query_impl[e0a7c844c3569b46]::query_impl::collect_and_partition_mono_items::execute_query_non_incr::__rust_end_short_backtrace
  29:     0x7f058649cdc0 - rustc_codegen_ssa[9d2ef248dbc53dd3]::base::codegen_crate::<rustc_codegen_llvm[37ce2c06ea606dca]::LlvmCodegenBackend, rustc_codegen_llvm[37ce2c06ea606dca]::ModuleLlvm>
  30:     0x7f058649ad4c - <rustc_codegen_llvm[37ce2c06ea606dca]::LlvmCodegenBackend as rustc_codegen_ssa[9d2ef248dbc53dd3]::traits::backend::CodegenBackend>::codegen_crate
  31:     0x7f0586628aa5 - <rustc_interface[1a36412a1dda276]::queries::Linker>::codegen_and_build_linker
  32:     0x7f0586620495 - rustc_interface[1a36412a1dda276]::interface::run_compiler::<(), rustc_driver_impl[1d9b9be3672627fe]::run_compiler::{closure#0}>::{closure#2}
  33:     0x7f0586655ca4 - std[999cce9698cb2e30]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[1a36412a1dda276]::util::run_in_thread_with_globals<rustc_interface[1a36412a1dda276]::util::run_in_thread_pool_with_globals<rustc_interface[1a36412a1dda276]::interface::run_compiler<(), rustc_driver_impl[1d9b9be3672627fe]::run_compiler::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  34:     0x7f0586655a6d - <std[999cce9698cb2e30]::thread::lifecycle::spawn_unchecked<rustc_interface[1a36412a1dda276]::util::run_in_thread_with_globals<rustc_interface[1a36412a1dda276]::util::run_in_thread_pool_with_globals<rustc_interface[1a36412a1dda276]::interface::run_compiler<(), rustc_driver_impl[1d9b9be3672627fe]::run_compiler::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[611a668b6db07504]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  35:     0x7f058665323a - <std[999cce9698cb2e30]::sys::thread::unix::Thread>::new::thread_start
  36:     0x7f057fa97739 - <unknown>
  37:     0x7f057fb1bedc - <unknown>
  38:                0x0 - <unknown>

error: the compiler unexpectedly panicked. This is a bug

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.99.0-nightly (49c80b5a0 2026-08-08) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z mir-opt-level=5 -Z dump-mir-dir=dir

query stack during panic:
#0 [optimized_mir] optimizing MIR for `main`
#1 [items_of_instance] collecting items used by `main`
#2 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
warning: 1 warning emitted


Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the ICE with the a.rs snippet using rustc -Zmir-opt-level=5, then inspect compiler/rustc_const_eval/src/interpret/intern.rs around lines 368-380 and the intern_const_alloc_for_constprop entry point. Done means the snippet no longer triggers the reported panic during optimized MIR processing, with coverage for this case.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.