Skip to content

ICE: impossible case reached: can't relate: UnevaluatedConst #137260

Open
@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

#![feature(generic_const_exprs)]
trait Iter<const FN: fn() = { || {} }> {}

fn needs_iter<'a, T: Iter<'a, I> + ?Sized, I: 'a>(_: &T) {}

fn test(x: &dyn Iter<'_, ()>) {
    needs_iter(x);
}

original:

//@ compile-flags: -Znext-solver
//@ check-pass

trait Iter<const FN: fn() = { || {} }>: Iterator<Item = &'a I> {}

fn needs_iter<'a, T: Iter<'a, I> + ?Sized, I: 'a>(_: &T) {}

fn test(x: &dyn Iter<'_, ()>) {
    needs_iter(x);
}

fn main() {}

Version information

rustc 1.87.0-nightly (17c1c329a 2025-02-19)
binary: rustc
commit-hash: 17c1c329a5512d718b67ef6797538b154016cd34
commit-date: 2025-02-19
host: x86_64-unknown-linux-gnu
release: 1.87.0-nightly
LLVM version: 20.1.0

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zcrate-attr=feature(generic_const_exprs)

Program output

warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
 --> <crate attribute>:1:9
  |
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

error[E0601]: `main` function not found in crate `mvce`
 --> /tmp/icemaker_global_tempdir.ffNkrQVFC034/rustc_testrunner_tmpdir_reporting.XReiXIhsphr5/mvce.rs:7:2
  |
