rust-lang / rust-lang/rust

ICE: `cannot find 'N/#0' in param-env: ParamEnv`

Open
#143,117 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug F-adt_const_params F-generic_const_exprs F-generic_const_parameter_types I-ICE T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
#![feature(generic_const_exprs)]
#![feature(generic_const_parameter_types)]
#![feature(adt_const_params)]
#[derive(Clone)]
struct Foo<const N : [u8; Self::FOO]>;

pub fn main() {}

Version information

rustc 1.90.0-nightly (fe5f3dedf 2025-06-27)
binary: rustc
commit-hash: fe5f3dedf7b4d6bea2cadb17343f747d70b4c66b
commit-date: 2025-06-27
host: x86_64-unknown-linux-gnu
release: 1.90.0-nightly
LLVM version: 20.1.7

Possibly related line of code:
https://github.com/rust-lang/rust/blob/fe5f3dedf7b4d6bea2cadb17343f747d70b4c66b/compiler/rustc_middle/src/ty/sty.rs#L366-L378

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

Program output

error: cannot use `Self` in const parameter type
 --> /tmp/icemaker_global_tempdir.09Cy251VhU78/rustc_testrunner_tmpdir_reporting.l9Ia4P1qfQIs/mvce.rs:5:26
  |
5 | struct Foo<const N: [u8; Self::FOO]>;
  |                          ^^^^^^^^^

warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /tmp/icemaker_global_tempdir.09Cy251VhU78/rustc_testrunner_tmpdir_reporting.l9Ia4P1qfQIs/mvce.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

warning: the feature `generic_const_parameter_types` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /tmp/icemaker_global_tempdir.09Cy251VhU78/rustc_testrunner_tmpdir_reporting.l9Ia4P1qfQIs/mvce.rs:2:12
  |
2 | #![feature(generic_const_parameter_types)]
  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #137626 <https://github.com/rust-lang/rust/issues/137626> for more information

error[E0601]: `main` function not found in crate `mvce`
 --> /tmp/icemaker_global_tempdir.09Cy251VhU78/rustc_testrunner_tmpdir_reporting.l9Ia4P1qfQIs/mvce.rs:5:38
  |
