rust-lang / rust-lang/rust

[ICE]: expected type for `impl ...` but found Const.. when instantiating

Open
#155,658 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug F-min_generic_const_args I-ICE needs-triage T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

snippet:

#![feature(min_generic_const_args)]

struct S<const N: usize>()
where
    S<{ main }>:;

fn main(_: impl ?Sized) {}

Version information

rustc 1.97.0-nightly (f676c20ed 2026-04-22)
binary: rustc
commit-hash: f676c20edd32321e9fa2781543d8970109707e30
commit-date: 2026-04-22
host: x86_64-unknown-linux-gnu
release: 1.97.0-nightly
LLVM version: 22.1.2

Possibly related line of code:
https://github.com/rust-lang/rust/blob/f676c20edd32321e9fa2781543d8970109707e30/compiler/rustc_type_ir/src/binder.rs#L774-L786

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

Program output

warning: the feature `min_generic_const_args` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /tmp/icemaker_global_tempdir.n2zhBENnAxL7/rustc_testrunner_tmpdir_reporting.tVf9INQOKps0/mvce.rs:1:12
  |
1 | #![feature(min_generic_const_args)]
  |            ^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #132980 <https://github.com/rust-lang/rust/issues/132980> for more information
  = note: `#[warn(incomplete_features)]` on by default


thread 'rustc' (3595469) panicked at /rustc-dev/f676c20edd32321e9fa2781543d8970109707e30/compiler/rustc_type_ir/src/binder.rs:780:9:
expected type for `impl ?Sized/#0` (impl ?Sized/#0/0) but found Const(main::<impl ?Sized>) when instantiating, args=[main::<impl ?Sized>]
stack backtrace:
   0:     0x7fae7c6307bb - <<std[b8d64e2847fc4178]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[d4bfc9c60fb22063]::fmt::Display>::fmt
   1:     0x7fae7cc2db08 - core[d4bfc9c60fb22063]::fmt::write
   2:     0x7fae7c647766 - <std[b8d64e2847fc4178]::sys::stdio::unix::Stderr as std[b8d64e2847fc4178]::io::Write>::write_fmt
   3:     0x7fae7c606a38 - std[b8d64e2847fc4178]::panicking::default_hook::{closure#0}
   4:     0x7fae7c623e23 - std[b8d64e2847fc4178]::panicking::default_hook
   5:     0x7fae7b5e3b6c - std[b8d64e2847fc4178]::panicking::update_hook::<alloc[3e237d8049b24958]::boxed::Box<rustc_driver_impl[357a5a533077f120]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7fae7c624102 - std[b8d64e2847fc4178]::panicking::panic_with_hook
   7:     0x7fae7c606af8 - std[b8d64e2847fc4178]::panicking::panic_handler::{closure#0}
   8:     0x7fae7c5fd839 - std[b8d64e2847fc4178]::sys::backtrace::__rust_end_short_backtrace::<std[b8d64e2847fc4178]::panicking::panic_handler::{closure#0}, !>
   9:     0x7fae7c60855d - __rustc[d06383092acfb5e4]::rust_begin_unwind
  10:     0x7fae797eb7cc - core[d4bfc9c60fb22063]::panicking::panic_fmt
  11:     0x7fae794e2651 - <rustc_type_ir[52ee834ff3b74c8a]::binder::ArgFolder<rustc_middle[c3912ba97521f304]::ty::context::TyCtxt>>::type_param_expected
  12:     0x7fae7cc45c64 - <rustc_type_ir[52ee834ff3b74c8a]::binder::ArgFolder<rustc_middle[c3912ba97521f304]::ty::context::TyCtxt> as rustc_type_ir[52ee834ff3b74c8a]::fold::TypeFolder<rustc_middle[c3912ba97521f304]::ty::context::TyCtxt>>::fold_ty
  13:     0x7fae7cc43559 - <rustc_type_ir[52ee834ff3b74c8a]::binder::ArgFolder<rustc_middle[c3912ba97521f304]::ty::context::TyCtxt> as rustc_type_ir[52ee834ff3b74c8a]::fold::TypeFolder<rustc_middle[c3912ba97521f304]::ty::context::TyCtxt>>::fold_ty
  14:     0x7fae7cc3dc67 - <rustc_type_ir[52ee834ff3b74c8a]::binder::ArgFolder<rustc_middle[c3912ba97521f304]::ty::context::TyCtxt> as rustc_type_ir[52ee834ff3b74c8a]::fold::TypeFolder<rustc_middle[c3912ba97521f304]::ty::context::TyCtxt>>::fold_const
  15:     0x7fae7cc42873 - <rustc_type_ir[52ee834ff3b74c8a]::binder::ArgFolder<rustc_middle[c3912ba97521f304]::ty::context::TyCtxt> as rustc_type_ir[52ee834ff3b74c8a]::fold::TypeFolder<rustc_middle[c3912ba97521f304]::ty::context::TyCtxt>>::fold_ty
  16:     0x7fae7cc4011d - <rustc_middle[c3912ba97521f304]::ty::generics::GenericPredicates>::instantiate_into
  17:     0x7fae7d705225 - <rustc_trait_selection[47a9a79168a577ed]::traits::wf::WfPredicates as rustc_type_ir[52ee834ff3b74c8a]::visit::TypeVisitor<rustc_middle[c3912ba97521f304]::ty::context::TyCtxt>>::visit_ty
  18:     0x7fae7d42d2dd - rustc_trait_selection[47a9a79168a577ed]::traits::wf::clause_obligations
  19:     0x7fae7d429a84 - rustc_hir_analysis[7364a272dc0a4549]::check::wfcheck::check_where_clauses
  20:     0x7fae7d44ade9 - rustc_hir_analysis[7364a272dc0a4549]::check::wfcheck::check_type_defn
  21:     0x7fae7d358ff0 - rustc_hir_analysis[7364a272dc0a4549]::check::check::check_item_type
  22:     0x7fae7d35519c - rustc_hir_analysis[7364a272dc0a4549]::check::wfcheck::check_well_formed
  23:     0x7fae7d355179 - rustc_query_impl[cf6728bbee7013af]::query_impl::check_well_formed::invoke_provider_fn::__rust_begin_short_backtrace
  24:     0x7fae7d354766 - rustc_query_impl[cf6728bbee7013af]::execution::try_execute_query::<rustc_data_structures[4d5a350bb12c3e7e]::vec_cache::VecCache<rustc_span[5e97d7b30bf4cb45]::def_id::LocalDefId, rustc_middle[c3912ba97521f304]::query::erase::ErasedData<[u8; 1usize]>, rustc_middle[c3912ba97521f304]::dep_graph::graph::DepNodeIndex>, false>
  25:     0x7fae7d3544fb - rustc_query_impl[cf6728bbee7013af]::query_impl::check_well_formed::execute_query_non_incr::__rust_end_short_backtrace
  26:     0x7fae7d350709 - rustc_hir_analysis[7364a272dc0a4549]::check::wfcheck::check_type_wf
  27:     0x7fae7d350613 - rustc_query_impl[cf6728bbee7013af]::query_impl::check_type_wf::invoke_provider_fn::__rust_begin_short_backtrace
  28:     0x7fae7dd4dc10 - rustc_query_impl[cf6728bbee7013af]::execution::try_execute_query::<rustc_middle[c3912ba97521f304]::query::caches::SingleCache<rustc_middle[c3912ba97521f304]::query::erase::ErasedData<[u8; 1usize]>>, false>
  29:     0x7fae7dd4d9e9 - rustc_query_impl[cf6728bbee7013af]::query_impl::check_type_wf::execute_query_non_incr::__rust_end_short_backtrace
  30:     0x7fae7d4ad6db - rustc_hir_analysis[7364a272dc0a4549]::check_crate
  31:     0x7fae7dae3d27 - rustc_interface[b8a47d5d5c195ccb]::passes::analysis
  32:     0x7fae7dd4b489 - rustc_query_impl[cf6728bbee7013af]::execution::try_execute_query::<rustc_middle[c3912ba97521f304]::query::caches::SingleCache<rustc_middle[c3912ba97521f304]::query::erase::ErasedData<[u8; 0usize]>>, false>
  33:     0x7fae7dd4b0e9 - rustc_query_impl[cf6728bbee7013af]::query_impl::analysis::execute_query_non_incr::__rust_end_short_backtrace
  34:     0x7fae7dd67007 - rustc_interface[b8a47d5d5c195ccb]::interface::run_compiler::<(), rustc_driver_impl[357a5a533077f120]::run_compiler::{closure#0}>::{closure#1}
  35:     0x7fae7dd3fd7e - std[b8d64e2847fc4178]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[b8a47d5d5c195ccb]::util::run_in_thread_with_globals<rustc_interface[b8a47d5d5c195ccb]::util::run_in_thread_pool_with_globals<rustc_interface[b8a47d5d5c195ccb]::interface::run_compiler<(), rustc_driver_impl[357a5a533077f120]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  36:     0x7fae7dd4046d - <std[b8d64e2847fc4178]::thread::lifecycle::spawn_unchecked<rustc_interface[b8a47d5d5c195ccb]::util::run_in_thread_with_globals<rustc_interface[b8a47d5d5c195ccb]::util::run_in_thread_pool_with_globals<rustc_interface[b8a47d5d5c195ccb]::interface::run_compiler<(), rustc_driver_impl[357a5a533077f120]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[d4bfc9c60fb22063]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  37:     0x7fae7dd412ec - <std[b8d64e2847fc4178]::sys::thread::unix::Thread>::new::thread_start
  38:     0x7fae778a597a - <unknown>
  39:     0x7fae779292bc - <unknown>
  40:                0x0 - <unknown>

error: the compiler unexpectedly panicked. This is a bug

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.97.0-nightly (f676c20ed 2026-04-22) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [check_well_formed] checking that `S` is well-formed
#1 [check_type_wf] checking that types are well-formed
#2 [analysis] running analysis passes on crate `mvce`
end of query stack
warning: 1 warning emitted

note: no errors encountered even though delayed bugs were created

note: those delayed bugs will now be shown as internal compiler errors

error: internal compiler error: function items cannot be used as const args
 --> /tmp/icemaker_global_tempdir.n2zhBENnAxL7/rustc_testrunner_tmpdir_reporting.tVf9INQOKps0/mvce.rs:5:9
  |
5 |     S<{ main }>:;
  |         ^^^^
  |
note: delayed at /rustc-dev/f676c20edd32321e9fa2781543d8970109707e30/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:2892:28
         0: <rustc_errors::DiagCtxtInner>::emit_diagnostic
         1: <rustc_errors::DiagCtxtHandle>::emit_diagnostic
         2: <rustc_span::ErrorGuaranteed as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
         3: <rustc_errors::DiagCtxtHandle>::span_delayed_bug::<rustc_span::span_encoding::Span, &str>
         4: <dyn rustc_hir_analysis::hir_ty_lowering::HirTyLowerer>::lower_resolved_const_path.cold
         5: <dyn rustc_hir_analysis::hir_ty_lowering::HirTyLowerer>::lower_generic_args_of_path::{closure#0}
         6: <dyn rustc_hir_analysis::hir_ty_lowering::HirTyLowerer>::lower_ty
         7: rustc_hir_analysis::collect::predicates_of::gather_explicit_predicates_of
         8: rustc_query_impl::query_impl::explicit_predicates_of::invoke_provider_fn::__rust_begin_short_backtrace
         9: rustc_query_impl::execution::try_execute_query::<rustc_middle::query::caches::DefIdCache<rustc_middle::query::erase::ErasedData<[u8; 24]>>, false>
        10: rustc_query_impl::query_impl::explicit_predicates_of::execute_query_non_incr::__rust_end_short_backtrace
        11: rustc_query_impl::query_impl::predicates_of::invoke_provider_fn::__rust_begin_short_backtrace
        12: rustc_query_impl::execution::try_execute_query::<rustc_middle::query::caches::DefIdCache<rustc_middle::query::erase::ErasedData<[u8; 24]>>, false>
        13: rustc_query_impl::query_impl::predicates_of::execute_query_non_incr::__rust_end_short_backtrace
        14: rustc_hir_analysis::check::check::check_item_type
        15: rustc_hir_analysis::check::wfcheck::check_well_formed
        16: rustc_query_impl::query_impl::check_well_formed::invoke_provider_fn::__rust_begin_short_backtrace
        17: rustc_query_impl::execution::try_execute_query::<rustc_data_structures::vec_cache::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::ErasedData<[u8; 1]>, rustc_middle::dep_graph::graph::DepNodeIndex>, false>
        18: rustc_query_impl::query_impl::check_well_formed::execute_query_non_incr::__rust_end_short_backtrace
        19: rustc_hir_analysis::check::wfcheck::check_type_wf
        20: rustc_query_impl::query_impl::check_type_wf::invoke_provider_fn::__rust_begin_short_backtrace
        21: rustc_query_impl::execution::try_execute_query::<rustc_middle::query::caches::SingleCache<rustc_middle::query::erase::ErasedData<[u8; 1]>>, false>
        22: rustc_query_impl::query_impl::check_type_wf::execute_query_non_incr::__rust_end_short_backtrace
        23: rustc_hir_analysis::check_crate
        24: rustc_interface::passes::analysis
        25: rustc_query_impl::execution::try_execute_query::<rustc_middle::query::caches::SingleCache<rustc_middle::query::erase::ErasedData<[u8; 0]>>, false>
        26: rustc_query_impl::query_impl::analysis::execute_query_non_incr::__rust_end_short_backtrace
        27: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
        28: std::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
        29: <std::thread::lifecycle::spawn_unchecked<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
        30: <std::sys::thread::unix::Thread>::new::thread_start
        31: <unknown>
        32: <unknown>
      
 --> /tmp/icemaker_global_tempdir.n2zhBENnAxL7/rustc_testrunner_tmpdir_reporting.tVf9INQOKps0/mvce.rs:5:9
  |
5 |     S<{ main }>:;
  |         ^^^^

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.97.0-nightly (f676c20ed 2026-04-22) running on x86_64-unknown-linux-gnu

query stack during panic:
end of query stack

@rustbot label +F-min_generic_const_args

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

Start by compiling the provided a.rs reproducer with the min_generic_const_args feature. Read compiler/rustc_type_ir/src/binder.rs around lines 774-786 and the delayed-bug location in compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:2892. Done means this input no longer triggers an internal compiler error and reports the invalid const argument appropriately.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.