Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICE: ConstArgHasWrongType failed but we don't know how to compute type #135361

Open
matthiaskrgr opened this issue Jan 11, 2025 · 3 comments · May be fixed by #135380
Open

ICE: ConstArgHasWrongType failed but we don't know how to compute type #135361

matthiaskrgr opened this issue Jan 11, 2025 · 3 comments · May be fixed by #135380
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

auto-reduced (treereduce-rust):

trait If<const generic_const_exprs: bool> {}
impl If<true> 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<true> for () {}

trait IsZero<const N: usize> {}

impl<const N: 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.86.0-nightly (7e4077d06 2025-01-11)
binary: rustc
commit-hash: 7e4077d06fc073442c567d58885b47ed2c5121b8
commit-date: 2025-01-11
host: x86_64-unknown-linux-gnu
release: 1.86.0-nightly
LLVM version: 19.1.6

Possibly related line of code:

ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, expected_ty)) => {
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),
_ => span_bug!(
obligation.cause.span,
"ConstArgHasWrongType failed but we don't know how to compute type"
),
};
FulfillmentErrorCode::Select(SelectionError::ConstArgHasWrongType {
ct,

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

Program output

error[E0412]: cannot find type `N` in this scope
 --> /tmp/icemaker_global_tempdir.Clgh7OT0H3Q5/rustc_testrunner_tmpdir_reporting.8bDVhjbOqSrL/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.Clgh7OT0H3Q5/rustc_testrunner_tmpdir_reporting.8bDVhjbOqSrL/mvce.rs:8:25
  |
8 | impl Foobar<N> for () {}
  |                         ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.Clgh7OT0H3Q5/rustc_testrunner_tmpdir_reporting.8bDVhjbOqSrL/mvce.rs`

error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied
 --> /tmp/icemaker_global_tempdir.Clgh7OT0H3Q5/rustc_testrunner_tmpdir_reporting.8bDVhjbOqSrL/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.Clgh7OT0H3Q5/rustc_testrunner_tmpdir_reporting.8bDVhjbOqSrL/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.Clgh7OT0H3Q5/rustc_testrunner_tmpdir_reporting.8bDVhjbOqSrL/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.Clgh7OT0H3Q5/rustc_testrunner_tmpdir_reporting.8bDVhjbOqSrL/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.Clgh7OT0H3Q5/rustc_testrunner_tmpdir_reporting.8bDVhjbOqSrL/mvce.rs:4:7
  |
4 | trait Foobar {}
  |       ^^^^^^

error: internal compiler error: compiler/rustc_trait_selection/src/solve/fulfill.rs:267:22: ConstArgHasWrongType failed but we don't know how to compute type


thread 'rustc' panicked at compiler/rustc_trait_selection/src/solve/fulfill.rs:267:22:
Box<dyn Any>
stack backtrace:
   0:     0x75e2d90f5b9a - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h6ad413a9c5d92132
   1:     0x75e2d9812d66 - core::fmt::write::hd9d1731ab47c0ca7
   2:     0x75e2da777e91 - std::io::Write::write_fmt::h7f0b3d462e354385
   3:     0x75e2d90f59f2 - std::sys::backtrace::BacktraceLock::print::h2b918afb2877943f
   4:     0x75e2d90f7f97 - std::panicking::default_hook::{{closure}}::h6129e8f978485814
   5:     0x75e2d90f7d80 - std::panicking::default_hook::h03e9c5e42fe92791
   6:     0x75e2d825df38 - std[33acbbc1924c4cd6]::panicking::update_hook::<alloc[893ed522702f9859]::boxed::Box<rustc_driver_impl[f9fe3354fe2fd435]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x75e2d90f87e3 - std::panicking::rust_panic_with_hook::h9ba2b54837e008ba
   8:     0x75e2d8296d81 - std[33acbbc1924c4cd6]::panicking::begin_panic::<rustc_errors[2805a1dbbffdc483]::ExplicitBug>::{closure#0}
   9:     0x75e2d828bc86 - std[33acbbc1924c4cd6]::sys::backtrace::__rust_end_short_backtrace::<std[33acbbc1924c4cd6]::panicking::begin_panic<rustc_errors[2805a1dbbffdc483]::ExplicitBug>::{closure#0}, !>
  10:     0x75e2d8288799 - std[33acbbc1924c4cd6]::panicking::begin_panic::<rustc_errors[2805a1dbbffdc483]::ExplicitBug>
  11:     0x75e2d82a0cc1 - <rustc_errors[2805a1dbbffdc483]::diagnostic::BugAbort as rustc_errors[2805a1dbbffdc483]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x75e2d87f780c - <rustc_errors[2805a1dbbffdc483]::DiagCtxtHandle>::span_bug::<rustc_span[475c1a9bb47d94c0]::span_encoding::Span, alloc[893ed522702f9859]::string::String>
  13:     0x75e2d887ceb7 - rustc_middle[ff83cc293d1a3dd6]::util::bug::opt_span_bug_fmt::<rustc_span[475c1a9bb47d94c0]::span_encoding::Span>::{closure#0}
  14:     0x75e2d8861eba - rustc_middle[ff83cc293d1a3dd6]::ty::context::tls::with_opt::<rustc_middle[ff83cc293d1a3dd6]::util::bug::opt_span_bug_fmt<rustc_span[475c1a9bb47d94c0]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  15:     0x75e2d8861d4b - rustc_middle[ff83cc293d1a3dd6]::ty::context::tls::with_context_opt::<rustc_middle[ff83cc293d1a3dd6]::ty::context::tls::with_opt<rustc_middle[ff83cc293d1a3dd6]::util::bug::opt_span_bug_fmt<rustc_span[475c1a9bb47d94c0]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  16:     0x75e2d72a50f7 - rustc_middle[ff83cc293d1a3dd6]::util::bug::span_bug_fmt::<rustc_span[475c1a9bb47d94c0]::span_encoding::Span>
  17:     0x75e2da7e08e2 - <rustc_trait_selection[a9962fce8e4fbdac]::traits::FulfillmentError as rustc_infer[4d6832c29a414c7]::traits::engine::FromSolverError<rustc_trait_selection[a9962fce8e4fbdac]::solve::fulfill::NextSolverError>>::from_solver_error
  18:     0x75e2da5478a3 - <rustc_trait_selection[a9962fce8e4fbdac]::solve::fulfill::FulfillmentCtxt<rustc_trait_selection[a9962fce8e4fbdac]::traits::FulfillmentError> as rustc_infer[4d6832c29a414c7]::traits::engine::TraitEngine<rustc_trait_selection[a9962fce8e4fbdac]::traits::FulfillmentError>>::select_where_possible
  19:     0x75e2da7dfdb3 - <rustc_trait_selection[a9962fce8e4fbdac]::solve::fulfill::FulfillmentCtxt<rustc_trait_selection[a9962fce8e4fbdac]::traits::FulfillmentError> as rustc_infer[4d6832c29a414c7]::traits::engine::TraitEngine<rustc_trait_selection[a9962fce8e4fbdac]::traits::FulfillmentError>>::select_all_or_error
  20:     0x75e2da542977 - rustc_trait_selection[a9962fce8e4fbdac]::traits::coherence::overlap
  21:     0x75e2d981a5bd - <rustc_middle[ff83cc293d1a3dd6]::traits::specialization_graph::Children as rustc_trait_selection[a9962fce8e4fbdac]::traits::specialize::specialization_graph::ChildrenExt>::insert
  22:     0x75e2da69565b - <rustc_middle[ff83cc293d1a3dd6]::traits::specialization_graph::Graph as rustc_trait_selection[a9962fce8e4fbdac]::traits::specialize::specialization_graph::GraphExt>::insert
  23:     0x75e2d9a3af33 - rustc_trait_selection[a9962fce8e4fbdac]::traits::specialize::specialization_graph_provider
  24:     0x75e2d9a3a955 - rustc_query_impl[85545818dc61c388]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[85545818dc61c388]::query_impl::specialization_graph_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ff83cc293d1a3dd6]::query::erase::Erased<[u8; 8usize]>>
  25:     0x75e2d9b119df - rustc_query_system[861d73d81f5ebaeb]::query::plumbing::try_execute_query::<rustc_query_impl[85545818dc61c388]::DynamicConfig<rustc_query_system[861d73d81f5ebaeb]::query::caches::DefIdCache<rustc_middle[ff83cc293d1a3dd6]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[85545818dc61c388]::plumbing::QueryCtxt, false>
  26:     0x75e2da45cb81 - rustc_query_impl[85545818dc61c388]::query_impl::specialization_graph_of::get_query_non_incr::__rust_end_short_backtrace
  27:     0x75e2d9e55165 - rustc_hir_analysis[b4134b0e1e97b436]::coherence::coherent_trait
  28:     0x75e2d9e54ecf - rustc_query_impl[85545818dc61c388]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[85545818dc61c388]::query_impl::coherent_trait::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ff83cc293d1a3dd6]::query::erase::Erased<[u8; 1usize]>>
  29:     0x75e2d9bf3830 - rustc_query_system[861d73d81f5ebaeb]::query::plumbing::try_execute_query::<rustc_query_impl[85545818dc61c388]::DynamicConfig<rustc_query_system[861d73d81f5ebaeb]::query::caches::DefIdCache<rustc_middle[ff83cc293d1a3dd6]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[85545818dc61c388]::plumbing::QueryCtxt, false>
  30:     0x75e2d9bf2862 - rustc_query_impl[85545818dc61c388]::query_impl::coherent_trait::get_query_non_incr::__rust_end_short_backtrace
  31:     0x75e2d9e95e8c - rustc_middle[ff83cc293d1a3dd6]::query::plumbing::query_ensure_error_guaranteed::<rustc_query_system[861d73d81f5ebaeb]::query::caches::DefIdCache<rustc_middle[ff83cc293d1a3dd6]::query::erase::Erased<[u8; 1usize]>>, ()>
  32:     0x75e2d9ea1f2c - rustc_hir_analysis[b4134b0e1e97b436]::check::wfcheck::check_well_formed
  33:     0x75e2d9ea16a3 - rustc_query_impl[85545818dc61c388]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[85545818dc61c388]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ff83cc293d1a3dd6]::query::erase::Erased<[u8; 1usize]>>
  34:     0x75e2d9ea1145 - rustc_query_system[861d73d81f5ebaeb]::query::plumbing::try_execute_query::<rustc_query_impl[85545818dc61c388]::DynamicConfig<rustc_data_structures[6294f6aa86e67250]::vec_cache::VecCache<rustc_span[475c1a9bb47d94c0]::def_id::LocalDefId, rustc_middle[ff83cc293d1a3dd6]::query::erase::Erased<[u8; 1usize]>, rustc_query_system[861d73d81f5ebaeb]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[85545818dc61c388]::plumbing::QueryCtxt, false>
  35:     0x75e2d9ea0bc1 - rustc_query_impl[85545818dc61c388]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
  36:     0x75e2d9e9dfec - rustc_hir_analysis[b4134b0e1e97b436]::check::wfcheck::check_mod_type_wf
  37:     0x75e2d9e9de0b - rustc_query_impl[85545818dc61c388]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[85545818dc61c388]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ff83cc293d1a3dd6]::query::erase::Erased<[u8; 1usize]>>
  38:     0x75e2da7b9e88 - rustc_query_system[861d73d81f5ebaeb]::query::plumbing::try_execute_query::<rustc_query_impl[85545818dc61c388]::DynamicConfig<rustc_query_system[861d73d81f5ebaeb]::query::caches::DefaultCache<rustc_span[475c1a9bb47d94c0]::def_id::LocalModDefId, rustc_middle[ff83cc293d1a3dd6]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[85545818dc61c388]::plumbing::QueryCtxt, false>
  39:     0x75e2da7b9c30 - rustc_query_impl[85545818dc61c388]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
  40:     0x75e2d99ff338 - rustc_hir_analysis[b4134b0e1e97b436]::check_crate
  41:     0x75e2d9bec3e8 - rustc_interface[3ef31e66eb8873de]::passes::run_required_analyses
  42:     0x75e2da77bd1e - rustc_interface[3ef31e66eb8873de]::passes::analysis
  43:     0x75e2da77bcef - rustc_query_impl[85545818dc61c388]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[85545818dc61c388]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ff83cc293d1a3dd6]::query::erase::Erased<[u8; 0usize]>>
  44:     0x75e2da7d8955 - rustc_query_system[861d73d81f5ebaeb]::query::plumbing::try_execute_query::<rustc_query_impl[85545818dc61c388]::DynamicConfig<rustc_query_system[861d73d81f5ebaeb]::query::caches::SingleCache<rustc_middle[ff83cc293d1a3dd6]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[85545818dc61c388]::plumbing::QueryCtxt, false>
  45:     0x75e2da7d868e - rustc_query_impl[85545818dc61c388]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  46:     0x75e2da82355e - rustc_interface[3ef31e66eb8873de]::passes::create_and_enter_global_ctxt::<core[6cf442861785187b]::option::Option<rustc_interface[3ef31e66eb8873de]::queries::Linker>, rustc_driver_impl[f9fe3354fe2fd435]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  47:     0x75e2da79eba4 - rustc_interface[3ef31e66eb8873de]::interface::run_compiler::<(), rustc_driver_impl[f9fe3354fe2fd435]::run_compiler::{closure#0}>::{closure#1}
  48:     0x75e2da6908d1 - std[33acbbc1924c4cd6]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[3ef31e66eb8873de]::util::run_in_thread_with_globals<rustc_interface[3ef31e66eb8873de]::util::run_in_thread_pool_with_globals<rustc_interface[3ef31e66eb8873de]::interface::run_compiler<(), rustc_driver_impl[f9fe3354fe2fd435]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  49:     0x75e2da690d84 - <<std[33acbbc1924c4cd6]::thread::Builder>::spawn_unchecked_<rustc_interface[3ef31e66eb8873de]::util::run_in_thread_with_globals<rustc_interface[3ef31e66eb8873de]::util::run_in_thread_pool_with_globals<rustc_interface[3ef31e66eb8873de]::interface::run_compiler<(), rustc_driver_impl[f9fe3354fe2fd435]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[6cf442861785187b]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  50:     0x75e2da692341 - std::sys::pal::unix::thread::Thread::new::thread_start::h8bb747bec67b46a6
  51:     0x75e2d4aa339d - <unknown>
  52:     0x75e2d4b2849c - <unknown>
  53:                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.86.0-nightly (7e4077d06 2025-01-11) 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.Clgh7OT0H3Q5/rustc_testrunner_tmpdir_reporting.8bDVhjbOqSrL/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 6 previous errors

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

@matthiaskrgr matthiaskrgr added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 11, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 11, 2025
@matthiaskrgr
Copy link
Member Author

bisection points to #134771

@matthiaskrgr
Copy link
Member Author

matthiaskrgr commented Jan 11, 2025

trait A<const B: bool> {}
impl A<true> for () {}
trait C {}
impl<const D: u8> C for () where (): A<D> {}
impl C for () {}

pub fn main() {}

@cyrgani

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants