Skip to content

ICE: ConstArgHasWrongType failed but we don't know how to compute type for {const error} #139905

Open
@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

trait If<const generic_const_exprs: bool> {}
impl If<{ N == 0 }> for () {}

trait Foobar {}

impl<const N: u8> Foobar<N> for () where (): If<N> {}

impl Foobar<N> for () {}

original:

#![feature(generic_const_exprs)]

trait If<const generic_const_exprs: bool> {}
impl If<{ N == 0 }> for () {}

trait IsZero<const N: usize> {}

impl<const generic_const_exprs: usize> IsZero<N> for () where (If): If<{ N == 0 }> {}

trait Foobar<const N: u8> {}

impl<const N: u8> Foobar<N> for () where (): If<N> {}

impl<const N: u8> Foobar<N> for () {}

pub fn main() {}

Version information

rustc 1.88.0-nightly (efb1e3d67 2025-04-16)
binary: rustc
commit-hash: efb1e3d676e1549811da79ebd124b6fc4d856248
commit-date: 2025-04-16
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.2

Possibly related line of code:

let ct_ty = match ct.kind() {
ty::ConstKind::Unevaluated(uv) => {
infcx.tcx.type_of(uv.def).instantiate(infcx.tcx, uv.args)
}
ty::ConstKind::Param(param_ct) => param_ct.find_ty_from_env(obligation.param_env),
ty::ConstKind::Value(cv) => cv.ty,
kind => span_bug!(
obligation.cause.span,
"ConstArgHasWrongType failed but we don't know how to compute type for {kind:?}"
),
};
FulfillmentErrorCode::Select(SelectionError::ConstArgHasWrongType {
ct,

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

Program output

error[E0425]: cannot find value `N` in this scope
 --> /tmp/icemaker_global_tempdir.DhVnlOQKWcDz/rustc_testrunner_tmpdir_reporting.pNj8RS2vIsUM/mvce.rs:2:11
  |
2 | impl If<{ N == 0 }> for () {}
  |           ^ not found in this scope
  |
help: you might be missing a const parameter
  |
2 | impl<const N: /* Type */> If<{ N == 0 }> for () {}
  |     +++++++++++++++++++++

error[E0412]: cannot find type `N` in this scope
 --> /tmp/icemaker_global_tempdir.DhVnlOQKWcDz/rustc_testrunner_tmpdir_reporting.pNj8RS2vIsUM/mvce.rs:8:13
  |
8 | impl Foobar<N> for () {}
  |             ^ not found in this scope
  |
help: you might be missing a type parameter
  |
8 | impl<N> Foobar<N> for () {}
  |     +++

error[E0601]: `main` function not found in crate `mvce`
 --> /tmp/icemaker_global_tempdir.DhVnlOQKWcDz/rustc_testrunner_tmpdir_reporting.pNj8RS2vIsUM/mvce.rs:8:25
  |
8 | impl Foobar<N> for () {}
  |                         ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.DhVnlOQKWcDz/rustc_testrunner_tmpdir_reporting.pNj8RS2vIsUM/mvce.rs`

error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied
 --> /tmp/icemaker_global_tempdir.DhVnlOQKWcDz/rustc_testrunner_tmpdir_reporting.pNj8RS2vIsUM/mvce.rs:6:19
  |
6 | impl<const N: u8> Foobar<N> for () where (): If<N> {}
  |                   ^^^^^^--- help: remove the unnecessary generics
  |                   |
  |                   expected 0 generic arguments
  |
note: trait defined here, with 0 generic parameters
 --> /tmp/icemaker_global_tempdir.DhVnlOQKWcDz/rustc_testrunner_tmpdir_reporting.pNj8RS2vIsUM/mvce.rs:4:7
  |
4 | trait Foobar {}
  |       ^^^^^^

error[E0207]: the const parameter `N` is not constrained by the impl trait, self type, or predicates
 --> /tmp/icemaker_global_tempdir.DhVnlOQKWcDz/rustc_testrunner_tmpdir_reporting.pNj8RS2vIsUM/mvce.rs:6:6
  |
6 | impl<const N: u8> Foobar<N> for () where (): If<N> {}
  |      ^^^^^^^^^^^ unconstrained const parameter
  |
  = note: expressions using a const parameter must map each value to a distinct output value
  = note: proving the result of expressions other than the parameter are unique is not supported

error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied
 --> /tmp/icemaker_global_tempdir.DhVnlOQKWcDz/rustc_testrunner_tmpdir_reporting.pNj8RS2vIsUM/mvce.rs:8:6
  |
8 | impl Foobar<N> for () {}
  |      ^^^^^^--- help: remove the unnecessary generics
  |      |
  |      expected 0 generic arguments
  |
note: trait defined here, with 0 generic parameters
 --> /tmp/icemaker_global_tempdir.DhVnlOQKWcDz/rustc_testrunner_tmpdir_reporting.pNj8RS2vIsUM/mvce.rs:4:7
  |
4 | trait Foobar {}
  |       ^^^^^^

error: internal compiler error: compiler/rustc_trait_selection/src/solve/fulfill/derive_errors.rs:41:25: ConstArgHasWrongType failed but we don't know how to compute type for {const error}


thread 'rustc' panicked at compiler/rustc_trait_selection/src/solve/fulfill/derive_errors.rs:41:25:
Box<dyn Any>
stack backtrace:
   0:     0x72d6580e8673 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h1a1578912ef3532a
   1:     0x72d658805b07 - core::fmt::write::heb19b03bbf71ea65
   2:     0x72d659c9ec11 - std::io::Write::write_fmt::h03bed1eb86fc19b5
   3:     0x72d6580e84d2 - std::sys::backtrace::BacktraceLock::print::ha68b0dc472f598a9
   4:     0x72d6580ebe4a - std::panicking::default_hook::{{closure}}::h05ef3467e6512178
   5:     0x72d6580eb9cf - std::panicking::default_hook::h0056913d3552120b
   6:     0x72d65715a2c3 - std[5aea8dc484e35cc6]::panicking::update_hook::<alloc[32bfce7e44e7099d]::boxed::Box<rustc_driver_impl[5fbc7f39e785f21a]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x72d6580ec6c3 - std::panicking::rust_panic_with_hook::h569a87af951f918c
   8:     0x72d657199421 - std[5aea8dc484e35cc6]::panicking::begin_panic::<rustc_errors[1bbd3c49342f8c7f]::ExplicitBug>::{closure#0}
   9:     0x72d65718d2f6 - std[5aea8dc484e35cc6]::sys::backtrace::__rust_end_short_backtrace::<std[5aea8dc484e35cc6]::panicking::begin_panic<rustc_errors[1bbd3c49342f8c7f]::ExplicitBug>::{closure#0}, !>
  10:     0x72d657189d3b - std[5aea8dc484e35cc6]::panicking::begin_panic::<rustc_errors[1bbd3c49342f8c7f]::ExplicitBug>
  11:     0x72d6571a37f1 - <rustc_errors[1bbd3c49342f8c7f]::diagnostic::BugAbort as rustc_errors[1bbd3c49342f8c7f]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x72d65775557c - <rustc_errors[1bbd3c49342f8c7f]::DiagCtxtHandle>::span_bug::<rustc_span[ee8b464a5d67a10a]::span_encoding::Span, alloc[32bfce7e44e7099d]::string::String>
  13:     0x72d6577ec997 - rustc_middle[8cfc63f490ebd3ee]::util::bug::opt_span_bug_fmt::<rustc_span[ee8b464a5d67a10a]::span_encoding::Span>::{closure#0}
  14:     0x72d6577c749a - rustc_middle[8cfc63f490ebd3ee]::ty::context::tls::with_opt::<rustc_middle[8cfc63f490ebd3ee]::util::bug::opt_span_bug_fmt<rustc_span[ee8b464a5d67a10a]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  15:     0x72d6577c730b - rustc_middle[8cfc63f490ebd3ee]::ty::context::tls::with_context_opt::<rustc_middle[8cfc63f490ebd3ee]::ty::context::tls::with_opt<rustc_middle[8cfc63f490ebd3ee]::util::bug::opt_span_bug_fmt<rustc_span[ee8b464a5d67a10a]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  16:     0x72d6555440e7 - rustc_middle[8cfc63f490ebd3ee]::util::bug::span_bug_fmt::<rustc_span[ee8b464a5d67a10a]::span_encoding::Span>
  17:     0x72d65993dd05 - <rustc_trait_selection[8c684b2a66bf7961]::traits::FulfillmentError as rustc_infer[10a6c158a7dd932e]::traits::engine::FromSolverError<rustc_trait_selection[8c684b2a66bf7961]::solve::fulfill::NextSolverError>>::from_solver_error
  18:     0x72d6594dbd1f - <rustc_trait_selection[8c684b2a66bf7961]::solve::fulfill::FulfillmentCtxt<rustc_trait_selection[8c684b2a66bf7961]::traits::FulfillmentError> as rustc_infer[10a6c158a7dd932e]::traits::engine::TraitEngine<rustc_trait_selection[8c684b2a66bf7961]::traits::FulfillmentError>>::select_where_possible
  19:     0x72d65993d273 - <rustc_trait_selection[8c684b2a66bf7961]::solve::fulfill::FulfillmentCtxt<rustc_trait_selection[8c684b2a66bf7961]::traits::FulfillmentError> as rustc_infer[10a6c158a7dd932e]::traits::engine::TraitEngine<rustc_trait_selection[8c684b2a66bf7961]::traits::FulfillmentError>>::select_all_or_error
  20:     0x72d65902f579 - rustc_trait_selection[8c684b2a66bf7961]::traits::coherence::overlap
  21:     0x72d6557faa95 - <rustc_middle[8cfc63f490ebd3ee]::traits::specialization_graph::Children as rustc_trait_selection[8c684b2a66bf7961]::traits::specialize::specialization_graph::ChildrenExt>::insert
  22:     0x72d6589c1073 - <rustc_middle[8cfc63f490ebd3ee]::traits::specialization_graph::Graph as rustc_trait_selection[8c684b2a66bf7961]::traits::specialize::specialization_graph::GraphExt>::insert
  23:     0x72d6589c25ed - rustc_trait_selection[8c684b2a66bf7961]::traits::specialize::specialization_graph_provider
  24:     0x72d6589c200b - rustc_query_impl[7d29f6d255d6e3b]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[7d29f6d255d6e3b]::query_impl::specialization_graph_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8cfc63f490ebd3ee]::query::erase::Erased<[u8; 8usize]>>
  25:     0x72d658ac2faf - rustc_query_system[cfa5091e76a1a105]::query::plumbing::try_execute_query::<rustc_query_impl[7d29f6d255d6e3b]::DynamicConfig<rustc_query_system[cfa5091e76a1a105]::query::caches::DefIdCache<rustc_middle[8cfc63f490ebd3ee]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[7d29f6d255d6e3b]::plumbing::QueryCtxt, false>
  26:     0x72d6590d115d - rustc_query_impl[7d29f6d255d6e3b]::query_impl::specialization_graph_of::get_query_non_incr::__rust_end_short_backtrace
  27:     0x72d6590d14d3 - rustc_hir_analysis[cb16671c9e71821a]::coherence::coherent_trait
  28:     0x72d6590d1189 - rustc_query_impl[7d29f6d255d6e3b]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[7d29f6d255d6e3b]::query_impl::coherent_trait::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8cfc63f490ebd3ee]::query::erase::Erased<[u8; 1usize]>>
  29:     0x72d658c21ade - rustc_query_system[cfa5091e76a1a105]::query::plumbing::try_execute_query::<rustc_query_impl[7d29f6d255d6e3b]::DynamicConfig<rustc_query_system[cfa5091e76a1a105]::query::caches::DefIdCache<rustc_middle[8cfc63f490ebd3ee]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[7d29f6d255d6e3b]::plumbing::QueryCtxt, false>
  30:     0x72d658c20e88 - rustc_query_impl[7d29f6d255d6e3b]::query_impl::coherent_trait::get_query_non_incr::__rust_end_short_backtrace
  31:     0x72d658ff1a36 - rustc_hir_analysis[cb16671c9e71821a]::check::wfcheck::check_well_formed
  32:     0x72d658fef92b - rustc_query_impl[7d29f6d255d6e3b]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[7d29f6d255d6e3b]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8cfc63f490ebd3ee]::query::erase::Erased<[u8; 1usize]>>
  33:     0x72d658fef1d4 - rustc_query_system[cfa5091e76a1a105]::query::plumbing::try_execute_query::<rustc_query_impl[7d29f6d255d6e3b]::DynamicConfig<rustc_data_structures[5dbc2a5ec838e218]::vec_cache::VecCache<rustc_span[ee8b464a5d67a10a]::def_id::LocalDefId, rustc_middle[8cfc63f490ebd3ee]::query::erase::Erased<[u8; 1usize]>, rustc_query_system[cfa5091e76a1a105]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[7d29f6d255d6e3b]::plumbing::QueryCtxt, false>
  34:     0x72d658feecc3 - rustc_query_impl[7d29f6d255d6e3b]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
  35:     0x72d658feb125 - rustc_hir_analysis[cb16671c9e71821a]::check::wfcheck::check_mod_type_wf
  36:     0x72d658feaf1d - rustc_query_impl[7d29f6d255d6e3b]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[7d29f6d255d6e3b]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8cfc63f490ebd3ee]::query::erase::Erased<[u8; 1usize]>>
  37:     0x72d6598d6359 - rustc_query_system[cfa5091e76a1a105]::query::plumbing::try_execute_query::<rustc_query_impl[7d29f6d255d6e3b]::DynamicConfig<rustc_query_system[cfa5091e76a1a105]::query::caches::DefaultCache<rustc_span[ee8b464a5d67a10a]::def_id::LocalModDefId, rustc_middle[8cfc63f490ebd3ee]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[7d29f6d255d6e3b]::plumbing::QueryCtxt, false>
  38:     0x72d6598d60ca - rustc_query_impl[7d29f6d255d6e3b]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
  39:     0x72d658a379e6 - rustc_hir_analysis[cb16671c9e71821a]::check_crate
  40:     0x72d658c17af2 - rustc_interface[9955e5d2c1d978e3]::passes::run_required_analyses
  41:     0x72d65937da5e - rustc_interface[9955e5d2c1d978e3]::passes::analysis
  42:     0x72d65937da33 - rustc_query_impl[7d29f6d255d6e3b]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[7d29f6d255d6e3b]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8cfc63f490ebd3ee]::query::erase::Erased<[u8; 0usize]>>
  43:     0x72d659810d7d - rustc_query_system[cfa5091e76a1a105]::query::plumbing::try_execute_query::<rustc_query_impl[7d29f6d255d6e3b]::DynamicConfig<rustc_query_system[cfa5091e76a1a105]::query::caches::SingleCache<rustc_middle[8cfc63f490ebd3ee]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[7d29f6d255d6e3b]::plumbing::QueryCtxt, false>
  44:     0x72d659810a78 - rustc_query_impl[7d29f6d255d6e3b]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  45:     0x72d659b2dffe - rustc_interface[9955e5d2c1d978e3]::passes::create_and_enter_global_ctxt::<core[75c159c8a08d6904]::option::Option<rustc_interface[9955e5d2c1d978e3]::queries::Linker>, rustc_driver_impl[5fbc7f39e785f21a]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  46:     0x72d65990ac44 - rustc_interface[9955e5d2c1d978e3]::interface::run_compiler::<(), rustc_driver_impl[5fbc7f39e785f21a]::run_compiler::{closure#0}>::{closure#1}
  47:     0x72d6596f60a8 - std[5aea8dc484e35cc6]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[9955e5d2c1d978e3]::util::run_in_thread_with_globals<rustc_interface[9955e5d2c1d978e3]::util::run_in_thread_pool_with_globals<rustc_interface[9955e5d2c1d978e3]::interface::run_compiler<(), rustc_driver_impl[5fbc7f39e785f21a]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  48:     0x72d6596f69ab - <<std[5aea8dc484e35cc6]::thread::Builder>::spawn_unchecked_<rustc_interface[9955e5d2c1d978e3]::util::run_in_thread_with_globals<rustc_interface[9955e5d2c1d978e3]::util::run_in_thread_pool_with_globals<rustc_interface[9955e5d2c1d978e3]::interface::run_compiler<(), rustc_driver_impl[5fbc7f39e785f21a]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[75c159c8a08d6904]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  49:     0x72d6596f7db7 - std::sys::pal::unix::thread::Thread::new::thread_start::habd13637cdfe3cac
  50:     0x72d65365d70a - <unknown>
  51:     0x72d6536e1aac - <unknown>
  52:                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.88.0-nightly (efb1e3d67 2025-04-16) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [specialization_graph_of] building specialization graph of trait `Foobar`
#1 [coherent_trait] coherence checking all impls of trait `Foobar`
#2 [check_well_formed] checking that `<impl at /tmp/icemaker_global_tempdir.DhVnlOQKWcDz/rustc_testrunner_tmpdir_reporting.pNj8RS2vIsUM/mvce.rs:8:1: 8:22>` is well-formed
#3 [check_mod_type_wf] checking that types are well-formed in top-level module
#4 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 7 previous errors

Some errors have detailed explanations: E0107, E0207, E0412, E0425, E0601.
For more information about an error, try `rustc --explain E0107`.

@rustbot label +F-generic_const_exprs

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.S-has-bisectionStatus: A bisection has been found for this issueS-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-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