rust-lang / rust-lang/rust

[ICE]: broken MIR after phase change to runtime-optimized: invalid source scope

Open
#155,441 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-ICE needs-triage S-needs-repro T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
   Compiling uuid v1.23.1
error: internal compiler error: broken MIR in Item(DefId(0:646 ~ uuid[e135]::{impl#0}::to_bytes_le)) (after phase change to runtime-optimized):
                                invalid source scope scope[131072]
   --> /home/ariel/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/uuid-1.23.1/src/lib.rs:849:5
    |
849 | /     pub const fn to_bytes_le(&self) -> Bytes {
850 | |         [
851 | |             self.0[3], self.0[2], self.0[1], self.0[0], self.0[5], self.0[4], self.0[7], self.0[6],
852 | |             self.0[8], self.0[9], self.0[10], self.0[11], self.0[12], self.0[13], self.0[14],
...   |
855 | |     }
    | |_____^


thread 'rustc' (539740) panicked at /rustc-dev/59807616e1fa2540724bfbac14d7976d7e4a3860/compiler/rustc_mir_transform/src/validate.rs:532:28:
Box<dyn Any>
stack backtrace:
   0:     0x76e248d9314b - <<std[e28293b1aa0f68bd]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[c1f1a4ba060b9bfa]::fmt::Display>::fmt
   1:     0x76e24941f408 - core[c1f1a4ba060b9bfa]::fmt::write
   2:     0x76e24a9683b6 - <std[e28293b1aa0f68bd]::sys::stdio::unix::Stderr as std[e28293b1aa0f68bd]::io::Write>::write_fmt
   3:     0x76e248d69238 - std[e28293b1aa0f68bd]::panicking::default_hook::{closure#0}
   4:     0x76e248d865b3 - std[e28293b1aa0f68bd]::panicking::default_hook
   5:     0x76e247d5cc30 - std[e28293b1aa0f68bd]::panicking::update_hook::<alloc[fdfd2bd8633a6659]::boxed::Box<rustc_driver_impl[e4ca9dd5dd6cf2a8]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x76e248d86892 - std[e28293b1aa0f68bd]::panicking::panic_with_hook
   7:     0x76e247d8d8b1 - std[e28293b1aa0f68bd]::panicking::begin_panic::<rustc_errors[795cd5cf46ddce51]::ExplicitBug>::{closure#0}
   8:     0x76e247d865c6 - std[e28293b1aa0f68bd]::sys::backtrace::__rust_end_short_backtrace::<std[e28293b1aa0f68bd]::panicking::begin_panic<rustc_errors[795cd5cf46ddce51]::ExplicitBug>::{closure#0}, !>
   9:     0x76e247d8643b - std[e28293b1aa0f68bd]::panicking::begin_panic::<rustc_errors[795cd5cf46ddce51]::ExplicitBug>
  10:     0x76e247d985a1 - <rustc_errors[795cd5cf46ddce51]::diagnostic::BugAbort as rustc_errors[795cd5cf46ddce51]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  11:     0x76e2484d478c - <rustc_errors[795cd5cf46ddce51]::DiagCtxtHandle>::span_bug::<rustc_span[e3c9a1967c4921fd]::span_encoding::Span, alloc[fdfd2bd8633a6659]::string::String>
  12:     0x76e249feb4cb - <rustc_mir_transform[2be6bdc629d1da0e]::validate::Validator as rustc_mir_transform[2be6bdc629d1da0e]::pass_manager::MirPass>::run_pass
  13:     0x76e249409afa - rustc_mir_transform[2be6bdc629d1da0e]::run_optimization_passes
  14:     0x76e249b8edcf - rustc_mir_transform[2be6bdc629d1da0e]::optimized_mir
  15:     0x76e249b8ea1d - rustc_query_impl[b21371cac9e22a84]::query_impl::optimized_mir::invoke_provider_fn::__rust_begin_short_backtrace
  16:     0x76e249413368 - rustc_query_impl[b21371cac9e22a84]::execution::try_execute_query::<rustc_middle[9956b31dc9b62104]::query::caches::DefIdCache<rustc_middle[9956b31dc9b62104]::query::erase::ErasedData<[u8; 8usize]>>, false>
  17:     0x76e249412a4e - rustc_query_impl[b21371cac9e22a84]::query_impl::optimized_mir::execute_query_non_incr::__rust_end_short_backtrace
  18:     0x76e249cba98b - rustc_mir_transform[2be6bdc629d1da0e]::cross_crate_inline::cross_crate_inlinable
  19:     0x76e249976378 - rustc_query_impl[b21371cac9e22a84]::query_impl::cross_crate_inlinable::invoke_provider_fn::__rust_begin_short_backtrace
  20:     0x76e24997548e - rustc_query_impl[b21371cac9e22a84]::execution::try_execute_query::<rustc_middle[9956b31dc9b62104]::query::caches::DefIdCache<rustc_middle[9956b31dc9b62104]::query::erase::ErasedData<[u8; 1usize]>>, false>
  21:     0x76e249975058 - rustc_query_impl[b21371cac9e22a84]::query_impl::cross_crate_inlinable::execute_query_non_incr::__rust_end_short_backtrace
  22:     0x76e249a2374f - rustc_passes[6bf4acf08ac4e6d9]::reachable::reachable_set
  23:     0x76e24a642a9c - rustc_query_impl[b21371cac9e22a84]::query_impl::reachable_set::invoke_provider_fn::__rust_begin_short_backtrace
  24:     0x76e24a641f6e - rustc_query_impl[b21371cac9e22a84]::execution::try_execute_query::<rustc_middle[9956b31dc9b62104]::query::caches::SingleCache<rustc_middle[9956b31dc9b62104]::query::erase::ErasedData<[u8; 8usize]>>, false>
  25:     0x76e24a6429b9 - rustc_query_impl[b21371cac9e22a84]::query_impl::reachable_set::execute_query_non_incr::__rust_end_short_backtrace
  26:     0x76e249e6c9ed - <rustc_metadata[420ade231d97cbc6]::rmeta::encoder::EncodeContext>::encode_crate_root
  27:     0x76e24a8b0452 - <rustc_metadata[420ade231d97cbc6]::rmeta::encoder::encode_metadata::{closure#3} as core[c1f1a4ba060b9bfa]::ops::function::FnOnce<(rustc_middle[9956b31dc9b62104]::ty::context::TyCtxt, &std[e28293b1aa0f68bd]::path::Path)>>::call_once
  28:     0x76e24a8adb54 - rustc_metadata[420ade231d97cbc6]::rmeta::encoder::encode_metadata
  29:     0x76e24a3b87d9 - rustc_metadata[420ade231d97cbc6]::fs::encode_and_write_metadata
  30:     0x76e24a65b1eb - <rustc_interface[c8170c4b7b680ee8]::queries::Linker>::codegen_and_build_linker
  31:     0x76e24a6563e6 - rustc_interface[c8170c4b7b680ee8]::interface::run_compiler::<(), rustc_driver_impl[e4ca9dd5dd6cf2a8]::run_compiler::{closure#0}>::{closure#1}
  32:     0x76e24a62663e - std[e28293b1aa0f68bd]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[c8170c4b7b680ee8]::util::run_in_thread_with_globals<rustc_interface[c8170c4b7b680ee8]::util::run_in_thread_pool_with_globals<rustc_interface[c8170c4b7b680ee8]::interface::run_compiler<(), rustc_driver_impl[e4ca9dd5dd6cf2a8]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  33:     0x76e24a626ca0 - <std[e28293b1aa0f68bd]::thread::lifecycle::spawn_unchecked<rustc_interface[c8170c4b7b680ee8]::util::run_in_thread_with_globals<rustc_interface[c8170c4b7b680ee8]::util::run_in_thread_pool_with_globals<rustc_interface[c8170c4b7b680ee8]::interface::run_compiler<(), rustc_driver_impl[e4ca9dd5dd6cf2a8]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[c1f1a4ba060b9bfa]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  34:     0x76e24a627b2c - <std[e28293b1aa0f68bd]::sys::thread::unix::Thread>::new::thread_start
   Compiling rmp-serde v1.3.1
  35:     0x76e243e9caa4 - start_thread
                               at ./nptl/pthread_create.c:447:8
  36:     0x76e243f29c6c - clone3
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78:0
  37:                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.95.0 (59807616e 2026-04-14) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -C opt-level=3 -C panic=abort -C linker-plugin-lto -C codegen-units=1 -C strip=symbols

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

query stack during panic:
#0 [optimized_mir] optimizing MIR for `<impl at /home/ariel/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/uuid-1.23.1/src/lib.rs:467:1: 467:10>::to_bytes_le`
#1 [cross_crate_inlinable] whether the item should be made inlinable across crates
... and 1 other queries... use `env RUST_BACKTRACE=1` to see the full query stack
error: could not compile `uuid` (lib)

Caused by:
  process didn't exit successfully: `/home/ariel/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/rustc --crate-name uuid --edition=2021 /home/ariel/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/uuid-1.23.1/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=156 --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C panic=abort -C linker-plugin-lto -C codegen-units=1 --allow=unexpected_cfgs --check-cfg 'cfg(uuid_unstable)' --cfg 'feature="default"' --cfg 'feature="rng"' --cfg 'feature="serde"' --cfg 'feature="std"' --cfg 'feature="v7"' --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values("arbitrary", "atomic", "borsh", "bytemuck", "default", "fast-rng", "js", "macro-diagnostics", "md5", "rng", "rng-getrandom", "rng-rand", "serde", "sha1", "slog", "std", "uuid-rng-internal-lib", "v1", "v3", "v4", "v5", "v6", "v7", "v8", "zerocopy"))' -C metadata=4677166967f1f8e5 -C extra-filename=-f6b35daa25e5ea2d --out-dir /home/ariel/remshell/target/x86_64-unknown-linux-musl/release/deps --target x86_64-unknown-linux-musl -C strip=symbols -L dependency=/home/ariel/remshell/target/x86_64-unknown-linux-musl/release/deps -L dependency=/home/ariel/remshell/target/release/deps --extern getrandom=/home/ariel/remshell/target/x86_64-unknown-linux-musl/release/deps/libge

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 while compiling uuid-1.23.1 with the shown optimization and linker-plugin-LTO flags. Start in compiler/rustc_mir_transform/src/validate.rs at the reported validator panic and compare it with the MIR generated for uuid/src/lib.rs:849-855. Done means the compiler no longer reports broken MIR or panics for this build.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.