Skip to content

ICE: const parameter N/#1 (N/#1/1) out of range when instantiating args=[N/#1] #15069

Closed
@nhusung

Description

@nhusung

Summary

When running cargo +nightly clippy on the following (stripped-down) code, I get an ICE.

use std::cell::Cell;

pub struct Foo<T, const N: usize>(pub Entry<N>, pub T);

pub struct Entry<const N: usize>(pub Cell<[u32; N]>);

impl<const N: usize> Entry<N> {
    #[allow(clippy::declare_interior_mutable_const)]
    const INIT: Self = Self(Cell::new([42; N]));
}

impl<T, const N: usize> Foo<T, N> {
    pub fn make_foo(v: T) -> Self {
        Foo(Entry::INIT, v)
    }
}

The error does not occur on Rust stable (1.87) or beta (1.88).

Version

rustc 1.89.0-nightly (586ad391f 2025-06-15)
binary: rustc
commit-hash: 586ad391f5ee4519acc7cae340e34673bae762b1
commit-date: 2025-06-15
host: x86_64-unknown-linux-gnu
release: 1.89.0-nightly
LLVM version: 20.1.5

Error output

Backtrace

thread 'rustc' panicked at /rustc-dev/586ad391f5ee4519acc7cae340e34673bae762b1/compiler/rustc_type_ir/src/binder.rs:795:9:
const parameter `N/#1` (N/#1/1) out of range when instantiating args=[N/#1]
stack backtrace:
 0: __rustc::rust_begin_unwind
 1: core::panicking::panic_fmt
 2: <rustc_type_ir::binder::ArgFolder<rustc_middle::ty::context::TyCtxt>>::const_param_out_of_range
 3: <rustc_type_ir::binder::ArgFolder<rustc_middle::ty::context::TyCtxt>>::const_for_param
 4: <&rustc_middle::ty::list::RawList<(), rustc_middle::ty::generic_args::GenericArg> as rustc_type_ir::fold::TypeFoldable<rustc_middle::ty::context::TyCtxt>>::fold_with::<rustc_type_ir::binder::ArgFolder<rustc_middle::ty::context::TyCtxt>>
 5: <rustc_middle::ty::Ty as rustc_type_ir::fold::TypeSuperFoldable<rustc_middle::ty::context::TyCtxt>>::super_fold_with::<rustc_type_ir::binder::ArgFolder<rustc_middle::ty::context::TyCtxt>>
 6: <clippy_lints::non_copy_const::NonCopyConst>::is_non_freeze_init_borrowed
 7: <clippy_lints::non_copy_const::NonCopyConst as rustc_lint::passes::LateLintPass>::check_expr
 8: <rustc_lint::late::LateContextAndPass<rustc_lint::late::RuntimeCombinedLateLintPass> as rustc_hir::intravisit::Visitor>::visit_expr::{closure#0}::{closure#0}
 9: <rustc_lint::late::LateContextAndPass<rustc_lint::late::RuntimeCombinedLateLintPass> as rustc_hir::intravisit::Visitor>::visit_expr
10: <rustc_lint::late::LateContextAndPass<rustc_lint::late::RuntimeCombinedLateLintPass> as rustc_hir::intravisit::Visitor>::visit_expr::{closure#0}::{closure#0}
11: <rustc_lint::late::LateContextAndPass<rustc_lint::late::RuntimeCombinedLateLintPass> as rustc_hir::intravisit::Visitor>::visit_expr
12: <rustc_lint::late::LateContextAndPass<rustc_lint::late::RuntimeCombinedLateLintPass> as rustc_hir::intravisit::Visitor>::visit_block
13: <rustc_lint::late::LateContextAndPass<rustc_lint::late::RuntimeCombinedLateLintPass> as rustc_hir::intravisit::Visitor>::visit_expr::{closure#0}::{closure#0}
14: <rustc_lint::late::LateContextAndPass<rustc_lint::late::RuntimeCombinedLateLintPass> as rustc_hir::intravisit::Visitor>::visit_expr
15: <rustc_lint::late::LateContextAndPass<rustc_lint::late::RuntimeCombinedLateLintPass> as rustc_hir::intravisit::Visitor>::visit_nested_body
16: <rustc_lint::late::LateContextAndPass<rustc_lint::late::RuntimeCombinedLateLintPass> as rustc_hir::intravisit::Visitor>::visit_fn
17: <rustc_lint::late::LateContextAndPass<rustc_lint::late::RuntimeCombinedLateLintPass> as rustc_hir::intravisit::Visitor>::visit_nested_item
18: rustc_lint::late::check_crate::{closure#0}
19: rustc_lint::late::check_crate
20: rustc_interface::passes::analysis
    [... omitted 1 frame ...]
21: 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}
22: 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.

error: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust-clippy/issues/new?template=ice.yml

note: please make sure that you have updated to the latest nightly

note: please attach the file at `/tmp/example/rustc-ice-2025-06-17T14_09_07-100550.txt` to your bug report

note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

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

query stack during panic:
#0 [analysis] running analysis passes on this crate
end of query stack
note: Clippy version: clippy 0.1.89 (586ad391f5 2025-06-15)

rustc-ice-2025-06-17T14_09_07-100550.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-ICEIssue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions