Skip to content

ICE: cannot find R/#0 in param-env when using generic parameters in const operations #153163

@Anonymous1-design

Description

@Anonymous1-design

I tried this code:

trait ImageTrait {
    type Rows: ;
}
struct Image<const R: usize, const C: usize>();
impl<const R: usize, > ImageTrait for Image<R, C> {
    fn get_image_data() -> &[[u32; Self::Columns::SIZE]; Self::Rows::SIZE] {
    }
}

Meta

rustc --version --verbose:

rustc 1.93.0 (254b59607 2026-01-19)
binary: rustc
commit-hash: 254b59607d4417e9dffbc307138ae5c86280fe4c
commit-date: 2026-01-19
host: x86_64-unknown-linux-gnu
release: 1.93.0
LLVM version: 21.1.8
Backtrace

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


thread 'rustc' (1087139) panicked at compiler/rustc_middle/src/ty/sty.rs:373: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_middle::ty::sty::ParamConst>::find_const_ty_from_env.cold
   7: <rustc_trait_selection::traits::fulfill::FulfillProcessor as rustc_data_structures::obligation_forest::ObligationProcessor>::process_obligation
   8: <rustc_data_structures::obligation_forest::ObligationForest<rustc_trait_selection::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection::traits::fulfill::FulfillProcessor>
   9: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_path
  10: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  11: rustc_hir_typeck::typeck_with_inspect::{closure#0}
      [... omitted 1 frame ...]
  12: rustc_mir_build::thir::pattern::check_match::check_match
      [... omitted 1 frame ...]
  13: rustc_mir_build::builder::build_mir
  14: rustc_mir_transform::mir_built
      [... omitted 2 frames ...]
  15: rustc_const_eval::const_eval::eval_queries::eval_to_allocation_raw_provider
      [... omitted 1 frame ...]
  16: rustc_const_eval::const_eval::valtrees::eval_to_valtree
  17: <rustc_const_eval::provide::{closure#0} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_middle::ty::PseudoCanonicalInput<rustc_middle::mir::interpret::GlobalId>)>>::call_once
      [... omitted 2 frames ...]
  18: <rustc_middle::ty::context::TyCtxt>::const_eval_resolve_for_typeck
  19: rustc_trait_selection::traits::try_evaluate_const
  20: <rustc_trait_selection::traits::normalize::AssocTypeNormalizer as rustc_type_ir::fold::TypeFolder<rustc_middle::ty::context::TyCtxt>>::fold_const
  21: <rustc_middle::ty::Ty as rustc_type_ir::fold::TypeSuperFoldable<rustc_middle::ty::context::TyCtxt>>::super_fold_with::<rustc_trait_selection::traits::normalize::AssocTypeNormalizer>
  22: <rustc_middle::ty::Ty as rustc_type_ir::fold::TypeSuperFoldable<rustc_middle::ty::context::TyCtxt>>::super_fold_with::<rustc_trait_selection::traits::normalize::AssocTypeNormalizer>
  23: <rustc_middle::ty::Ty as rustc_type_ir::fold::TypeSuperFoldable<rustc_middle::ty::context::TyCtxt>>::super_fold_with::<rustc_trait_selection::traits::normalize::AssocTypeNormalizer>
  24: <&rustc_middle::ty::list::RawList<(), rustc_middle::ty::Ty> as rustc_type_ir::fold::TypeFoldable<rustc_middle::ty::context::TyCtxt>>::fold_with::<rustc_trait_selection::traits::normalize::AssocTypeNormalizer>
  25: <rustc_trait_selection::traits::engine::ObligationCtxt<rustc_trait_selection::traits::FulfillmentError>>::normalize::<rustc_type_ir::ty_kind::FnSig<rustc_middle::ty::context::TyCtxt>>
  26: rustc_hir_analysis::check::compare_impl_item::compare_impl_item
      [... omitted 1 frame ...]
  27: rustc_hir_analysis::check::check::check_item_type
  28: rustc_hir_analysis::check::wfcheck::check_well_formed
      [... omitted 1 frame ...]
  29: rustc_hir_analysis::check::wfcheck::check_type_wf
      [... omitted 1 frame ...]
  30: rustc_hir_analysis::check_crate
  31: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  32: <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} as core::ops::function::FnOnce<(&rustc_session::session::Session, rustc_middle::ty::context::CurrentGcx, alloc::sync::Arc<rustc_data_structures::jobserver::Proxy>, &std::sync::once_lock::OnceLock<rustc_middle::ty::context::GlobalCtxt>, &rustc_data_structures::sync::worker_local::WorkerLocal<rustc_middle::arena::Arena>, &rustc_data_structures::sync::worker_local::WorkerLocal<rustc_hir::Arena>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0}
  33: 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.

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: rustc 1.93.0 (254b59607 2026-01-19) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [typeck] type-checking `<impl at ice.rs:17:1: 17:64>::get_image_data::{constant#0}`
#1 [check_match] match-checking `<impl at ice.rs:17:1: 17:64>::get_image_data::{constant#0}`
#2 [mir_built] building MIR for `<impl at ice.rs:17:1: 17:64>::get_image_data::{constant#0}`
#3 [trivial_const] checking if `<impl at ice.rs:17:1: 17:64>::get_image_data::{constant#0}` is a trivial const
#4 [eval_to_allocation_raw] const-evaluating + checking `<impl at ice.rs:17:1: 17:64>::get_image_data::{constant#0}`
#5 [eval_to_valtree] evaluating type-level constant
#6 [compare_impl_item] checking assoc item `<impl at ice.rs:17:1: 17:64>::get_image_data` is compatible with trait definition
#7 [check_well_formed] checking that `<impl at ice.rs:17:1: 17:64>` is well-formed
#8 [check_type_wf] checking that types are well-formed
#9 [analysis] running analysis passes on crate `bug`
end of query stack

Metadata

Metadata

Assignees

No one assigned

    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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions