Skip to content

(generic_const_exprs) Crash when indexing into a generic slice with computed length in const fns #145138

@5GameMaker

Description

@5GameMaker

Code

#![feature(generic_const_exprs)]

trait One: Sized {
    const ONE: Self;
}

const fn noop<T: One>(a: &mut T, b: &mut T) {
    _ = (a, b);
}

struct Test<T: One, const LEN: usize>([T; LEN * LEN])
where
    [u8; LEN * LEN]:;
impl<T: One, const LEN: usize> Test<T, LEN>
where
    [u8; LEN * LEN]:,
{
    const fn test() -> Self {
        let mut a = Self([T::ONE; LEN * LEN]);
        let mut i = 0;
        while i < LEN {
            let mut one = T::ONE;
            noop(&mut one, &mut a.0[i * i + 1]);
            i += 1;
        }
        a
    }
}

Meta

rustc --version --verbose:

rustc 1.91.0-nightly (2fd855fbf 2025-08-07)
binary: rustc
commit-hash: 2fd855fbfc8239285aa2d596f76a8cc75e17ce02
commit-date: 2025-08-07
host: x86_64-unknown-linux-gnu
release: 1.91.0-nightly
LLVM version: 21.1.0

Error output

error: internal compiler error: compiler/rustc_const_eval/src/check_consts/qualifs.rs:359:13: expected ConstKind::Param or ConstKind::Value here, found UnevaluatedConst { def: DefId(0:134 ~ libcommons[74c2]::matrix::Test::0::{constant#0}), args: [T/#0, LEN/#1] }
Backtrace

thread 'rustc' (571492) panicked at compiler/rustc_const_eval/src/check_consts/qualifs.rs:359:13:
Box<dyn Any>
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: <rustc_errors::diagnostic::BugAbort as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
   2: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0}
   3: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}
   4: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_opt<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
   5: rustc_middle::util::bug::bug_fmt
   6: rustc_const_eval::check_consts::qualifs::in_operand::<rustc_const_eval::check_consts::qualifs::NeedsDrop, <rustc_const_eval::check_consts::resolver::TransferFunction<rustc_const_eval::check_consts::qualifs::NeedsDrop> as rustc_middle::mir::visit::Visitor>::visit_assign::{closure#0}>.cold
   7: <rustc_const_eval::check_consts::resolver::FlowSensitiveAnalysis<rustc_const_eval::check_consts::qualifs::NeedsDrop> as rustc_mir_dataflow::framework::Analysis>::apply_primary_statement_effect
   8: <rustc_const_eval::check_consts::check::Qualifs>::needs_drop
   9: <rustc_const_eval::check_consts::check::Checker>::check_drop_terminator
  10: <rustc_const_eval::check_consts::check::Checker>::check_body
  11: rustc_mir_transform::mir_const_qualif
      [... omitted 6 frames ...]
  12: <rustc_middle::ty::context::TyCtxt>::par_hir_body_owners::<rustc_interface::passes::run_required_analyses::{closure#1}::{closure#0}>::{closure#0}
  13: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  14: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  15: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

rustc-ice-2025-08-08T23_03_08-571490.txt

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.F-generic_const_exprs`#![feature(generic_const_exprs)]`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.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions