Skip to content

ICE compiler/rustc_query_system/src/dep_graph/query.rs index out of bounds #142152

Description

@matthiaskrgr

Code

compile with -Zquery-dep-graph -Zthreads=4 -Cincremental=/tmp/ -Zincremental-verify-ich=yes --edition=2024 --crate-type lib

This will sometimes ICE, around 1/10 times for me

pub trait Associate {
    type Associated;
}

pub struct Wrap<'a> {
    pub field: &'a i32,
}

pub trait Create<T> {
    fn create() -> Self;
}

pub fn oh_no<'a, T>()
where
    Wrap<'a>: Associate,
    <Wrap<'a> as Associate>::Associated: Create<T>,
{
    <Wrap<'a> as Associate>::Associated::create();
}

pub fn main() {}

Meta

rustc --version --verbose:

rustc 1.89.0-nightly (c57119b9a 2025-06-07)
binary: rustc
commit-hash: c57119b9a1c86968188bb9703a7859c17f8bc71c
commit-date: 2025-06-07
host: x86_64-unknown-linux-gnu
release: 1.89.0-nightly
LLVM version: 20.1.5

Error output

thread 'rustc' panicked at compiler/rustc_query_system/src/dep_graph/query.rs:31:49:
index out of bounds: the len is 122 but the index is 523
stack backtrace:
   0:     0x724e3390ef53 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::haf62842818d14700
   1:     0x724e34002cb7 - core::fmt::write::hcbc7f51ba008f803
   2:     0x724e33904c63 - std::io::Write::write_fmt::hae893cdefa15425e
   3:     0x724e3390edb2 - std::sys::backtrace::BacktraceLock::print::ha054f106f07b7628
   4:     0x724e3391299a - std::panicking::default_hook::{{closure}}::h7f764cabab3db86e
   5:     0x724e3391251f - std::panicking::default_hook::h014d489547013991
   6:     0x724e32a14343 - std[c475a882e07ae63]::panicking::update_hook::<alloc[81a84acdd818619f]::boxed::Box<rustc_driver_impl[521b9eae2fc4e103]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x724e33913203 - std::panicking::rust_panic_with_hook::h09797f209f5eff9b
   8:     0x724e33912efa - std::panicking::begin_panic_handler::{{closure}}::h9e770369565c83a5
   9:     0x724e3390f429 - std::sys::backtrace::__rust_end_short_backtrace::h74b6f9a68b0bb61f
  10:     0x724e33912bcd - __rustc[68e581a04d2baff0]::rust_begin_unwind
  11:     0x724e30076700 - core::panicking::panic_fmt::hd3bdf9865accc11f
  12:     0x724e3209d3a3 - core::panicking::panic_bounds_check::h9cebfb3d6917ee12
  13:     0x724e334494c4 - <rustc_query_system[5096c0469bfd6733]::dep_graph::query::DepGraphQuery>::push
  14:     0x724e33303e56 - rustc_data_structures[48b81750ed2870a8]::outline::<<rustc_query_system[5096c0469bfd6733]::dep_graph::serialized::EncoderState<rustc_middle[ecaecb1147c2deb2]::dep_graph::DepsType>>::record<<rustc_query_system[5096c0469bfd6733]::dep_graph::serialized::EncoderState<rustc_middle[ecaecb1147c2deb2]::dep_graph::DepsType>>::encode_promoted_node::{closure#0}>::{closure#0}, ()>
  15:     0x724e34462911 - <rustc_query_system[5096c0469bfd6733]::dep_graph::graph::DepGraphData<rustc_middle[ecaecb1147c2deb2]::dep_graph::DepsType>>::try_mark_previous_green::<rustc_query_impl[70af034b9e771977]::plumbing::QueryCtxt>
  16:     0x724e34da5136 - <rustc_query_system[5096c0469bfd6733]::dep_graph::graph::DepGraphData<rustc_middle[ecaecb1147c2deb2]::dep_graph::DepsType>>::try_mark_green::<rustc_query_impl[70af034b9e771977]::plumbing::QueryCtxt>
  17:     0x724e34d9bd1d - rustc_query_system[5096c0469bfd6733]::query::plumbing::ensure_must_run::<rustc_query_impl[70af034b9e771977]::DynamicConfig<rustc_query_system[5096c0469bfd6733]::query::caches::SingleCache<rustc_middle[ecaecb1147c2deb2]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[70af034b9e771977]::plumbing::QueryCtxt>
  18:     0x724e3546ef1e - rustc_query_impl[70af034b9e771977]::query_impl::proc_macro_decls_static::get_query_incr::__rust_end_short_backtrace
  19:     0x724e32e0733d - rayon_core[7170aa47ed7daee8]::scope::scope::<rustc_data_structures[48b81750ed2870a8]::sync::parallel::scope<rustc_interface[bbfabb48a2aa6e29]::passes::run_required_analyses::{closure#0}::{closure#1}::{closure#0}, ()>::{closure#0}, rustc_data_structures[48b81750ed2870a8]::marker::FromDyn<()>>::{closure#0}
  20:     0x724e342b9a48 - rustc_interface[bbfabb48a2aa6e29]::passes::analysis
  21:     0x724e342b8c75 - rustc_query_impl[70af034b9e771977]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[70af034b9e771977]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ecaecb1147c2deb2]::query::erase::Erased<[u8; 0usize]>>
  22:     0x724e35532e82 - rustc_query_system[5096c0469bfd6733]::query::plumbing::try_execute_query::<rustc_query_impl[70af034b9e771977]::DynamicConfig<rustc_query_system[5096c0469bfd6733]::query::caches::SingleCache<rustc_middle[ecaecb1147c2deb2]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[70af034b9e771977]::plumbing::QueryCtxt, true>
  23:     0x724e355327a3 - rustc_query_impl[70af034b9e771977]::query_impl::analysis::get_query_incr::__rust_end_short_backtrace
  24:     0x724e354f603f - rustc_interface[bbfabb48a2aa6e29]::passes::create_and_enter_global_ctxt::<core[c83a95fd3175649b]::option::Option<rustc_interface[bbfabb48a2aa6e29]::queries::Linker>, rustc_driver_impl[521b9eae2fc4e103]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  25:     0x724e35345b70 - rustc_interface[bbfabb48a2aa6e29]::interface::run_compiler::<(), rustc_driver_impl[521b9eae2fc4e103]::run_compiler::{closure#0}>::{closure#1}
  26:     0x724e32a28d94 - <rayon_core[7170aa47ed7daee8]::job::StackJob<rayon_core[7170aa47ed7daee8]::latch::LatchRef<rayon_core[7170aa47ed7daee8]::latch::LockLatch>, <rayon_core[7170aa47ed7daee8]::registry::Registry>::in_worker_cold<<rayon_core[7170aa47ed7daee8]::thread_pool::ThreadPool>::install<rustc_interface[bbfabb48a2aa6e29]::util::run_in_thread_pool_with_globals<rustc_interface[bbfabb48a2aa6e29]::interface::run_compiler<(), rustc_driver_impl[521b9eae2fc4e103]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#5}::{closure#0}::{closure#1}::{closure#0}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()> as rayon_core[7170aa47ed7daee8]::job::Job>::execute
  27:     0x724e3252f01e - <rayon_core[7170aa47ed7daee8]::registry::WorkerThread>::wait_until_cold
  28:     0x724e3252c9a1 - <rayon_core[7170aa47ed7daee8]::registry::ThreadBuilder>::run
  29:     0x724e32a0a8bd - std[c475a882e07ae63]::sys::backtrace::__rust_begin_short_backtrace::<<rayon_core[7170aa47ed7daee8]::ThreadPoolBuilder>::build_scoped<rustc_interface[bbfabb48a2aa6e29]::util::run_in_thread_pool_with_globals<rustc_interface[bbfabb48a2aa6e29]::interface::run_compiler<(), rustc_driver_impl[521b9eae2fc4e103]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#5}::{closure#0}::{closure#0}, rustc_interface[bbfabb48a2aa6e29]::util::run_in_thread_pool_with_globals<rustc_interface[bbfabb48a2aa6e29]::interface::run_compiler<(), rustc_driver_impl[521b9eae2fc4e103]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#5}::{closure#0}::{closure#1}, ()>::{closure#0}::{closure#0}::{closure#0}, ()>
  30:     0x724e32a19862 - <<std[c475a882e07ae63]::thread::Builder>::spawn_unchecked_<<rayon_core[7170aa47ed7daee8]::ThreadPoolBuilder>::build_scoped<rustc_interface[bbfabb48a2aa6e29]::util::run_in_thread_pool_with_globals<rustc_interface[bbfabb48a2aa6e29]::interface::run_compiler<(), rustc_driver_impl[521b9eae2fc4e103]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#5}::{closure#0}::{closure#0}, rustc_interface[bbfabb48a2aa6e29]::util::run_in_thread_pool_with_globals<rustc_interface[bbfabb48a2aa6e29]::interface::run_compiler<(), rustc_driver_impl[521b9eae2fc4e103]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#5}::{closure#0}::{closure#1}, ()>::{closure#0}::{closure#0}::{closure#0}, ()>::{closure#1} as core[c83a95fd3175649b]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  31:     0x724e352a62bd - std::sys::pal::unix::thread::Thread::new::thread_start::h44a4c2b992fd9536
  32:     0x724e2eca57eb - <unknown>
  33:     0x724e2ed2918c - <unknown>
  34:                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: please attach the file at `/tmp/glacier2/fixed/rustc-ice-2025-06-07T09_54_25-2892720.txt` to your bug report

note: compiler flags: -Z query-dep-graph -Z threads=4 -C incremental=[REDACTED] -Z incremental-verify-ich=yes --crate-type lib

query stack during panic:
#0 [analysis] running analysis passes on this crate
end of query stack
Backtrace

<backtrace>

Activity

  1. added
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    C-bugCategory: This is a bug.
    on Jun 7, 2025
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Jun 7, 2025
  3. removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Jun 7, 2025
  4. cyrgani commented on Jun 8, 2025

    @cyrgani
    Contributor

    simpler, but still only occuring spuriously:

    trait Associate {
        type Associated;
    }
    
    // not necessary, but increases the probability of causing the ice
    struct Wrap<'a> {
        field: &'a i32,
    }
    
    fn main() {}

    commands:

    rm -rf incr/
    rustc src/main.rs -Zquery-dep-graph -Zthreads=2 -Cincremental=incr/  
    rustc src/main.rs -Zquery-dep-graph -Zthreads=2 -Cincremental=incr/
    
  5. added
    S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issue
    on Jun 8, 2025
  6. zetanumbers commented on Sep 10, 2025

    @zetanumbers
    Contributor

    If you remove -Cincremental option rustc will give you another ICE on unwrap at:

    let dep_node_debug = &self.data.as_ref().unwrap().dep_node_debug;

    This is due to -Zdump-dep-graph option not being enabled (idk how this should be fixed tho). If you add that flag instead, this issue will no longer reproduce. It means bug could be related to program's (i.e. compiler's) memory ordering or other logic when panic happens, if such scenario was not thought through.

    As such I would like to see if it can be reproduced with both -Zdump-dep-graph and -Zquery-dep-graph set. I guess this is the testcase to include into #143953.

  7. ywxt commented on Nov 10, 2025

    @ywxt
    Contributor

    Even compiling a hello world, there is another panic while printing query stack. But this needs a bunch to reproduce. (over 1000 times here)

    thread 'rustc' (1211095) panicked at compiler/rustc_query_system/src/dep_graph/query.rs:31:49:
    index out of bounds: the len is 1044 but the index is 1045
    stack backtrace:
       0:     0x7a7e43075243 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h275e909084b1a684
       1:     0x7a7e43801afc - core::fmt::write::hf760d67cf9b2da55
       2:     0x7a7e43029e33 - std::io::Write::write_fmt::h46e65fbc1f072ebd
       3:     0x7a7e4303b442 - std::sys::backtrace::BacktraceLock::print::heeffa864a4cc6853
       4:     0x7a7e430415d9 - std::panicking::default_hook::{{closure}}::ha1187c52840bb77a
       5:     0x7a7e43041103 - std::panicking::default_hook::h3597edaf39d86724
       6:     0x7a7e42031341 - std[c0ce55412202fb59]::panicking::update_hook::<alloc[4123f12742ba7419]::boxed::Box<rustc_driver_impl[5cfea032dd4e7986]::install_ice_hook::{closure#1}>>::{closure#0}
       7:     0x7a7e430419fb - std::panicking::panic_with_hook::h0e9397ed55f9ce63
       8:     0x7a7e430417ba - std::panicking::panic_handler::{{closure}}::h047060a714057723
       9:     0x7a7e4303b579 - std::sys::backtrace::__rust_end_short_backtrace::h8057a932be1ba9ec
      10:     0x7a7e4301c16d - __rustc[459dbf790511d39a]::rust_begin_unwind
      11:     0x7a7e400ce4c0 - core::panicking::panic_fmt::h84c50daa2269b357
      12:     0x7a7e3fc11a6d - core::panicking::panic_bounds_check::hc2dcd07fa2cc71d7
      13:     0x7a7e42b46cf3 - <rustc_query_system[b561d73868fa1e34]::dep_graph::query::DepGraphQuery>::push
      14:     0x7a7e429f4116 - rustc_data_structures[469c5225820d4653]::outline::<<rustc_query_system[b561d73868fa1e34]::dep_graph::serialized::EncoderState<rustc_middle[a62e1c9468295d17]::dep_graph::DepsType>>::record<<rustc_query_system[b561d73868fa1e34]::dep_graph::serialized::EncoderState<rustc_middle[a62e1c9468295d17]::dep_graph::DepsType>>::encode_promoted_node::{closure#0}>::{closure#0}, ()>
      15:     0x7a7e4382e70c - <rustc_query_system[b561d73868fa1e34]::dep_graph::graph::DepGraphData<rustc_middle[a62e1c9468295d17]::dep_graph::DepsType>>::try_mark_previous_green::<rustc_query_impl[322b07c669eb3743]::plumbing::QueryCtxt>
      16:     0x7a7e4382dee2 - <rustc_query_system[b561d73868fa1e34]::dep_graph::graph::DepGraphData<rustc_middle[a62e1c9468295d17]::dep_graph::DepsType>>::try_mark_previous_green::<rustc_query_impl[322b07c669eb3743]::plumbing::QueryCtxt>
      17:     0x7a7e4439eaf3 - rustc_query_system[b561d73868fa1e34]::query::plumbing::try_execute_query::<rustc_query_impl[322b07c669eb3743]::DynamicConfig<rustc_query_system[b561d73868fa1e34]::query::caches::DefaultCache<(rustc_middle[a62e1c9468295d17]::ty::instance::Instance, rustc_middle[a62e1c9468295d17]::mir::mono::CollectionMode), rustc_middle[a62e1c9468295d17]::query::erase::Erased<[u8; 32usize]>>, false, false, false>, rustc_query_impl[322b07c669eb3743]::plumbing::QueryCtxt, true>
      18:     0x7a7e4439d35b - rustc_query_impl[322b07c669eb3743]::query_impl::items_of_instance::get_query_incr::__rust_end_short_backtrace
      19:     0x7a7e443989b1 - rustc_monomorphize[abedb7dce80f5aa9]::collector::collect_items_rec::{closure#0}
      20:     0x7a7e44399b3e - rustc_monomorphize[abedb7dce80f5aa9]::collector::collect_items_rec
      21:     0x7a7e43b31eef - rustc_monomorphize[abedb7dce80f5aa9]::collector::collect_crate_mono_items::{closure#1}::{closure#0}
      22:     0x7a7e42881065 - rustc_data_structures[469c5225820d4653]::sync::parallel::par_slice::par_rec::<rustc_middle[a62e1c9468295d17]::mir::mono::MonoItem, rustc_data_structures[469c5225820d4653]::sync::parallel::par_for_each_in<rustc_middle[a62e1c9468295d17]::mir::mono::MonoItem, alloc[4123f12742ba7419]::vec::Vec<rustc_middle[a62e1c9468295d17]::mir::mono::MonoItem>, rustc_monomorphize[abedb7dce80f5aa9]::collector::collect_crate_mono_items::{closure#1}::{closure#0}>::{closure#0}::{closure#0}>
      23:     0x7a7e4288a1f7 - <rustc_thread_pool[4ae909ee64d2dd56]::job::StackJob<rustc_thread_pool[4ae909ee64d2dd56]::latch::SpinLatch, rustc_thread_pool[4ae909ee64d2dd56]::join::join_context<rustc_thread_pool[4ae909ee64d2dd56]::join::join::call<(), rustc_data_structures[469c5225820d4653]::sync::parallel::par_slice::par_rec<rustc_middle[a62e1c9468295d17]::mir::mono::MonoItem, rustc_data_structures[469c5225820d4653]::sync::parallel::par_for_each_in<rustc_middle[a62e1c9468295d17]::mir::mono::MonoItem, alloc[4123f12742ba7419]::vec::Vec<rustc_middle[a62e1c9468295d17]::mir::mono::MonoItem>, rustc_monomorphize[abedb7dce80f5aa9]::collector::collect_crate_mono_items::{closure#1}::{closure#0}>::{closure#0}::{closure#0}>::{closure#1}>::{closure#0}, rustc_thread_pool[4ae909ee64d2dd56]::join::join::call<(), rustc_data_structures[469c5225820d4653]::sync::parallel::par_slice::par_rec<rustc_middle[a62e1c9468295d17]::mir::mono::MonoItem, rustc_data_structures[469c5225820d4653]::sync::parallel::par_for_each_in<rustc_middle[a62e1c9468295d17]::mir::mono::MonoItem, alloc[4123f12742ba7419]::vec::Vec<rustc_middle[a62e1c9468295d17]::mir::mono::MonoItem>, rustc_monomorphize[abedb7dce80f5aa9]::collector::collect_crate_mono_items::{closure#1}::{closure#0}>::{closure#0}::{closure#0}>::{closure#2}>::{closure#0}, (), ()>::{closure#0}::{closure#0}, ()> as rustc_thread_pool[4ae909ee64d2dd56]::job::Job>::execute
      24:     0x7a7e42d4c22f - <rustc_thread_pool[4ae909ee64d2dd56]::registry::WorkerThread>::wait_or_steal_until_cold
      25:     0x7a7e42d4acd1 - <rustc_thread_pool[4ae909ee64d2dd56]::registry::ThreadBuilder>::run
      26:     0x7a7e4202936d - std[c0ce55412202fb59]::sys::backtrace::__rust_begin_short_backtrace::<<rustc_thread_pool[4ae909ee64d2dd56]::ThreadPoolBuilder>::build_scoped<rustc_interface[575b60d3cd400129]::util::run_in_thread_pool_with_globals<rustc_interface[575b60d3cd400129]::interface::run_compiler<(), rustc_driver_impl[5cfea032dd4e7986]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#5}::{closure#0}::{closure#0}, rustc_interface[575b60d3cd400129]::util::run_in_thread_pool_with_globals<rustc_interface[575b60d3cd400129]::interface::run_compiler<(), rustc_driver_impl[5cfea032dd4e7986]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#5}::{closure#0}::{closure#1}, ()>::{closure#0}::{closure#0}::{closure#0}, ()>
      27:     0x7a7e42034332 - <<std[c0ce55412202fb59]::thread::Builder>::spawn_unchecked_<<rustc_thread_pool[4ae909ee64d2dd56]::ThreadPoolBuilder>::build_scoped<rustc_interface[575b60d3cd400129]::util::run_in_thread_pool_with_globals<rustc_interface[575b60d3cd400129]::interface::run_compiler<(), rustc_driver_impl[5cfea032dd4e7986]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#5}::{closure#0}::{closure#0}, rustc_interface[575b60d3cd400129]::util::run_in_thread_pool_with_globals<rustc_interface[575b60d3cd400129]::interface::run_compiler<(), rustc_driver_impl[5cfea032dd4e7986]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#5}::{closure#0}::{closure#1}, ()>::{closure#0}::{closure#0}::{closure#0}, ()>::{closure#1} as core[968b6d0815caf745]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
      28:     0x7a7e449146af - std::sys::thread::unix::Thread::new::thread_start::h897ae72f919a9cf9
      29:     0x7a7e3e09caa4 - start_thread
                                   at ./nptl/pthread_create.c:447:8
      30:     0x7a7e3e129c6c - clone3
                                   at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78:0
      31:                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: please attach the file at `/root/rust/reproducible/rustc-ice-2025-11-10T03_49_04-1211092.txt` to your bug report
    
    note: compiler flags: -Z query-dep-graph -Z threads=8 -C incremental=[REDACTED]
    
    query stack during panic:
    panicked at /rustc-dev/6647be93640686a2a443a49f15c3390b68c8b5dd/compiler/rustc_query_system/src/dep_graph/serialized.rs:875:43:
    
    thread panicked while processing panic. aborting.
    
  8. zetanumbers commented on Dec 11, 2025

    @zetanumbers
    Contributor

    Due to my suspicions of this issue being related to #141540 I have reproduced this bug a bunch of times on f520900 and found that mir_drops_elaborated_and_const_checked regularly shows up in the backtrace.

  9. zetanumbers commented on Dec 13, 2025

    @zetanumbers
    Contributor

    Bisects to 3ef8e64 (aka #139758). Not unexpected really.

  10. petrochenkov commented on Feb 13, 2026

    @petrochenkov
    Contributor

    Minimal fix is in #152590.

  11. added 2 commits that reference this issue on Feb 14, 2026
  12. added a commit that references this issue on Feb 14, 2026
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-incr-compArea: Incremental compilationA-parallel-compilerArea: parallel compilerC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-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