Skip to content

[ICE]: next solver: missing generic: called 'Result::unwrap_err()' on an 'Ok' value: {const error} #159703

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

//@compile-flags: -Znext-solver=globally
trait Foo {}
struct BarType<const N: usize>;
impl<const N: usize> Foo for BarType {}

fn a(x: &Foo) {
    let bar = BarType;
    a(bar);
}

original:

trait Foo {}
struct BarType<const N: usize>;
impl<const N: usize> Foo for BarType {} // expected 1 generic argument

fn a(x: &Foo) {
    let bar = BarType;
    a(bar);
}

fn main() {}

Version information

rustc 1.99.0-nightly (b9ee8d8bc 2026-07-21)
binary: rustc
commit-hash: b9ee8d8bcb1e4c7905a183a37e6d984c4b9a8468
commit-date: 2026-07-21
host: x86_64-unknown-linux-gnu
release: 1.99.0-nightly
LLVM version: 22.1.8

Possibly related line of code:

return c;
}
match c.kind() {
ty::ConstKind::Infer(ty::InferConst::Var(vid)) => {
let vid = self.infcx.root_const_var(vid);
let universe = self.infcx.try_resolve_const_var(vid).unwrap_err();
if self.for_universe.can_name(universe) {
c
} else {
let origin = self.infcx.const_var_origin(vid).unwrap();
let new_var_id = self
.infcx

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Znext-solver=globally

Program output

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

error[E0107]: missing generics for struct `BarType`
 --> /tmp/icemaker_global_tempdir.Jl1slngaS2Bx/rustc_testrunner_tmpdir_reporting.3T320K0DEjES/mvce.rs:3:30
  |
3 | impl<const N: usize> Foo for BarType {}
  |                              ^^^^^^^ expected 1 generic argument
  |
note: struct defined here, with 1 generic parameter: `N`
 --> /tmp/icemaker_global_tempdir.Jl1slngaS2Bx/rustc_testrunner_tmpdir_reporting.3T320K0DEjES/mvce.rs:2:8
  |
2 | struct BarType<const N: usize>;
  |        ^^^^^^^ --------------
help: add missing generic argument
  |
3 | impl<const N: usize> Foo for BarType<N> {}
  |                                     +++

warning: trait objects without an explicit `dyn` are deprecated
 --> /tmp/icemaker_global_tempdir.Jl1slngaS2Bx/rustc_testrunner_tmpdir_reporting.3T320K0DEjES/mvce.rs:5:10
  |
5 | fn a(x: &Foo) {
  |          ^^^
  |
  = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
  = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2021/warnings-promoted-to-error.html>
  = note: `#[warn(bare_trait_objects)]` (part of `#[warn(rust_2021_compatibility)]`) on by default
help: if this is a dyn-compatible trait, use `dyn`
  |
5 | fn a(x: &dyn Foo) {
  |          +++


thread 'rustc' (1053593) panicked at /rustc-dev/b9ee8d8bcb1e4c7905a183a37e6d984c4b9a8468/compiler/rustc_infer/src/infer/context.rs:524:70:
called `Result::unwrap_err()` on an `Ok` value: {const error}
stack backtrace:
   0:     0x7f0c64e29516 - <<std[e7e31dd881df98bb]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[c88a0a802f7ea8d1]::fmt::Display>::fmt
   1:     0x7f0c6540d912 - core[c88a0a802f7ea8d1]::fmt::write
   2:     0x7f0c64e3e66c - <std[e7e31dd881df98bb]::sys::stdio::unix::Stderr as core[c88a0a802f7ea8d1]::io::write::Write>::write_fmt
   3:     0x7f0c64dfb14a - std[e7e31dd881df98bb]::panicking::default_hook::{closure#0}
   4:     0x7f0c64e1bbb3 - std[e7e31dd881df98bb]::panicking::default_hook
   5:     0x7f0c63da090b - std[e7e31dd881df98bb]::panicking::update_hook::<alloc[ec3dd5f39d329b4e]::boxed::Box<rustc_driver_impl[383cde084ff42635]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7f0c64e1c052 - std[e7e31dd881df98bb]::panicking::panic_with_hook
   7:     0x7f0c64dfb202 - std[e7e31dd881df98bb]::panicking::panic_handler::{closure#0}
   8:     0x7f0c64df2df9 - std[e7e31dd881df98bb]::sys::backtrace::__rust_end_short_backtrace::<std[e7e31dd881df98bb]::panicking::panic_handler::{closure#0}, !>
   9:     0x7f0c64dfcb5d - __rustc[db4185f8d0a68659]::rust_begin_unwind
  10:     0x7f0c6198dd0c - core[c88a0a802f7ea8d1]::panicking::panic_fmt
  11:     0x7f0c613a2de2 - core[c88a0a802f7ea8d1]::result::unwrap_failed
  12:     0x7f0c6673f745 - <rustc_infer[268a96dbfa1d9cb9]::infer::context::LowerUniverseFolder as rustc_type_ir[3f031e8ec3f876a6]::fold::TypeFolder<rustc_middle[c436af0429e6724f]::ty::context::TyCtxt>>::fold_const
  13:     0x7f0c659d20f0 - <&rustc_middle[c436af0429e6724f]::ty::list::RawList<(), rustc_middle[c436af0429e6724f]::ty::generic_args::GenericArg> as rustc_type_ir[3f031e8ec3f876a6]::fold::TypeFoldable<rustc_middle[c436af0429e6724f]::ty::context::TyCtxt>>::fold_with::<rustc_infer[268a96dbfa1d9cb9]::infer::context::LowerUniverseFolder>
  14:     0x7f0c659d242d - <rustc_middle[c436af0429e6724f]::ty::Ty as rustc_type_ir[3f031e8ec3f876a6]::fold::TypeSuperFoldable<rustc_middle[c436af0429e6724f]::ty::context::TyCtxt>>::super_fold_with::<rustc_infer[268a96dbfa1d9cb9]::infer::context::LowerUniverseFolder>
  15:     0x7f0c659cee15 - <rustc_infer[268a96dbfa1d9cb9]::infer::context::LowerUniverseFolder as rustc_type_ir[3f031e8ec3f876a6]::fold::TypeFolder<rustc_middle[c436af0429e6724f]::ty::context::TyCtxt>>::fold_ty
  16:     0x7f0c659cea66 - <rustc_infer[268a96dbfa1d9cb9]::infer::InferCtxt as rustc_type_ir[3f031e8ec3f876a6]::infer_ctxt::InferCtxtLike>::instantiate_ty_var_raw
  17:     0x7f0c659cf48c - <rustc_next_trait_solver[80bb1502c5d2ca88]::canonical::ResponseRelating<rustc_infer[268a96dbfa1d9cb9]::infer::InferCtxt, rustc_middle[c436af0429e6724f]::ty::context::TyCtxt> as rustc_type_ir[3f031e8ec3f876a6]::relate::TypeRelation<rustc_middle[c436af0429e6724f]::ty::context::TyCtxt>>::tys
  18:     0x7f0c659cf250 - rustc_next_trait_solver[80bb1502c5d2ca88]::canonical::unify_query_var_values::<rustc_trait_selection[ea9d61c240fbd158]::solve::delegate::SolverDelegate, rustc_middle[c436af0429e6724f]::ty::context::TyCtxt>
  19:     0x7f0c663194f5 - <rustc_trait_selection[ea9d61c240fbd158]::solve::inspect::analyse::InspectCandidate>::instantiate_nested_goals
  20:     0x7f0c65db0031 - <rustc_trait_selection[ea9d61c240fbd158]::solve::inspect::analyse::InspectCandidate>::visit_nested_no_probe::<rustc_hir_typeck[f17462d0efe89a72]::coercion::CoerceVisitor>
  21:     0x7f0c65dad0e0 - <rustc_hir_typeck[f17462d0efe89a72]::coercion::CoerceVisitor as rustc_trait_selection[ea9d61c240fbd158]::solve::inspect::analyse::ProofTreeVisitor>::visit_goal
  22:     0x7f0c6630c4e0 - <rustc_hir_typeck[f17462d0efe89a72]::coercion::Coerce>::coerce
  23:     0x7f0c640bba1a - <rustc_hir_typeck[f17462d0efe89a72]::fn_ctxt::FnCtxt>::may_coerce
  24:     0x7f0c6409037c - <rustc_hir_typeck[f17462d0efe89a72]::fn_ctxt::FnCtxt>::suggest_deref_or_ref
  25:     0x7f0c64094bb7 - <rustc_hir_typeck[f17462d0efe89a72]::fn_ctxt::FnCtxt>::suggest_deref_ref_or_into
  26:     0x7f0c6408849d - <rustc_hir_typeck[f17462d0efe89a72]::fn_ctxt::FnCtxt>::emit_type_mismatch_suggestions
  27:     0x7f0c64083a92 - <rustc_hir_typeck[f17462d0efe89a72]::fn_ctxt::FnCtxt>::emit_coerce_suggestions
  28:     0x7f0c640b27b4 - <rustc_hir_typeck[f17462d0efe89a72]::fn_ctxt::FnCtxt>::report_arg_errors
  29:     0x7f0c656534db - <rustc_hir_typeck[f17462d0efe89a72]::fn_ctxt::FnCtxt>::check_expr_call
  30:     0x7f0c656113fc - <rustc_hir_typeck[f17462d0efe89a72]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  31:     0x7f0c65606d6b - <rustc_hir_typeck[f17462d0efe89a72]::fn_ctxt::FnCtxt>::check_expr_block
  32:     0x7f0c656113d8 - <rustc_hir_typeck[f17462d0efe89a72]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  33:     0x7f0c6562b8f5 - rustc_hir_typeck[f17462d0efe89a72]::check::check_fn
  34:     0x7f0c666df19f - rustc_hir_typeck[f17462d0efe89a72]::typeck_with_inspect::{closure#0}
  35:     0x7f0c666dd8b0 - rustc_query_impl[9a9b2dbab4aa42cf]::query_impl::typeck_root::invoke_provider_fn::__rust_begin_short_backtrace
  36:     0x7f0c65ab4629 - rustc_query_impl[9a9b2dbab4aa42cf]::execution::try_execute_query::<rustc_data_structures[b573e1ebd6629dca]::vec_cache::VecCache<rustc_span[5e0315be33f6440b]::def_id::LocalDefId, rustc_middle[c436af0429e6724f]::query::erase::ErasedData<[u8; 8usize]>, rustc_middle[c436af0429e6724f]::dep_graph::graph::DepNodeIndex>, false>
  37:     0x7f0c65ab4083 - rustc_query_impl[9a9b2dbab4aa42cf]::query_impl::typeck_root::execute_query_non_incr::__rust_end_short_backtrace
  38:     0x7f0c65ab6f7e - rustc_hir_analysis[18680bb4726cf8e]::check_crate
  39:     0x7f0c65ab0a4b - rustc_interface[1cdecb41dc13d5b0]::passes::analysis
  40:     0x7f0c6662c9c7 - rustc_query_impl[9a9b2dbab4aa42cf]::execution::try_execute_query::<rustc_middle[c436af0429e6724f]::query::caches::SingleCache<rustc_middle[c436af0429e6724f]::query::erase::ErasedData<[u8; 0usize]>>, false>
  41:     0x7f0c6662c6a9 - rustc_query_impl[9a9b2dbab4aa42cf]::query_impl::analysis::execute_query_non_incr::__rust_end_short_backtrace
  42:     0x7f0c66602ecd - rustc_interface[1cdecb41dc13d5b0]::interface::run_compiler::<(), rustc_driver_impl[383cde084ff42635]::run_compiler::{closure#0}>::{closure#2}
  43:     0x7f0c6663a8a4 - std[e7e31dd881df98bb]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[1cdecb41dc13d5b0]::util::run_in_thread_with_globals<rustc_interface[1cdecb41dc13d5b0]::util::run_in_thread_pool_with_globals<rustc_interface[1cdecb41dc13d5b0]::interface::run_compiler<(), rustc_driver_impl[383cde084ff42635]::run_compiler::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  44:     0x7f0c6663a673 - <std[e7e31dd881df98bb]::thread::lifecycle::spawn_unchecked<rustc_interface[1cdecb41dc13d5b0]::util::run_in_thread_with_globals<rustc_interface[1cdecb41dc13d5b0]::util::run_in_thread_pool_with_globals<rustc_interface[1cdecb41dc13d5b0]::interface::run_compiler<(), rustc_driver_impl[383cde084ff42635]::run_compiler::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[c88a0a802f7ea8d1]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  45:     0x7f0c6664547a - <std[e7e31dd881df98bb]::sys::thread::unix::Thread>::new::thread_start
  46:     0x7f0c5fc97739 - <unknown>
  47:     0x7f0c5fd1bedc - <unknown>
  48:                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.99.0-nightly (b9ee8d8bc 2026-07-21) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z next-solver=globally -Z dump-mir-dir=dir

query stack during panic:
#0 [typeck_root] type-checking `a`
#1 [analysis] running analysis passes on crate `mvce`
end of query stack
error: aborting due to 2 previous errors; 1 warning emitted

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

@rustbot label +WG-trait-system-refactor

Metadata

Metadata

Assignees

No one assigned

    Labels

    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.WG-trait-system-refactorThe Rustc Trait System Refactor Initiative (-Znext-solver)needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions