Skip to content

[ICE]: stealing value which is locked #152662

Description

@zetanumbers

Initially reported in #151509 (review)

This is A-parallel-compiler issue as it occurs only with -Zthreads=8

Code

Source code of rustc, commit 75b9d89.

Meta

rustc --version --verbose:

rustc 1.95.0-nightly (a33907a7a 2026-02-14)
binary: rustc
commit-hash: a33907a7a5381473eec8bcfa0c56e05a856a911c
commit-date: 2026-02-14
host: aarch64-apple-darwin
release: 1.95.0-nightly
LLVM version: 22.1.0

Error output

thread 'rustc' panicked at /rustc-dev/a33907a7a5381473eec8bcfa0c56e05a856a911c/compiler/rustc_mir_transform/src/lib.rs:549:25:
stealing value which is locked: ()
Backtrace

stack backtrace:
   0:        0x1139b8224 - <std[fb7650b96fc3e2b2]::backtrace::Backtrace>::create
   1:        0x1118a4b90 - std[fb7650b96fc3e2b2]::panicking::update_hook::<alloc[2c7721ec027e506c]::boxed::Box<rustc_driver_impl[fcca23ff68962ade]::install_ice_hook::{closure#1}>>::{closure#0}
   2:        0x1139c9788 - std[fb7650b96fc3e2b2]::panicking::panic_with_hook
   3:        0x1139ad720 - std[fb7650b96fc3e2b2]::panicking::panic_handler::{closure#0}
   4:        0x1139a40e8 - std[fb7650b96fc3e2b2]::sys::backtrace::__rust_end_short_backtrace::<std[fb7650b96fc3e2b2]::panicking::panic_handler::{closure#0}, !>
   5:        0x1139aecf0 - __rustc[b0419f81c5efee33]::rust_begin_unwind
   6:        0x1169e462c - core[5b2322a8d5f57ee]::panicking::panic_fmt
   7:        0x1169e4394 - core[5b2322a8d5f57ee]::result::unwrap_failed
   8:        0x1128e6e38 - rustc_mir_transform[93ce7f6be37bbafc]::mir_drops_elaborated_and_const_checked
   9:        0x112e1a58c - rustc_query_impl[abe004534d1d69cf]::execution::try_execute_query::<rustc_data_structures[2654685372cda76c]::vec_cache::VecCache<rustc_span[f00e5f7574cd0ad2]::def_id::LocalDefId, rustc_middle[5ae9d75c2f1bdf17]::query::erase::ErasedData<[u8; 8usize]>, rustc_middle[5ae9d75c2f1bdf17]::dep_graph::graph::DepNodeIndex>, {rustc_query_impl[abe004534d1d69cf]::QueryFlags { is_anon: false, is_depth_limit: false, is_feedable: false }}, true>
  10:        0x112fe07ac - rustc_query_impl[abe004534d1d69cf]::query_impl::mir_drops_elaborated_and_const_checked::get_query_incr::__rust_end_short_backtrace
  11:        0x1121975ac - <rustc_middle[5ae9d75c2f1bdf17]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_interface[4e0e0615d47554a1]::passes::run_required_analyses::{closure#1}::{closure#0}>::{closure#0}
  12:        0x11212ee10 - <rustc_data_structures[2654685372cda76c]::sync::parallel::ParallelGuard>::run::<(), rustc_data_structures[2654685372cda76c]::sync::parallel::par_slice::par_rec<&rustc_span[f00e5f7574cd0ad2]::def_id::LocalDefId, rustc_data_structures[2654685372cda76c]::sync::parallel::par_for_each_in<&rustc_span[f00e5f7574cd0ad2]::def_id::LocalDefId, &[rustc_span[f00e5f7574cd0ad2]::def_id::LocalDefId], <rustc_middle[5ae9d75c2f1bdf17]::ty::context::TyCtxt>::par_hir_body_owners<rustc_interface[4e0e0615d47554a1]::passes::run_required_analyses::{closure#1}::{closure#0}>::{closure#0}>::{closure#0}::{closure#0}>::{closure#0}>
  13:        0x11219d990 - rustc_thread_pool[e1f27a471ba69f13]::join::join_context::<rustc_thread_pool[e1f27a471ba69f13]::join::join::call<(), rustc_data_structures[2654685372cda76c]::sync::parallel::par_slice::par_rec<&rustc_span[f00e5f7574cd0ad2]::def_id::LocalDefId, rustc_data_structures[2654685372cda76c]::sync::parallel::par_for_each_in<&rustc_span[f00e5f7574cd0ad2]::def_id::LocalDefId, &[rustc_span[f00e5f7574cd0ad2]::def_id::LocalDefId], <rustc_middle[5ae9d75c2f1bdf17]::ty::context::TyCtxt>::par_hir_body_owners<rustc_interface[4e0e0615d47554a1]::passes::run_required_analyses::{closure#1}::{closure#0}>::{closure#0}>::{closure#0}::{closure#0}>::{closure#1}>::{closure#0}, rustc_thread_pool[e1f27a471ba69f13]::join::join::call<(), rustc_data_structures[2654685372cda76c]::sync::parallel::par_slice::par_rec<&rustc_span[f00e5f7574cd0ad2]::def_id::LocalDefId, rustc_data_structures[2654685372cda76c]::sync::parallel::par_for_each_in<&rustc_span[f00e5f7574cd0ad2]::def_id::LocalDefId, &[rustc_span[f00e5f7574cd0ad2]::def_id::LocalDefId], <rustc_middle[5ae9d75c2f1bdf17]::ty::context::TyCtxt>::par_hir_body_owners<rustc_interface[4e0e0615d47554a1]::passes::run_required_analyses::{closure#1}::{closure#0}>::{closure#0}>::{closure#0}::{closure#0}>::{closure#2}>::{closure#0}, (), ()>::{closure#0}
  14:        0x11216cb30 - rustc_data_structures[2654685372cda76c]::sync::parallel::par_slice::par_rec::<&rustc_span[f00e5f7574cd0ad2]::def_id::LocalDefId, rustc_data_structures[2654685372cda76c]::sync::parallel::par_for_each_in<&rustc_span[f00e5f7574cd0ad2]::def_id::LocalDefId, &[rustc_span[f00e5f7574cd0ad2]::def_id::LocalDefId], <rustc_middle[5ae9d75c2f1bdf17]::ty::context::TyCtxt>::par_hir_body_owners<rustc_interface[4e0e0615d47554a1]::passes::run_required_analyses::{closure#1}::{closure#0}>::{closure#0}>::{closure#0}::{closure#0}>
  15:        0x11222b49c - <rustc_thread_pool[e1f27a471ba69f13]::job::StackJob<rustc_thread_pool[e1f27a471ba69f13]::latch::SpinLatch, rustc_thread_pool[e1f27a471ba69f13]::join::join_context<rustc_thread_pool[e1f27a471ba69f13]::join::join::call<(), rustc_data_structures[2654685372cda76c]::sync::parallel::par_slice::par_rec<&rustc_span[f00e5f7574cd0ad2]::def_id::LocalDefId, rustc_data_structures[2654685372cda76c]::sync::parallel::par_for_each_in<&rustc_span[f00e5f7574cd0ad2]::def_id::LocalDefId, &[rustc_span[f00e5f7574cd0ad2]::def_id::LocalDefId], <rustc_middle[5ae9d75c2f1bdf17]::ty::context::TyCtxt>::par_hir_body_owners<rustc_interface[4e0e0615d47554a1]::passes::run_required_analyses::{closure#1}::{closure#0}>::{closure#0}>::{closure#0}::{closure#0}>::{closure#1}>::{closure#0}, rustc_thread_pool[e1f27a471ba69f13]::join::join::call<(), rustc_data_structures[2654685372cda76c]::sync::parallel::par_slice::par_rec<&rustc_span[f00e5f7574cd0ad2]::def_id::LocalDefId, rustc_data_structures[2654685372cda76c]::sync::parallel::par_for_each_in<&rustc_span[f00e5f7574cd0ad2]::def_id::LocalDefId, &[rustc_span[f00e5f7574cd0ad2]::def_id::LocalDefId], <rustc_middle[5ae9d75c2f1bdf17]::ty::context::TyCtxt>::par_hir_body_owners<rustc_interface[4e0e0615d47554a1]::passes::run_required_analyses::{closure#1}::{closure#0}>::{closure#0}>::{closure#0}::{closure#0}>::{closure#2}>::{closure#0}, (), ()>::{closure#0}::{closure#0}, ()> as rustc_thread_pool[e1f27a471ba69f13]::job::Job>::execute
  16:        0x116b615f0 - <rustc_thread_pool[e1f27a471ba69f13]::registry::WorkerThread>::wait_or_steal_until_cold
  17:        0x1134d943c - <rustc_thread_pool[e1f27a471ba69f13]::registry::ThreadBuilder>::run
  18:        0x11189c1cc - std[fb7650b96fc3e2b2]::sys::backtrace::__rust_begin_short_backtrace::<<rustc_thread_pool[e1f27a471ba69f13]::ThreadPoolBuilder>::build_scoped<rustc_interface[4e0e0615d47554a1]::util::run_in_thread_pool_with_globals<rustc_interface[4e0e0615d47554a1]::interface::run_compiler<(), rustc_driver_impl[fcca23ff68962ade]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#5}::{closure#0}::{closure#0}, rustc_interface[4e0e0615d47554a1]::util::run_in_thread_pool_with_globals<rustc_interface[4e0e0615d47554a1]::interface::run_compiler<(), rustc_driver_impl[fcca23ff68962ade]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#5}::{closure#0}::{closure#1}, ()>::{closure#0}::{closure#0}::{closure#0}, ()>
  19:        0x1118ac434 - <std[fb7650b96fc3e2b2]::thread::lifecycle::spawn_unchecked<<rustc_thread_pool[e1f27a471ba69f13]::ThreadPoolBuilder>::build_scoped<rustc_interface[4e0e0615d47554a1]::util::run_in_thread_pool_with_globals<rustc_interface[4e0e0615d47554a1]::interface::run_compiler<(), rustc_driver_impl[fcca23ff68962ade]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#5}::{closure#0}::{closure#0}, rustc_interface[4e0e0615d47554a1]::util::run_in_thread_pool_with_globals<rustc_interface[4e0e0615d47554a1]::interface::run_compiler<(), rustc_driver_impl[fcca23ff68962ade]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#5}::{closure#0}::{closure#1}, ()>::{closure#0}::{closure#0}::{closure#0}, ()>::{closure#1} as core[5b2322a8d5f57ee]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  20:        0x1139d44b8 - <std[fb7650b96fc3e2b2]::sys::thread::unix::Thread>::new::thread_start
  21:        0x198f69c08 - __pthread_cond_wait


rustc version: 1.95.0-nightly (a33907a7a 2026-02-14)
platform: aarch64-apple-darwin

query stack during panic:
#0 [mir_drops_elaborated_and_const_checked] elaborating drops for `<impl at compiler/rustc_errors/src/lib.rs:1170:1: 1170:19>::emit_diagnostic::{closure#3}::{closure#0}`
#1 [analysis] running analysis passes on crate `rustc_errors`
end of query stack

Reproduction steps

This method took me 10 minutes of incrementally rebuilding the rustc to reproduce on apple M1 pro. Run ./x b rustc in a clean git worktree of rust-lang/rust with build.rustc = "/path/to/nightly/rustc-2026-02-15, rust.incremental = true, rust.deny-warnings = false and rust.rustflags = "-Zthreads=8" set in bootstrap.toml. Then do a change from below diff to rustc source code:

diff --git a/compiler/rustc_data_structures/src/lib.rs b/compiler/rustc_data_structures/src/lib.rs
index 4467a281118..e79312458b3 100644
--- a/compiler/rustc_data_structures/src/lib.rs
+++ b/compiler/rustc_data_structures/src/lib.rs
@@ -162,3 +162,8 @@ fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
         }
     };
 }
+
+#[derive(Clone, Copy)]
+pub struct BadStruct {
+    int: u64,
+}

Finally run ./x b rustc again. It may sometimes not reproduce, in such case restore changes and ./x b rustc, then apply change and ./x b rustc until ICE is reproduced.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-parallel-compilerArea: parallel compilerC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-needs-reproStatus: This issue has no reproduction and needs a reproduction to make progress.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