5 | struct Foo<const N: [u8; Self::FOO]>;
  |                                      ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.09Cy251VhU78/rustc_testrunner_tmpdir_reporting.l9Ia4P1qfQIs/mvce.rs`

error: `[u8; Self::FOO]` is forbidden as the type of a const generic parameter
 --> /tmp/icemaker_global_tempdir.09Cy251VhU78/rustc_testrunner_tmpdir_reporting.l9Ia4P1qfQIs/mvce.rs:5:21
  |
5 | struct Foo<const N: [u8; Self::FOO]>;
  |                     ^^^^^^^^^^^^^^^
  |
  = note: the only supported types are integers, `bool`, and `char`
help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
  |
4 + #![feature(adt_const_params)]
  |

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


thread 'rustc' panicked at compiler/rustc_middle/src/ty/sty.rs:372:13:
Box<dyn Any>
stack backtrace:
   0:     0x7dc6aa1096f3 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h48b24be8297e4a9c
   1:     0x7dc6aa802c37 - core::fmt::write::h44ef114fca1e3410
   2:     0x7dc6aa0ff213 - std::io::Write::write_fmt::h48f3596bb626dcaa
   3:     0x7dc6aa109552 - std::sys::backtrace::BacktraceLock::print::h08fe9f4d0c0a723f
   4:     0x7dc6aa10d04a - std::panicking::default_hook::{{closure}}::h470a325c2f4bb1be
   5:     0x7dc6aa10cbcf - std::panicking::default_hook::h375895b5d6b84766
   6:     0x7dc6a91ea173 - std[7a7d327c4bb6bc11]::panicking::update_hook::<alloc[95fe608572e1da2a]::boxed::Box<rustc_driver_impl[1d35d6f9d2799e05]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x7dc6aa10d89b - std::panicking::rust_panic_with_hook::h3f9361c44c0dd63d
   8:     0x7dc6a9224261 - std[7a7d327c4bb6bc11]::panicking::begin_panic::<rustc_errors[46b8c952c97445c4]::ExplicitBug>::{closure#0}
   9:     0x7dc6a9218936 - std[7a7d327c4bb6bc11]::sys::backtrace::__rust_end_short_backtrace::<std[7a7d327c4bb6bc11]::panicking::begin_panic<rustc_errors[46b8c952c97445c4]::ExplicitBug>::{closure#0}, !>
  10:     0x7dc6a9215139 - std[7a7d327c4bb6bc11]::panicking::begin_panic::<rustc_errors[46b8c952c97445c4]::ExplicitBug>
  11:     0x7dc6a922dd41 - <rustc_errors[46b8c952c97445c4]::diagnostic::BugAbort as rustc_errors[46b8c952c97445c4]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x7dc6a97f6bca - rustc_middle[421a23b7571f26a5]::util::bug::opt_span_bug_fmt::<rustc_span[dd092a92122222c1]::span_encoding::Span>::{closure#0}
  13:     0x7dc6a97d66ba - rustc_middle[421a23b7571f26a5]::ty::context::tls::with_opt::<rustc_middle[421a23b7571f26a5]::util::bug::opt_span_bug_fmt<rustc_span[dd092a92122222c1]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x7dc6a97d652b - rustc_middle[421a23b7571f26a5]::ty::context::tls::with_context_opt::<rustc_middle[421a23b7571f26a5]::ty::context::tls::with_opt<rustc_middle[421a23b7571f26a5]::util::bug::opt_span_bug_fmt<rustc_span[dd092a92122222c1]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x7dc6a689f860 - rustc_middle[421a23b7571f26a5]::util::bug::bug_fmt
  16:     0x7dc6ab279cb9 - <rustc_trait_selection[e32a2b5ce67343b3]::traits::fulfill::FulfillProcessor as rustc_data_structures[d5f78031b72118ca]::obligation_forest::ObligationProcessor>::process_obligation
  17:     0x7dc6aa805902 - <rustc_data_structures[d5f78031b72118ca]::obligation_forest::ObligationForest<rustc_trait_selection[e32a2b5ce67343b3]::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection[e32a2b5ce67343b3]::traits::fulfill::FulfillProcessor>
  18:     0x7dc6ab68a4f6 - <rustc_hir_typeck[e45be9a4afc83985]::fn_ctxt::FnCtxt>::check_expr_path
  19:     0x7dc6ab341e96 - <rustc_hir_typeck[e45be9a4afc83985]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  20:     0x7dc6ab9f3e01 - rustc_hir_typeck[e45be9a4afc83985]::typeck_with_inspect::{closure#0}
  21:     0x7dc6ab9f23b0 - rustc_query_impl[a46554db2076a7e1]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a46554db2076a7e1]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[421a23b7571f26a5]::query::erase::Erased<[u8; 8usize]>>
  22:     0x7dc6aaa0bcee - rustc_query_system[9da031a4e4fdb32b]::query::plumbing::try_execute_query::<rustc_query_impl[a46554db2076a7e1]::DynamicConfig<rustc_data_structures[d5f78031b72118ca]::vec_cache::VecCache<rustc_span[dd092a92122222c1]::def_id::LocalDefId, rustc_middle[421a23b7571f26a5]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[9da031a4e4fdb32b]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[a46554db2076a7e1]::plumbing::QueryCtxt, false>
  23:     0x7dc6aaa0b689 - rustc_query_impl[a46554db2076a7e1]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  24:     0x7dc6ab24104b - rustc_mir_build[4861131aeeb73c8e]::thir::cx::thir_body
  25:     0x7dc6ab23fdb4 - rustc_query_impl[a46554db2076a7e1]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a46554db2076a7e1]::query_impl::thir_body::dynamic_query::{closure#2}::{closure#0}, rustc_middle[421a23b7571f26a5]::query::erase::Erased<[u8; 16usize]>>
  26:     0x7dc6ab20d382 - rustc_query_system[9da031a4e4fdb32b]::query::plumbing::try_execute_query::<rustc_query_impl[a46554db2076a7e1]::DynamicConfig<rustc_data_structures[d5f78031b72118ca]::vec_cache::VecCache<rustc_span[dd092a92122222c1]::def_id::LocalDefId, rustc_middle[421a23b7571f26a5]::query::erase::Erased<[u8; 16usize]>, rustc_query_system[9da031a4e4fdb32b]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[a46554db2076a7e1]::plumbing::QueryCtxt, false>
  27:     0x7dc6ab20cfcc - rustc_query_impl[a46554db2076a7e1]::query_impl::thir_body::get_query_non_incr::__rust_end_short_backtrace
  28:     0x7dc6aac82047 - rustc_query_impl[a46554db2076a7e1]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a46554db2076a7e1]::query_impl::thir_abstract_const::dynamic_query::{closure#2}::{closure#0}, rustc_middle[421a23b7571f26a5]::query::erase::Erased<[u8; 16usize]>>
  29:     0x7dc6aac81f8d - <rustc_query_impl[a46554db2076a7e1]::query_impl::thir_abstract_const::dynamic_query::{closure#2} as core[df8911376af37c8c]::ops::function::FnOnce<(rustc_middle[421a23b7571f26a5]::ty::context::TyCtxt, rustc_span[dd092a92122222c1]::def_id::DefId)>>::call_once
  30:     0x7dc6aa9c19fb - rustc_query_system[9da031a4e4fdb32b]::query::plumbing::try_execute_query::<rustc_query_impl[a46554db2076a7e1]::DynamicConfig<rustc_query_system[9da031a4e4fdb32b]::query::caches::DefIdCache<rustc_middle[421a23b7571f26a5]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[a46554db2076a7e1]::plumbing::QueryCtxt, false>
  31:     0x7dc6aa9c1632 - rustc_query_impl[a46554db2076a7e1]::query_impl::thir_abstract_const::get_query_non_incr::__rust_end_short_backtrace
  32:     0x7dc6abef5d37 - <<rustc_middle[421a23b7571f26a5]::ty::context::TyCtxt>::expand_abstract_consts::Expander as rustc_type_ir[b99847d00467586e]::fold::TypeFolder<rustc_middle[421a23b7571f26a5]::ty::context::TyCtxt>>::fold_const.warm
  33:     0x7dc6aa841031 - rustc_trait_selection[e32a2b5ce67343b3]::traits::const_evaluatable::is_const_evaluatable
  34:     0x7dc6ab27dfad - <rustc_trait_selection[e32a2b5ce67343b3]::traits::fulfill::FulfillProcessor as rustc_data_structures[d5f78031b72118ca]::obligation_forest::ObligationProcessor>::process_obligation
  35:     0x7dc6aa805902 - <rustc_data_structures[d5f78031b72118ca]::obligation_forest::ObligationForest<rustc_trait_selection[e32a2b5ce67343b3]::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection[e32a2b5ce67343b3]::traits::fulfill::FulfillProcessor>
  36:     0x7dc6ab1de967 - <rustc_trait_selection[e32a2b5ce67343b3]::traits::fulfill::FulfillmentContext<rustc_trait_selection[e32a2b5ce67343b3]::traits::FulfillmentError> as rustc_infer[cb3f45674935538]::traits::engine::TraitEngine<rustc_trait_selection[e32a2b5ce67343b3]::traits::FulfillmentError>>::select_all_or_error
  37:     0x7dc6ab1e0ec3 - rustc_hir_analysis[bda1b381e8c255de]::check::wfcheck::check_item
  38:     0x7dc6ab1d9bd9 - rustc_hir_analysis[bda1b381e8c255de]::check::wfcheck::check_well_formed
  39:     0x7dc6ab1d9a59 - rustc_query_impl[a46554db2076a7e1]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a46554db2076a7e1]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[421a23b7571f26a5]::query::erase::Erased<[u8; 1usize]>>
  40:     0x7dc6ab1d928d - rustc_query_system[9da031a4e4fdb32b]::query::plumbing::try_execute_query::<rustc_query_impl[a46554db2076a7e1]::DynamicConfig<rustc_data_structures[d5f78031b72118ca]::vec_cache::VecCache<rustc_span[dd092a92122222c1]::def_id::LocalDefId, rustc_middle[421a23b7571f26a5]::query::erase::Erased<[u8; 1usize]>, rustc_query_system[9da031a4e4fdb32b]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[a46554db2076a7e1]::plumbing::QueryCtxt, false>
  41:     0x7dc6ab1d8dc2 - rustc_query_impl[a46554db2076a7e1]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
  42:     0x7dc6ab1d651f - rustc_hir_analysis[bda1b381e8c255de]::check::wfcheck::check_type_wf
  43:     0x7dc6ab1d641d - rustc_query_impl[a46554db2076a7e1]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a46554db2076a7e1]::query_impl::check_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[421a23b7571f26a5]::query::erase::Erased<[u8; 1usize]>>
  44:     0x7dc6ab8af9f0 - rustc_query_system[9da031a4e4fdb32b]::query::plumbing::try_execute_query::<rustc_query_impl[a46554db2076a7e1]::DynamicConfig<rustc_query_system[9da031a4e4fdb32b]::query::caches::SingleCache<rustc_middle[421a23b7571f26a5]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[a46554db2076a7e1]::plumbing::QueryCtxt, false>
  45:     0x7dc6ab8af7ce - rustc_query_impl[a46554db2076a7e1]::query_impl::check_type_wf::get_query_non_incr::__rust_end_short_backtrace
  46:     0x7dc6aaa0343a - rustc_hir_analysis[bda1b381e8c255de]::check_crate
  47:     0x7dc6aaa077a7 - rustc_interface[b6aba49ee050940e]::passes::analysis
  48:     0x7dc6aaa073cb - rustc_query_impl[a46554db2076a7e1]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a46554db2076a7e1]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[421a23b7571f26a5]::query::erase::Erased<[u8; 0usize]>>
  49:     0x7dc6ab8b113c - rustc_query_system[9da031a4e4fdb32b]::query::plumbing::try_execute_query::<rustc_query_impl[a46554db2076a7e1]::DynamicConfig<rustc_query_system[9da031a4e4fdb32b]::query::caches::SingleCache<rustc_middle[421a23b7571f26a5]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[a46554db2076a7e1]::plumbing::QueryCtxt, false>
  50:     0x7dc6ab8b0e12 - rustc_query_impl[a46554db2076a7e1]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  51:     0x7dc6abaa99d6 - rustc_interface[b6aba49ee050940e]::passes::create_and_enter_global_ctxt::<core[df8911376af37c8c]::option::Option<rustc_interface[b6aba49ee050940e]::queries::Linker>, rustc_driver_impl[1d35d6f9d2799e05]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  52:     0x7dc6aba9ae2f - rustc_interface[b6aba49ee050940e]::interface::run_compiler::<(), rustc_driver_impl[1d35d6f9d2799e05]::run_compiler::{closure#0}>::{closure#1}
  53:     0x7dc6aba460b8 - std[7a7d327c4bb6bc11]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[b6aba49ee050940e]::util::run_in_thread_with_globals<rustc_interface[b6aba49ee050940e]::util::run_in_thread_pool_with_globals<rustc_interface[b6aba49ee050940e]::interface::run_compiler<(), rustc_driver_impl[1d35d6f9d2799e05]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  54:     0x7dc6aba45d96 - <<std[7a7d327c4bb6bc11]::thread::Builder>::spawn_unchecked_<rustc_interface[b6aba49ee050940e]::util::run_in_thread_with_globals<rustc_interface[b6aba49ee050940e]::util::run_in_thread_pool_with_globals<rustc_interface[b6aba49ee050940e]::interface::run_compiler<(), rustc_driver_impl[1d35d6f9d2799e05]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[df8911376af37c8c]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  55:     0x7dc6aba443bd - std::sys::pal::unix::thread::Thread::new::thread_start::h10083fa6b51603a6
  56:     0x7dc6a54a57eb - <unknown>
  57:     0x7dc6a552918c - <unknown>
  58:                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.90.0-nightly (fe5f3dedf 2025-06-27) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [typeck] type-checking `<impl at /tmp/icemaker_global_tempdir.09Cy251VhU78/rustc_testrunner_tmpdir_reporting.l9Ia4P1qfQIs/mvce.rs:4:10: 4:15>::{constant#0}`
#1 [thir_body] building THIR for `<impl at /tmp/icemaker_global_tempdir.09Cy251VhU78/rustc_testrunner_tmpdir_reporting.l9Ia4P1qfQIs/mvce.rs:4:10: 4:15>::{constant#0}`
#2 [thir_abstract_const] building an abstract representation for `<impl at /tmp/icemaker_global_tempdir.09Cy251VhU78/rustc_testrunner_tmpdir_reporting.l9Ia4P1qfQIs/mvce.rs:4:10: 4:15>::{constant#0}`
#3 [check_well_formed] checking that `<impl at /tmp/icemaker_global_tempdir.09Cy251VhU78/rustc_testrunner_tmpdir_reporting.l9Ia4P1qfQIs/mvce.rs:4:10: 4:15>` is well-formed
#4 [check_type_wf] checking that types are well-formed
#5 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 4 previous errors; 2 warnings emitted

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

@rustbot label +F-generic_const_exprs +F-generic_const_parameter_types +F-adt_const_params

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the ICE with the provided minimal Rust program and nightly toolchain, then inspect compiler/rustc_middle/src/ty/sty.rs around lines 366-378 and the reported trait-selection and type-checking paths. Trace why the N/#0 parameter is absent from the ParamEnv; done means the program reports a normal diagnostic without panicking, with regression coverage added for this example.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.