7 | }
  |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.ffNkrQVFC034/rustc_testrunner_tmpdir_reporting.XReiXIhsphr5/mvce.rs`

error: using function pointers as const generic parameters is forbidden
 --> /tmp/icemaker_global_tempdir.ffNkrQVFC034/rustc_testrunner_tmpdir_reporting.XReiXIhsphr5/mvce.rs:1:22
  |
1 | trait Iter<const FN: fn() = { || {} }> {}
  |                      ^^^^
  |
  = note: the only supported types are integers, `bool`, and `char`

error[E0107]: trait takes 0 lifetime arguments but 1 lifetime argument was supplied
 --> /tmp/icemaker_global_tempdir.ffNkrQVFC034/rustc_testrunner_tmpdir_reporting.XReiXIhsphr5/mvce.rs:3:22
  |
3 | fn needs_iter<'a, T: Iter<'a, I> + ?Sized, I: 'a>(_: &T) {}
  |                      ^^^^ -- help: remove the lifetime argument
  |                      |
  |                      expected 0 lifetime arguments
  |
note: trait defined here, with 0 lifetime parameters
 --> /tmp/icemaker_global_tempdir.ffNkrQVFC034/rustc_testrunner_tmpdir_reporting.XReiXIhsphr5/mvce.rs:1:7
  |
1 | trait Iter<const FN: fn() = { || {} }> {}
  |       ^^^^

error: overly complex generic constant
 --> /tmp/icemaker_global_tempdir.ffNkrQVFC034/rustc_testrunner_tmpdir_reporting.XReiXIhsphr5/mvce.rs:1:29
  |
1 | trait Iter<const FN: fn() = { || {} }> {}
  |                             ^^-----^^
  |                               |
  |                               pointer casts are not allowed in generic constants
  |
  = help: consider moving this anonymous constant into a `const` function

error[E0107]: trait takes 0 lifetime arguments but 1 lifetime argument was supplied
 --> /tmp/icemaker_global_tempdir.ffNkrQVFC034/rustc_testrunner_tmpdir_reporting.XReiXIhsphr5/mvce.rs:5:17
  |
5 | fn test(x: &dyn Iter<'_, ()>) {
  |                 ^^^^ -- help: remove the lifetime argument
  |                 |
  |                 expected 0 lifetime arguments
  |
note: trait defined here, with 0 lifetime parameters
 --> /tmp/icemaker_global_tempdir.ffNkrQVFC034/rustc_testrunner_tmpdir_reporting.XReiXIhsphr5/mvce.rs:1:7
  |
1 | trait Iter<const FN: fn() = { || {} }> {}
  |       ^^^^

error[E0393]: the type parameter `FN` must be explicitly specified
 --> /tmp/icemaker_global_tempdir.ffNkrQVFC034/rustc_testrunner_tmpdir_reporting.XReiXIhsphr5/mvce.rs:5:17
  |
1 | trait Iter<const FN: fn() = { || {} }> {}
  | -------------------------------------- type parameter `FN` must be specified for this
...
5 | fn test(x: &dyn Iter<'_, ()>) {
  |                 ^^^^^^^^^^^^ missing reference to `FN`
  |
  = note: because the parameter default references `Self`, the parameter must be specified on the object type

error: internal compiler error: /rustc/17c1c329a5512d718b67ef6797538b154016cd34/compiler/rustc_middle/src/ty/relate.rs:189:18: impossible case reached: can't relate: UnevaluatedConst { def: DefId(0:5 ~ mvce[6cd1]::Iter::{constant#0}), args: [dyn [Binder { value: Trait(Iter<{type error}>), bound_vars: [] }] + '?3] } with {type error}


thread 'rustc' panicked at /rustc/17c1c329a5512d718b67ef6797538b154016cd34/compiler/rustc_middle/src/ty/relate.rs:189:18:
Box<dyn Any>
stack backtrace:
   0:     0x78000fd93754 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h058e0db08db4e308
   1:     0x78001041a2ac - core::fmt::write::h2896c353be594058
   2:     0x780011385a51 - std::io::Write::write_fmt::hb6d7e57799357016
   3:     0x78000fd935b2 - std::sys::backtrace::BacktraceLock::print::hf0f361819cf671ee
   4:     0x78000fd95dbe - std::panicking::default_hook::{{closure}}::ha203bbe1c0eab45f
   5:     0x78000fd95994 - std::panicking::default_hook::h241a0f75f184c349
   6:     0x78000eee2c77 - std[e8f7047bf536a035]::panicking::update_hook::<alloc[f5c9241a34fc739f]::boxed::Box<rustc_driver_impl[9b799b2b9a90c5eb]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x78000fd96633 - std::panicking::rust_panic_with_hook::h05db98a78b8e5ccb
   8:     0x78000ef1e321 - std[e8f7047bf536a035]::panicking::begin_panic::<rustc_errors[c739bb8b16ec05ea]::ExplicitBug>::{closure#0}
   9:     0x78000ef12736 - std[e8f7047bf536a035]::sys::backtrace::__rust_end_short_backtrace::<std[e8f7047bf536a035]::panicking::begin_panic<rustc_errors[c739bb8b16ec05ea]::ExplicitBug>::{closure#0}, !>
  10:     0x78000ef12513 - std[e8f7047bf536a035]::panicking::begin_panic::<rustc_errors[c739bb8b16ec05ea]::ExplicitBug>
  11:     0x78000ef27ca1 - <rustc_errors[c739bb8b16ec05ea]::diagnostic::BugAbort as rustc_errors[c739bb8b16ec05ea]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x78000f4f7906 - rustc_middle[85d9e04ee4b4f524]::util::bug::opt_span_bug_fmt::<rustc_span[c6f95d766fcdd5b1]::span_encoding::Span>::{closure#0}
  13:     0x78000f4e0b7a - rustc_middle[85d9e04ee4b4f524]::ty::context::tls::with_opt::<rustc_middle[85d9e04ee4b4f524]::util::bug::opt_span_bug_fmt<rustc_span[c6f95d766fcdd5b1]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x78000f4e0a0b - rustc_middle[85d9e04ee4b4f524]::ty::context::tls::with_context_opt::<rustc_middle[85d9e04ee4b4f524]::ty::context::tls::with_opt<rustc_middle[85d9e04ee4b4f524]::util::bug::opt_span_bug_fmt<rustc_span[c6f95d766fcdd5b1]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x78000db333c0 - rustc_middle[85d9e04ee4b4f524]::util::bug::bug_fmt
  16:     0x7800105bc812 - <rustc_infer[19c2b605c1a9a127]::infer::at::At>::eq_trace::<rustc_type_ir[c72b4e181bbac7a3]::predicate::TraitRef<rustc_middle[85d9e04ee4b4f524]::ty::context::TyCtxt>>
  17:     0x78000d15e2c5 - <rustc_trait_selection[5a6c0c637d1e74d2]::traits::select::SelectionContext>::match_normalize_trait_ref
  18:     0x78000d12e13f - <rustc_trait_selection[5a6c0c637d1e74d2]::traits::select::SelectionContext>::candidate_from_obligation::{closure#0}::{closure#0}
  19:     0x78000cd60446 - <rustc_trait_selection[5a6c0c637d1e74d2]::traits::select::SelectionContext>::poly_select::{closure#0}
  20:     0x780010da98e7 - <rustc_trait_selection[5a6c0c637d1e74d2]::traits::fulfill::FulfillProcessor as rustc_data_structures[f70c9a795d99fea2]::obligation_forest::ObligationProcessor>::process_obligation
  21:     0x78001040f13f - <rustc_data_structures[f70c9a795d99fea2]::obligation_forest::ObligationForest<rustc_trait_selection[5a6c0c637d1e74d2]::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection[5a6c0c637d1e74d2]::traits::fulfill::FulfillProcessor>
  22:     0x78001059c12d - <rustc_hir_typeck[6b1c2ee04c45e7a8]::fn_ctxt::FnCtxt>::confirm_builtin_call
  23:     0x780011016863 - <rustc_hir_typeck[6b1c2ee04c45e7a8]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  24:     0x78001100f94b - <rustc_hir_typeck[6b1c2ee04c45e7a8]::fn_ctxt::FnCtxt>::check_expr_block
  25:     0x78001101750f - <rustc_hir_typeck[6b1c2ee04c45e7a8]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  26:     0x7800106e85a0 - rustc_hir_typeck[6b1c2ee04c45e7a8]::check::check_fn
  27:     0x7800106f12bf - rustc_hir_typeck[6b1c2ee04c45e7a8]::typeck_with_inspect::{closure#0}
  28:     0x7800106ef388 - rustc_query_impl[86fa617db73557a2]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[86fa617db73557a2]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[85d9e04ee4b4f524]::query::erase::Erased<[u8; 8usize]>>
  29:     0x7800107c6b8c - rustc_query_system[b2c9516ca03027bf]::query::plumbing::try_execute_query::<rustc_query_impl[86fa617db73557a2]::DynamicConfig<rustc_data_structures[f70c9a795d99fea2]::vec_cache::VecCache<rustc_span[c6f95d766fcdd5b1]::def_id::LocalDefId, rustc_middle[85d9e04ee4b4f524]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[b2c9516ca03027bf]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[86fa617db73557a2]::plumbing::QueryCtxt, false>
  30:     0x7800107c565c - rustc_query_impl[86fa617db73557a2]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  31:     0x7800107c52ff - <rustc_middle[85d9e04ee4b4f524]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_hir_analysis[de8b4722af89528a]::check_crate::{closure#3}>::{closure#0}
  32:     0x7800107c4979 - rustc_hir_analysis[de8b4722af89528a]::check_crate
  33:     0x7800107ce75c - rustc_interface[d30adf414c41a3da]::passes::run_required_analyses
  34:     0x7800113819fa - rustc_interface[d30adf414c41a3da]::passes::analysis
  35:     0x7800113819d9 - rustc_query_impl[86fa617db73557a2]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[86fa617db73557a2]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[85d9e04ee4b4f524]::query::erase::Erased<[u8; 0usize]>>
  36:     0x78001140c483 - rustc_query_system[b2c9516ca03027bf]::query::plumbing::try_execute_query::<rustc_query_impl[86fa617db73557a2]::DynamicConfig<rustc_query_system[b2c9516ca03027bf]::query::caches::SingleCache<rustc_middle[85d9e04ee4b4f524]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[86fa617db73557a2]::plumbing::QueryCtxt, false>
  37:     0x78001140c153 - rustc_query_impl[86fa617db73557a2]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  38:     0x78001149117c - rustc_interface[d30adf414c41a3da]::passes::create_and_enter_global_ctxt::<core[f14dc92e3f316e7]::option::Option<rustc_interface[d30adf414c41a3da]::queries::Linker>, rustc_driver_impl[9b799b2b9a90c5eb]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  39:     0x780011484a6b - rustc_interface[d30adf414c41a3da]::interface::run_compiler::<(), rustc_driver_impl[9b799b2b9a90c5eb]::run_compiler::{closure#0}>::{closure#1}
  40:     0x780011309c48 - std[e8f7047bf536a035]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[d30adf414c41a3da]::util::run_in_thread_with_globals<rustc_interface[d30adf414c41a3da]::util::run_in_thread_pool_with_globals<rustc_interface[d30adf414c41a3da]::interface::run_compiler<(), rustc_driver_impl[9b799b2b9a90c5eb]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  41:     0x78001130a074 - <<std[e8f7047bf536a035]::thread::Builder>::spawn_unchecked_<rustc_interface[d30adf414c41a3da]::util::run_in_thread_with_globals<rustc_interface[d30adf414c41a3da]::util::run_in_thread_pool_with_globals<rustc_interface[d30adf414c41a3da]::interface::run_compiler<(), rustc_driver_impl[9b799b2b9a90c5eb]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[f14dc92e3f316e7]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  42:     0x78001130aa2f - std::sys::pal::unix::thread::Thread::new::thread_start::had6426447ba59d7e
  43:     0x78000b6a370a - <unknown>
  44:     0x78000b727aac - <unknown>
  45:                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.87.0-nightly (17c1c329a 2025-02-19) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z crate-attr=feature(generic_const_exprs) -Z dump-mir-dir=dir

query stack during panic:
#0 [typeck] type-checking `test`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 7 previous errors; 1 warning emitted

Some errors have detailed explanations: E0107, E0393, 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.F-generic_const_exprs`#![feature(generic_const_exprs)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-lowLow priorityS-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.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