Skip to content

[ICE]: enum variant discr was too generic to eval #158797

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

#![feature(const_async_blocks)]

enum Foo {
    Bar = (|| yield, 2).1,
}

original:

#![feature(coroutines)]
#![feature(const_async_blocks)]
#![feature(yield_expr)]
enum Foo {
    Bar = (
        #[coroutine]
        || yield,
        2,
    )
        .1,
}

fn main() {}

Version information

rustc 1.98.0-nightly (ea088e0a3 2026-07-05)
binary: rustc
commit-hash: ea088e0a3dd50c494b4589c3c121d7469dceec8f
commit-date: 2026-07-05
host: x86_64-unknown-linux-gnu
release: 1.98.0-nightly
LLVM version: 22.1.8

Possibly related line of code:

// Explicit `enum` discriminant values must const-evaluate successfully.
if let ty::VariantDiscr::Explicit(discr_def_id) = variant.discr {
match tcx.const_eval_poly(discr_def_id) {
Ok(_) => {}
Err(ErrorHandled::Reported(..)) => {}
Err(ErrorHandled::TooGeneric(sp)) => {
span_bug!(sp, "enum variant discr was too generic to eval")
}
}
}
}
check_where_clauses(wfcx, item);

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

Program output

error[E0658]: yield syntax is experimental
 --> /tmp/icemaker_global_tempdir.ptA2QDVmn15G/rustc_testrunner_tmpdir_reporting.L6CW6WUYm6Fw/mvce.rs:4:15
  |
4 |     Bar = (|| yield, 2).1,
  |               ^^^^^
  |
  = note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information
  = help: add `#![feature(yield_expr)]` to the crate attributes to enable
  = note: this compiler was built on 2026-07-05; consider upgrading it if it is out of date

error[E0658]: yield syntax is experimental
 --> /tmp/icemaker_global_tempdir.ptA2QDVmn15G/rustc_testrunner_tmpdir_reporting.L6CW6WUYm6Fw/mvce.rs:4:15
  |
4 |     Bar = (|| yield, 2).1,
  |               ^^^^^
  |
  = note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information
  = help: add `#![feature(yield_expr)]` to the crate attributes to enable
  = note: this compiler was built on 2026-07-05; consider upgrading it if it is out of date

error: `yield` can only be used in `#[coroutine]` closures, or `gen` blocks
 --> /tmp/icemaker_global_tempdir.ptA2QDVmn15G/rustc_testrunner_tmpdir_reporting.L6CW6WUYm6Fw/mvce.rs:4:15
  |
4 |     Bar = (|| yield, 2).1,
  |               ^^^^^
  |
help: use `#[coroutine]` to make this closure a coroutine
  |
4 |     Bar = (#[coroutine] || yield, 2).1,
  |            ++++++++++++

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

error: internal compiler error: /rustc-dev/ea088e0a3dd50c494b4589c3c121d7469dceec8f/compiler/rustc_hir_analysis/src/check/wfcheck.rs:1138:25: enum variant discr was too generic to eval


thread 'rustc' (2036952) panicked at /rustc-dev/ea088e0a3dd50c494b4589c3c121d7469dceec8f/compiler/rustc_hir_analysis/src/check/wfcheck.rs:1138:25:
Box<dyn Any>
stack backtrace:
   0:     0x7fce060e5ea6 - <<std[1023ab8fe43ea5ab]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[ac254214b649f1de]::fmt::Display>::fmt
   1:     0x7fce0680ecc8 - core[ac254214b649f1de]::fmt::write
   2:     0x7fce060fb28c - <std[1023ab8fe43ea5ab]::sys::stdio::unix::Stderr as std[1023ab8fe43ea5ab]::io::Write>::write_fmt
   3:     0x7fce060ba30a - std[1023ab8fe43ea5ab]::panicking::default_hook::{closure#0}
   4:     0x7fce060d85f3 - std[1023ab8fe43ea5ab]::panicking::default_hook
   5:     0x7fce050c45b8 - std[1023ab8fe43ea5ab]::panicking::update_hook::<alloc[e3e2338491c50a85]::boxed::Box<rustc_driver_impl[cdfcb04387bfb2d]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7fce060d8a92 - std[1023ab8fe43ea5ab]::panicking::panic_with_hook
   7:     0x7fce050f20e1 - std[1023ab8fe43ea5ab]::panicking::begin_panic::<rustc_errors[d242d9a7579ddf78]::ExplicitBug>::{closure#0}
   8:     0x7fce050eae56 - std[1023ab8fe43ea5ab]::sys::backtrace::__rust_end_short_backtrace::<std[1023ab8fe43ea5ab]::panicking::begin_panic<rustc_errors[d242d9a7579ddf78]::ExplicitBug>::{closure#0}, !>
   9:     0x7fce050e8e97 - std[1023ab8fe43ea5ab]::panicking::begin_panic::<rustc_errors[d242d9a7579ddf78]::ExplicitBug>
  10:     0x7fce050fd271 - <rustc_errors[d242d9a7579ddf78]::diagnostic::BugAbort as rustc_errors[d242d9a7579ddf78]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  11:     0x7fce05649cdc - <rustc_errors[d242d9a7579ddf78]::DiagCtxtHandle>::span_bug::<rustc_span[1809dac9b9f9f1f9]::span_encoding::Span, alloc[e3e2338491c50a85]::string::String>
  12:     0x7fce056787f6 - rustc_middle[65e93962a5a43da7]::util::bug::opt_span_bug_fmt::<rustc_span[1809dac9b9f9f1f9]::span_encoding::Span>::{closure#0}
  13:     0x7fce05678982 - rustc_middle[65e93962a5a43da7]::ty::context::tls::with_opt::<rustc_middle[65e93962a5a43da7]::util::bug::opt_span_bug_fmt<rustc_span[1809dac9b9f9f1f9]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x7fce056640cb - rustc_middle[65e93962a5a43da7]::ty::context::tls::with_context_opt::<rustc_middle[65e93962a5a43da7]::ty::context::tls::with_opt<rustc_middle[65e93962a5a43da7]::util::bug::opt_span_bug_fmt<rustc_span[1809dac9b9f9f1f9]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x7fce030d0a68 - rustc_middle[65e93962a5a43da7]::util::bug::span_bug_fmt::<rustc_span[1809dac9b9f9f1f9]::span_encoding::Span>
  16:     0x7fce070cbff7 - rustc_hir_analysis[6a1607dc5c50ec45]::check::wfcheck::check_type_defn
  17:     0x7fce076b7164 - rustc_hir_analysis[6a1607dc5c50ec45]::check::check::check_item_type
  18:     0x7fce076b03b0 - rustc_hir_analysis[6a1607dc5c50ec45]::check::wfcheck::check_well_formed
  19:     0x7fce076b0391 - rustc_query_impl[e6cc49fff9d6167b]::query_impl::check_well_formed::invoke_provider_fn::__rust_begin_short_backtrace
  20:     0x7fce076af971 - rustc_query_impl[e6cc49fff9d6167b]::execution::try_execute_query::<rustc_data_structures[1a2aab4d02078da7]::vec_cache::VecCache<rustc_span[1809dac9b9f9f1f9]::def_id::LocalDefId, rustc_middle[65e93962a5a43da7]::query::erase::ErasedData<[u8; 1usize]>, rustc_middle[65e93962a5a43da7]::dep_graph::graph::DepNodeIndex>, false>
  21:     0x7fce076af707 - rustc_query_impl[e6cc49fff9d6167b]::query_impl::check_well_formed::execute_query_non_incr::__rust_end_short_backtrace
  22:     0x7fce076ac185 - rustc_hir_analysis[6a1607dc5c50ec45]::check::wfcheck::check_type_wf
  23:     0x7fce076ac093 - rustc_query_impl[e6cc49fff9d6167b]::query_impl::check_type_wf::invoke_provider_fn::__rust_begin_short_backtrace
  24:     0x7fce07985186 - rustc_query_impl[e6cc49fff9d6167b]::execution::try_execute_query::<rustc_middle[65e93962a5a43da7]::query::caches::SingleCache<rustc_middle[65e93962a5a43da7]::query::erase::ErasedData<[u8; 1usize]>>, false>
  25:     0x7fce07984f69 - rustc_query_impl[e6cc49fff9d6167b]::query_impl::check_type_wf::execute_query_non_incr::__rust_end_short_backtrace
  26:     0x7fce06bd6b9a - rustc_hir_analysis[6a1607dc5c50ec45]::check_crate
  27:     0x7fce06bdb1ba - rustc_interface[a6d30ce4ed30ee91]::passes::analysis
  28:     0x7fce07983707 - rustc_query_impl[e6cc49fff9d6167b]::execution::try_execute_query::<rustc_middle[65e93962a5a43da7]::query::caches::SingleCache<rustc_middle[65e93962a5a43da7]::query::erase::ErasedData<[u8; 0usize]>>, false>
  29:     0x7fce07983369 - rustc_query_impl[e6cc49fff9d6167b]::query_impl::analysis::execute_query_non_incr::__rust_end_short_backtrace
  30:     0x7fce07959e40 - rustc_interface[a6d30ce4ed30ee91]::interface::run_compiler::<(), rustc_driver_impl[cdfcb04387bfb2d]::run_compiler::{closure#0}>::{closure#1}
  31:     0x7fce0799227a - std[1023ab8fe43ea5ab]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[a6d30ce4ed30ee91]::util::run_in_thread_with_globals<rustc_interface[a6d30ce4ed30ee91]::util::run_in_thread_pool_with_globals<rustc_interface[a6d30ce4ed30ee91]::interface::run_compiler<(), rustc_driver_impl[cdfcb04387bfb2d]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  32:     0x7fce0799202d - <std[1023ab8fe43ea5ab]::thread::lifecycle::spawn_unchecked<rustc_interface[a6d30ce4ed30ee91]::util::run_in_thread_with_globals<rustc_interface[a6d30ce4ed30ee91]::util::run_in_thread_pool_with_globals<rustc_interface[a6d30ce4ed30ee91]::interface::run_compiler<(), rustc_driver_impl[cdfcb04387bfb2d]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[ac254214b649f1de]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  33:     0x7fce07996450 - <std[1023ab8fe43ea5ab]::sys::thread::unix::Thread>::new::thread_start
  34:     0x7fce012981b9 - <unknown>
  35:     0x7fce0131d21c - <unknown>
  36:                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.98.0-nightly (ea088e0a3 2026-07-05) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [check_well_formed] checking that `Foo` 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
error: aborting due to 5 previous errors

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

@rustbot label +F-coroutines +F-const_async_blocks +F-yield_expr

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-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

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions