Skip to content

[ICE]: cannot find N/#0 in param-env: ParamEnv #154281

@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

struct S<const N: usize>([(); N]);

impl<const N: usize> S<N> {
    fn foo() -> [(); const {
           let _: Self = loop {};
           1
       }] {
        todo!()
    }
}

original:

struct S<const N: usize>([(); N]);

impl<const N: usize> S<N> {
    fn foo() -> [(); const {
           let _: Self = loop {};
           1
       }] {
        todo!()
    }
}

fn main() {}

Version information

rustc 1.96.0-nightly (f66622c7e 2026-03-23)
binary: rustc
commit-hash: f66622c7eca7fc48ccc4dac848ff911b09a4d566
commit-date: 2026-03-23
host: x86_64-unknown-linux-gnu
release: 1.96.0-nightly
LLVM version: 22.1.0

Possibly related line of code:

// `Option<Ty<'tcx>>` instead of `Ty<'tcx>`; however, this is generally
// considered to be a bandaid solution, since it hides more important
// underlying issues with how we construct generics and predicates of
// items. It's advised to fix the underlying issue rather than trying
// to modify this function.
let ty = candidates.next().unwrap_or_else(|| {
bug!("cannot find `{self:?}` in param-env: {env:#?}");
});
assert!(
candidates.next().is_none(),
"did not expect duplicate `ConstParamHasTy` for `{self:?}` in param-env: {env:#?}"
);
ty

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

error[E0601]: `main` function not found in crate `mvce`
  --> /tmp/icemaker_global_tempdir.V83zeUDD57C1/rustc_testrunner_tmpdir_reporting.T7QySKNN0ONt/mvce.rs:10:2
   |
10 | }
   |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.V83zeUDD57C1/rustc_testrunner_tmpdir_reporting.T7QySKNN0ONt/mvce.rs`

warning: unreachable expression
 --> /tmp/icemaker_global_tempdir.V83zeUDD57C1/rustc_testrunner_tmpdir_reporting.T7QySKNN0ONt/mvce.rs:6:12
  |
5 |            let _: Self = loop {};
  |                          ------- any code following this expression is unreachable
6 |            1
  |            ^ unreachable expression
  |
  = note: `#[warn(unreachable_code)]` (part of `#[warn(unused)]`) on by default

error: internal compiler error: /rustc-dev/f66622c7eca7fc48ccc4dac848ff911b09a4d566/compiler/rustc_middle/src/ty/sty.rs:352:13: cannot find `N/#0` in param-env: ParamEnv {
                                    caller_bounds: [],
                                }


thread 'rustc' (2782697) panicked at /rustc-dev/f66622c7eca7fc48ccc4dac848ff911b09a4d566/compiler/rustc_middle/src/ty/sty.rs:352:13:
Box<dyn Any>
stack backtrace:
   0:     0x7f4c665ae7eb - <<std[dbd160d25717361c]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[af451d9ab418ad9]::fmt::Display>::fmt
   1:     0x7f4c66c2f708 - core[af451d9ab418ad9]::fmt::write
   2:     0x7f4c665c57f6 - <std[dbd160d25717361c]::sys::stdio::unix::Stderr as std[dbd160d25717361c]::io::Write>::write_fmt
   3:     0x7f4c665847f8 - std[dbd160d25717361c]::panicking::default_hook::{closure#0}
   4:     0x7f4c665a1bf3 - std[dbd160d25717361c]::panicking::default_hook
   5:     0x7f4c6559e53c - std[dbd160d25717361c]::panicking::update_hook::<alloc[fbe1da7a96f3d929]::boxed::Box<rustc_driver_impl[11714a0f3389eb15]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7f4c665a1ed2 - std[dbd160d25717361c]::panicking::panic_with_hook
   7:     0x7f4c655cdbc1 - std[dbd160d25717361c]::panicking::begin_panic::<rustc_errors[e98ce2b093ebe336]::ExplicitBug>::{closure#0}
   8:     0x7f4c655c6626 - std[dbd160d25717361c]::sys::backtrace::__rust_end_short_backtrace::<std[dbd160d25717361c]::panicking::begin_panic<rustc_errors[e98ce2b093ebe336]::ExplicitBug>::{closure#0}, !>
   9:     0x7f4c655c660b - std[dbd160d25717361c]::panicking::begin_panic::<rustc_errors[e98ce2b093ebe336]::ExplicitBug>
  10:     0x7f4c655d9231 - <rustc_errors[e98ce2b093ebe336]::diagnostic::BugAbort as rustc_errors[e98ce2b093ebe336]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  11:     0x7f4c65bb84e9 - rustc_middle[b076dae3d4f5c3b1]::util::bug::opt_span_bug_fmt::<rustc_span[6d146ac66dea4702]::span_encoding::Span>::{closure#0}
  12:     0x7f4c65bb8672 - rustc_middle[b076dae3d4f5c3b1]::ty::context::tls::with_opt::<rustc_middle[b076dae3d4f5c3b1]::util::bug::opt_span_bug_fmt<rustc_span[6d146ac66dea4702]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  13:     0x7f4c65ba914b - rustc_middle[b076dae3d4f5c3b1]::ty::context::tls::with_context_opt::<rustc_middle[b076dae3d4f5c3b1]::ty::context::tls::with_opt<rustc_middle[b076dae3d4f5c3b1]::util::bug::opt_span_bug_fmt<rustc_span[6d146ac66dea4702]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  14:     0x7f4c6331f9c4 - rustc_middle[b076dae3d4f5c3b1]::util::bug::bug_fmt
  15:     0x7f4c670df8de - <rustc_trait_selection[56daeb37355a4237]::traits::fulfill::FulfillProcessor as rustc_data_structures[f30a6dcac191e75f]::obligation_forest::ObligationProcessor>::process_obligation
  16:     0x7f4c66c069c1 - <rustc_data_structures[f30a6dcac191e75f]::obligation_forest::ObligationForest<rustc_trait_selection[56daeb37355a4237]::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection[56daeb37355a4237]::traits::fulfill::FulfillProcessor>
  17:     0x7f4c6724021b - rustc_hir_typeck[85596fe57aff474]::typeck_with_inspect::{closure#0}
  18:     0x7f4c6723d2b0 - rustc_query_impl[d8b9270f442bd7e9]::query_impl::typeck::invoke_provider_fn::__rust_begin_short_backtrace
  19:     0x7f4c66ce7926 - rustc_query_impl[d8b9270f442bd7e9]::execution::try_execute_query::<rustc_data_structures[f30a6dcac191e75f]::vec_cache::VecCache<rustc_span[6d146ac66dea4702]::def_id::LocalDefId, rustc_middle[b076dae3d4f5c3b1]::query::erase::ErasedData<[u8; 8usize]>, rustc_middle[b076dae3d4f5c3b1]::dep_graph::graph::DepNodeIndex>, false>
  20:     0x7f4c66ce7383 - rustc_query_impl[d8b9270f442bd7e9]::query_impl::typeck::execute_query_non_incr::__rust_end_short_backtrace
  21:     0x7f4c6765e7a5 - rustc_mir_build[d007e31154e585d0]::thir::pattern::check_match::check_match
  22:     0x7f4c6765dc07 - rustc_query_impl[d8b9270f442bd7e9]::query_impl::check_match::invoke_provider_fn::__rust_begin_short_backtrace
  23:     0x7f4c678bbe24 - rustc_query_impl[d8b9270f442bd7e9]::execution::try_execute_query::<rustc_data_structures[f30a6dcac191e75f]::vec_cache::VecCache<rustc_span[6d146ac66dea4702]::def_id::LocalDefId, rustc_middle[b076dae3d4f5c3b1]::query::erase::ErasedData<[u8; 1usize]>, rustc_middle[b076dae3d4f5c3b1]::dep_graph::graph::DepNodeIndex>, false>
  24:     0x7f4c678bba82 - rustc_query_impl[d8b9270f442bd7e9]::query_impl::check_match::execute_query_non_incr::__rust_end_short_backtrace
  25:     0x7f4c67665b4a - rustc_mir_build[d007e31154e585d0]::builder::build_mir_inner_impl
  26:     0x7f4c66c0b434 - rustc_mir_transform[60db7b1400619a9]::mir_built
  27:     0x7f4c66ce7926 - rustc_query_impl[d8b9270f442bd7e9]::execution::try_execute_query::<rustc_data_structures[f30a6dcac191e75f]::vec_cache::VecCache<rustc_span[6d146ac66dea4702]::def_id::LocalDefId, rustc_middle[b076dae3d4f5c3b1]::query::erase::ErasedData<[u8; 8usize]>, rustc_middle[b076dae3d4f5c3b1]::dep_graph::graph::DepNodeIndex>, false>
  28:     0x7f4c66ce7443 - rustc_query_impl[d8b9270f442bd7e9]::query_impl::mir_built::execute_query_non_incr::__rust_end_short_backtrace
  29:     0x7f4c66f92e43 - rustc_query_impl[d8b9270f442bd7e9]::query_impl::trivial_const::invoke_provider_fn::__rust_begin_short_backtrace
  30:     0x7f4c66f922ee - rustc_query_impl[d8b9270f442bd7e9]::execution::try_execute_query::<rustc_middle[b076dae3d4f5c3b1]::query::caches::DefIdCache<rustc_middle[b076dae3d4f5c3b1]::query::erase::ErasedData<[u8; 32usize]>>, false>
  31:     0x7f4c66f91950 - rustc_query_impl[d8b9270f442bd7e9]::query_impl::trivial_const::execute_query_non_incr::__rust_end_short_backtrace
  32:     0x7f4c67cd597a - rustc_const_eval[7dbf906d1701551b]::const_eval::eval_queries::eval_to_allocation_raw_provider
  33:     0x7f4c67cd29d6 - rustc_query_impl[d8b9270f442bd7e9]::query_impl::eval_to_allocation_raw::invoke_provider_fn::__rust_begin_short_backtrace
  34:     0x7f4c675af357 - rustc_query_impl[d8b9270f442bd7e9]::execution::try_execute_query::<rustc_middle[b076dae3d4f5c3b1]::query::caches::DefaultCache<rustc_middle[b076dae3d4f5c3b1]::ty::PseudoCanonicalInput<rustc_middle[b076dae3d4f5c3b1]::mir::interpret::GlobalId>, rustc_middle[b076dae3d4f5c3b1]::query::erase::ErasedData<[u8; 24usize]>>, false>
  35:     0x7f4c675aed4f - rustc_query_impl[d8b9270f442bd7e9]::query_impl::eval_to_allocation_raw::execute_query_non_incr::__rust_end_short_backtrace
  36:     0x7f4c67121013 - rustc_const_eval[7dbf906d1701551b]::const_eval::valtrees::eval_to_valtree
  37:     0x7f4c67120de6 - <rustc_const_eval[7dbf906d1701551b]::provide::{closure#0} as core[af451d9ab418ad9]::ops::function::FnOnce<(rustc_middle[b076dae3d4f5c3b1]::ty::context::TyCtxt, rustc_middle[b076dae3d4f5c3b1]::ty::PseudoCanonicalInput<rustc_middle[b076dae3d4f5c3b1]::mir::interpret::GlobalId>)>>::call_once
  38:     0x7f4c67120d9c - rustc_query_impl[d8b9270f442bd7e9]::query_impl::eval_to_valtree::invoke_provider_fn::__rust_begin_short_backtrace
  39:     0x7f4c6748d72a - rustc_query_impl[d8b9270f442bd7e9]::execution::try_execute_query::<rustc_middle[b076dae3d4f5c3b1]::query::caches::DefaultCache<rustc_middle[b076dae3d4f5c3b1]::ty::PseudoCanonicalInput<rustc_middle[b076dae3d4f5c3b1]::mir::interpret::GlobalId>, rustc_middle[b076dae3d4f5c3b1]::query::erase::ErasedData<[u8; 16usize]>>, false>
  40:     0x7f4c6748d358 - rustc_query_impl[d8b9270f442bd7e9]::query_impl::eval_to_valtree::execute_query_non_incr::__rust_end_short_backtrace
  41:     0x7f4c63ab43c9 - <rustc_middle[b076dae3d4f5c3b1]::ty::context::TyCtxt>::const_eval_resolve_for_typeck
  42:     0x7f4c66d509ca - rustc_trait_selection[56daeb37355a4237]::traits::try_evaluate_const
  43:     0x7f4c66d54301 - <rustc_trait_selection[56daeb37355a4237]::traits::normalize::AssocTypeNormalizer as rustc_type_ir[51689a520c4c106f]::fold::TypeFolder<rustc_middle[b076dae3d4f5c3b1]::ty::context::TyCtxt>>::fold_const
  44:     0x7f4c66d55db6 - <rustc_middle[b076dae3d4f5c3b1]::ty::Ty as rustc_type_ir[51689a520c4c106f]::fold::TypeSuperFoldable<rustc_middle[b076dae3d4f5c3b1]::ty::context::TyCtxt>>::super_fold_with::<rustc_trait_selection[56daeb37355a4237]::traits::normalize::AssocTypeNormalizer>
  45:     0x7f4c674fde23 - <rustc_hir_analysis[1ead07aac7240e30]::check::wfcheck::WfCheckingCtxt>::deeply_normalize::<rustc_middle[b076dae3d4f5c3b1]::ty::Ty>
  46:     0x7f4c674ff4e9 - rustc_hir_analysis[1ead07aac7240e30]::check::wfcheck::check_fn_or_method
  47:     0x7f4c67507f0a - rustc_hir_analysis[1ead07aac7240e30]::check::wfcheck::check_associated_item
  48:     0x7f4c678be244 - rustc_hir_analysis[1ead07aac7240e30]::check::check::check_item_type
  49:     0x7f4c678bc826 - rustc_hir_analysis[1ead07aac7240e30]::check::wfcheck::check_well_formed
  50:     0x7f4c678bc807 - rustc_query_impl[d8b9270f442bd7e9]::query_impl::check_well_formed::invoke_provider_fn::__rust_begin_short_backtrace
  51:     0x7f4c678bbe24 - rustc_query_impl[d8b9270f442bd7e9]::execution::try_execute_query::<rustc_data_structures[f30a6dcac191e75f]::vec_cache::VecCache<rustc_span[6d146ac66dea4702]::def_id::LocalDefId, rustc_middle[b076dae3d4f5c3b1]::query::erase::ErasedData<[u8; 1usize]>, rustc_middle[b076dae3d4f5c3b1]::dep_graph::graph::DepNodeIndex>, false>
  52:     0x7f4c678bbbbb - rustc_query_impl[d8b9270f442bd7e9]::query_impl::check_well_formed::execute_query_non_incr::__rust_end_short_backtrace
  53:     0x7f4c678b8328 - rustc_hir_analysis[1ead07aac7240e30]::check::wfcheck::check_type_wf
  54:     0x7f4c678b8213 - rustc_query_impl[d8b9270f442bd7e9]::query_impl::check_type_wf::invoke_provider_fn::__rust_begin_short_backtrace
  55:     0x7f4c67e35690 - rustc_query_impl[d8b9270f442bd7e9]::execution::try_execute_query::<rustc_middle[b076dae3d4f5c3b1]::query::caches::SingleCache<rustc_middle[b076dae3d4f5c3b1]::query::erase::ErasedData<[u8; 1usize]>>, false>
  56:     0x7f4c67e35469 - rustc_query_impl[d8b9270f442bd7e9]::query_impl::check_type_wf::execute_query_non_incr::__rust_end_short_backtrace
  57:     0x7f4c66dbf897 - rustc_hir_analysis[1ead07aac7240e30]::check_crate
  58:     0x7f4c66ce40da - rustc_interface[7600c9e4d7bd5078]::passes::analysis
  59:     0x7f4c67e37e09 - rustc_query_impl[d8b9270f442bd7e9]::execution::try_execute_query::<rustc_middle[b076dae3d4f5c3b1]::query::caches::SingleCache<rustc_middle[b076dae3d4f5c3b1]::query::erase::ErasedData<[u8; 0usize]>>, false>
  60:     0x7f4c67e37a75 - rustc_query_impl[d8b9270f442bd7e9]::query_impl::analysis::execute_query_non_incr::__rust_end_short_backtrace
  61:     0x7f4c67e559d4 - rustc_interface[7600c9e4d7bd5078]::interface::run_compiler::<(), rustc_driver_impl[11714a0f3389eb15]::run_compiler::{closure#0}>::{closure#1}
  62:     0x7f4c67e2297e - std[dbd160d25717361c]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[7600c9e4d7bd5078]::util::run_in_thread_with_globals<rustc_interface[7600c9e4d7bd5078]::util::run_in_thread_pool_with_globals<rustc_interface[7600c9e4d7bd5078]::interface::run_compiler<(), rustc_driver_impl[11714a0f3389eb15]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  63:     0x7f4c67e23220 - <std[dbd160d25717361c]::thread::lifecycle::spawn_unchecked<rustc_interface[7600c9e4d7bd5078]::util::run_in_thread_with_globals<rustc_interface[7600c9e4d7bd5078]::util::run_in_thread_pool_with_globals<rustc_interface[7600c9e4d7bd5078]::interface::run_compiler<(), rustc_driver_impl[11714a0f3389eb15]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[af451d9ab418ad9]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  64:     0x7f4c67e240ac - <std[dbd160d25717361c]::sys::thread::unix::Thread>::new::thread_start
  65:     0x7f4c618a597a - <unknown>
  66:     0x7f4c619292bc - <unknown>
  67:                0x0 - <unknown>

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: rustc 1.96.0-nightly (f66622c7e 2026-03-23) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [typeck] type-checking `<impl at /tmp/icemaker_global_tempdir.V83zeUDD57C1/rustc_testrunner_tmpdir_reporting.T7QySKNN0ONt/mvce.rs:3:1: 3:26>::foo::{constant#0}`
#1 [check_match] match-checking `<impl at /tmp/icemaker_global_tempdir.V83zeUDD57C1/rustc_testrunner_tmpdir_reporting.T7QySKNN0ONt/mvce.rs:3:1: 3:26>::foo::{constant#0}`
#2 [mir_built] building MIR for `<impl at /tmp/icemaker_global_tempdir.V83zeUDD57C1/rustc_testrunner_tmpdir_reporting.T7QySKNN0ONt/mvce.rs:3:1: 3:26>::foo::{constant#0}`
#3 [trivial_const] checking if `<impl at /tmp/icemaker_global_tempdir.V83zeUDD57C1/rustc_testrunner_tmpdir_reporting.T7QySKNN0ONt/mvce.rs:3:1: 3:26>::foo::{constant#0}` is a trivial const
#4 [eval_to_allocation_raw] const-evaluating + checking `<impl at /tmp/icemaker_global_tempdir.V83zeUDD57C1/rustc_testrunner_tmpdir_reporting.T7QySKNN0ONt/mvce.rs:3:1: 3:26>::foo::{constant#0}`
#5 [eval_to_valtree] evaluating type-level constant
#6 [check_well_formed] checking that `<impl at /tmp/icemaker_global_tempdir.V83zeUDD57C1/rustc_testrunner_tmpdir_reporting.T7QySKNN0ONt/mvce.rs:3:1: 3:26>::foo` is well-formed
#7 [check_type_wf] checking that types are well-formed
#8 [analysis] running analysis passes on crate `mvce`
end of query stack
error: aborting due to 2 previous errors; 1 warning emitted

For more information about this error, try `rustc --explain E0601`.

Metadata

Metadata

Assignees

Labels

A-const-genericsArea: const generics (parameters and arguments)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.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions