Skip to content

ICE when using a generic const expression in a where clause #134978

Closed

Description

@jullanggit

Disclaimer

I know the feature generic_const_exprs is incomplete, and don't expect it to fully work. This is just in case this is a new issue and could be helpful.

Code

#![feature(generic_const_exprs)]

pub struct Struct<const N: usize>;

impl<const N: usize> Struct<N> {
    pub const OK: usize = 0;
}

fn main() {
    function::<0>();
}

fn function<const NUM_CARDS: usize>()
where
    [(); Struct::<{ NUM_CARDS + 0 }>::OK]:,
{
}

Meta

rustc --version --verbose:

rustc 1.85.0-nightly (7f75bfa1a 2024-12-30)
binary: rustc
commit-hash: 7f75bfa1ad4e9a9d33a179a90603001515e91991
commit-date: 2024-12-30
host: x86_64-unknown-linux-gnu
release: 1.85.0-nightly
LLVM version: 19.1.6

Error output

thread 'rustc query cycle handler' panicked at compiler/rustc_query_system/src/query/job.rs:504:9:
deadlock detected as we're unable to find a query cycle to break
Backtrace

❯ RUST_BACKTRACE=full cargo run
   Compiling ice v0.1.0 (/home/user/.config/rebos/files/common/home/user/Code/rust/ice)
warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
 --> src/main.rs:1:12
  |
1 | #![feature(generic_const_exprs)]
  |            ^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information
  = note: `#[warn(incomplete_features)]` on by default

thread 'rustc query cycle handler' panicked at compiler/rustc_query_system/src/query/job.rs:504:9:
deadlock detected as we're unable to find a query cycle to break
current query map:
{"reason":"compiler-message","package_id":"path+file:///home/user/.config/rebos/files/common/home/user/Code/rust/ice#0.1.0","manifest_path":"/home/user/.config/rebos/files/common/home/user/Code/rust/ice/Cargo.toml","target":{"kind":["bin"],"crate_types":["bin"],"name":"ice","src_path":"/home/user/.config/rebos/files/common/home/user/Code/rust/ice/src/main.rs","edition":"2024","doc":true,"doctest":false,"test":true},"message":{}}
stack backtrace:
   0:     0x767883ccccea - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hfeb90fd9b5398c4f
   1:     0x767884413466 - core::fmt::write::hd020802d4198e71b
   2:     0x76788531abd1 - std::io::Write::write_fmt::h7e2e8e4cf92a8d65
   3:     0x767883cccb42 - std::sys::backtrace::BacktraceLock::print::h66b4c03e5039d072
   4:     0x767883ccf049 - std::panicking::default_hook::{{closure}}::hcc157a01562efcba
   5:     0x767883ccee92 - std::panicking::default_hook::h21db3d7d04627650
   6:     0x767882e3a688 - std[cb5a7f0ea0430aa5]::panicking::update_hook::<alloc[dd9cf49c51639ce8]::boxed::Box<rustc_driver_impl[a708e1f659847ef0]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x767883ccf803 - std::panicking::rust_panic_with_hook::h6f76ca5eeec77396
   8:     0x767883ccf4fa - std::panicking::begin_panic_handler::{{closure}}::hf108fef1bd19d641
   9:     0x767883ccd199 - std::sys::backtrace::__rust_end_short_backtrace::heff692e62eddffc0
  10:     0x767883ccf1bd - rust_begin_unwind
  11:     0x76788099d390 - core::panicking::panic_fmt::h98a3fbf157fea8f4
  12:     0x7678838790da - rustc_query_system[7637a88347177bdb]::query::job::break_query_cycles
  13:     0x767882e30f3c - std[cb5a7f0ea0430aa5]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[5a45d25d69207022]::util::run_in_thread_pool_with_globals<rustc_interface[5a45d25d69207022]::interface::run_compiler<(), rustc_driver_impl[a708e1f659847ef0]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#2}::{closure#1}, ()>
  14:     0x767882e3f744 - <<std[cb5a7f0ea0430aa5]::thread::Builder>::spawn_unchecked_<rustc_interface[5a45d25d69207022]::util::run_in_thread_pool_with_globals<rustc_interface[5a45d25d69207022]::interface::run_compiler<(), rustc_driver_impl[a708e1f659847ef0]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#2}::{closure#1}, ()>::{closure#1} as core[2b031b7237be44de]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  15:     0x767885259381 - std::sys::pal::unix::thread::Thread::new::thread_start::h0f9dd4118f064405
  16:     0x76787f6a0386 - <unknown>
  17:     0x76787f721b0c - <unknown>
  18:                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 `/home/user/.config/rebos/files/common/home/user/Code/rust/ice/rustc-ice-2024-12-31T17_57_52-210002.txt` to your bug report

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED] -Z threads=12 -Z macro-backtrace -C target-cpu=native -C linker=clang -C link-arg=-fuse-ld=/usr/bin/mold -Z threads=12 -Z macro-backtrace -C target-cpu=native -C linker=clang -C link-arg=-fuse-ld=/usr/bin/mold

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

query stack during panic:
end of query stack
query cycle handler thread panicked, aborting process
warning: `ice` (bin "ice") generated 1 warning
error: could not compile `ice` (bin "ice"); 1 warning emitted

Caused by:
  process didn't exit successfully: `/home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc --crate-name ice --edition=2024 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=111 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values())' -C metadata=d5f9e422892f9ee1 -C extra-filename=-cd55e940cca72f2d --out-dir /home/user/.config/rebos/files/common/home/user/Code/rust/ice/target/debug/deps -C incremental=/home/user/.config/rebos/files/common/home/user/Code/rust/ice/target/debug/incremental -L dependency=/home/user/.config/rebos/files/common/home/user/Code/rust/ice/target/debug/deps -Zthreads=12 -Zmacro-backtrace -Ctarget-cpu=native -Clinker=clang -Clink-arg=-fuse-ld=/usr/bin/mold -Zthreads=12 -Zmacro-backtrace -Ctarget-cpu=native -Clinker=clang -Clink-arg=-fuse-ld=/usr/bin/mold` (signal: 6, SIGABRT: process abort signal)

Activity

  1. added
    C-bugCategory: This is a bug.
    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.
    on Dec 31, 2024
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Dec 31, 2024
  3. added
    I-cycleIssue: A query cycle occurred while none was expected
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    on Jan 8, 2025
  4. kei519 commented on Jan 26, 2025

    @kei519
    Contributor

    I found compiling the same code with -Zthreads=n (n ≠ 1) causes another error:

    error: could not compile `xxx` (bin "xxx"); 1 warning emitted
    
    Caused by:
      process didn't exit successfully: ... (signal: 11, SIGSEGV: invalid memory reference)
    

    I'm not sure whether it is obvious, so I note it here just in case.


    commit-hash: 2f0ad2a

  5. jullanggit commented on Jul 4, 2025

    @jullanggit
    ContributorAuthor

    Update: the compiler now emits an error, instead of crashing, although I still think this code should be accepted.

    error[E0391]: cycle detected when building an abstract representation for `function::{constant#0}`
      --> src/main.rs:15:10
       |
    15 |     [(); Struct::<{ NUM_CARDS + 0 }>::OK]:,
       |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       |
    note: ...which requires building THIR for `function::{constant#0}`...
      --> src/main.rs:15:10
       |
    15 |     [(); Struct::<{ NUM_CARDS + 0 }>::OK]:,
       |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    note: ...which requires type-checking `function::{constant#0}`...
      --> src/main.rs:15:10
       |
    15 |     [(); Struct::<{ NUM_CARDS + 0 }>::OK]:,
       |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       = note: ...which again requires building an abstract representation for `function::{constant#0}`, completing the cycle
    note: cycle used when checking that `function` is well-formed
      --> src/main.rs:13:1
       |
    13 | / fn function<const NUM_CARDS: usize>()
    14 | | where
    15 | |     [(); Struct::<{ NUM_CARDS + 0 }>::OK]:,
       | |___________________________________________^
       = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
  6. added 2 commits that reference this issue on Mar 26, 2026
  7. added
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    on Jun 11, 2026
  8. petrochenkov commented on Jun 11, 2026

    @petrochenkov
    Contributor

    This case was added to the parallel test suite (tests\ui\parallel-rustc\generic-const-exprs-deadlock-issue-134978.rs) and wasn't observed to fail there.
    So I'll close this issue, please reopen if it ever happens again.

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.F-generic_const_exprs`#![feature(generic_const_exprs)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️I-cycleIssue: A query cycle occurred while none was expectedP-lowLow priorityT-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