Skip to content

[ICE]: called Result::unwrap() on an Err value: ReferencesError(ErrorGuaranteed(())) #162391

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

#![feature(macroless_generic_const_args)]
#![feature(generic_const_args)]

enum Foo {
    A { y: NOPE },
}
const LIST: [Foo; 0] = [];
fn main() {
    match LIST {
        _ => {}
    }
}

original:

#![feature(macroless_generic_const_args)]
#![feature(generic_const_args)]
#![feature(min_generic_const_args)]
enum Foo {
    A { y: NOPE },
}
const LIST: [Foo; 0] = [];
fn main() {
    match LIST {
        _ => {}
    }
}

Version information

rustc 1.100.0-nightly (da47efd27 2026-09-06)
binary: rustc
commit-hash: da47efd27287edb02eed0b5a178a165c8f258e37
commit-date: 2026-09-06
host: x86_64-unknown-linux-gnu
release: 1.100.0-nightly
LLVM version: 23.1.1

Possibly related line of code:

imm,
tcx.layout_of(typing_env.as_query_input(cv.ty)).unwrap(),
);
op_to_const(&ecx, &imm.into(), /* for diagnostics */ false)
}
ty::Tuple(_) | ty::Array(_, _) | ty::Adt(..) => {
let layout = tcx.layout_of(typing_env.as_query_input(cv.ty)).unwrap();
if layout.is_zst() {
// Fast path to avoid some allocations.
return mir::ConstValue::ZeroSized;
}
if layout.backend_repr.is_scalar()
&& (matches!(cv.ty.kind(), ty::Tuple(_))

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

Program output

error[E0425]: cannot find type `NOPE` in this scope
 --> /tmp/icemaker_global_tempdir.hAMkwNuqtijj/rustc_testrunner_tmpdir_reporting.4ITH6h7cmD2l/mvce.rs:5:12
  |
5 |     A { y: NOPE },
  |            ^^^^ not found in this scope

error: `generic_const_args` requires `min_generic_const_args` to be enabled
 --> /tmp/icemaker_global_tempdir.hAMkwNuqtijj/rustc_testrunner_tmpdir_reporting.4ITH6h7cmD2l/mvce.rs:2:12
  |
2 | #![feature(generic_const_args)]
  |            ^^^^^^^^^^^^^^^^^^
  |
  = help: enable all of these features

error: `macroless_generic_const_args` requires `min_generic_const_args` to be enabled
 --> /tmp/icemaker_global_tempdir.hAMkwNuqtijj/rustc_testrunner_tmpdir_reporting.4ITH6h7cmD2l/mvce.rs:1:12
  |
1 | #![feature(macroless_generic_const_args)]
  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: enable all of these features

warning: the feature `macroless_generic_const_args` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /tmp/icemaker_global_tempdir.hAMkwNuqtijj/rustc_testrunner_tmpdir_reporting.4ITH6h7cmD2l/mvce.rs:1:12
  |
1 | #![feature(macroless_generic_const_args)]
  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #159006 <https://github.com/rust-lang/rust/issues/159006> for more information
  = note: `#[warn(incomplete_features)]` on by default

warning: the feature `generic_const_args` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /tmp/icemaker_global_tempdir.hAMkwNuqtijj/rustc_testrunner_tmpdir_reporting.4ITH6h7cmD2l/mvce.rs:2:12
  |
2 | #![feature(generic_const_args)]
  |            ^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #151972 <https://github.com/rust-lang/rust/issues/151972> for more information

error[E0741]: `[Foo; 0]` can't be used as a const parameter type
 --> /tmp/icemaker_global_tempdir.hAMkwNuqtijj/rustc_testrunner_tmpdir_reporting.4ITH6h7cmD2l/mvce.rs:7:13
  |
7 | const LIST: [Foo; 0] = [];
  |             ^^^^^^^^
  |
  = note: `Foo` must implement `ConstParamTy_`, but it does not


thread 'rustc' (2422236) panicked at /rustc-dev/da47efd27287edb02eed0b5a178a165c8f258e37/compiler/rustc_const_eval/src/const_eval/valtrees.rs:329:74:
called `Result::unwrap()` on an `Err` value: ReferencesError(ErrorGuaranteed(()))
stack backtrace:
   0:     0x7ffb104bde86 - <<std[7b8d936ff0591b4d]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[1338a38dbbf8640b]::fmt::Display>::fmt
   1:     0x7ffb10c0829d - core[1338a38dbbf8640b]::fmt::write
   2:     0x7ffb104d2f5c - <std[7b8d936ff0591b4d]::sys::stdio::unix::Stderr as core[1338a38dbbf8640b]::io::write::Write>::write_fmt
   3:     0x7ffb1049072a - std[7b8d936ff0591b4d]::panicking::default_hook::{closure#0}
   4:     0x7ffb104b2183 - std[7b8d936ff0591b4d]::panicking::default_hook
   5:     0x7ffb0f3fc55f - std[7b8d936ff0591b4d]::panicking::update_hook::<alloc[c8046bf86c4c1cc9]::boxed::Box<rustc_driver_impl[542a485098bab399]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7ffb104b2622 - std[7b8d936ff0591b4d]::panicking::panic_with_hook
   7:     0x7ffb104907e2 - std[7b8d936ff0591b4d]::panicking::panic_handler::{closure#0}
   8:     0x7ffb10487659 - std[7b8d936ff0591b4d]::sys::backtrace::__rust_end_short_backtrace::<std[7b8d936ff0591b4d]::panicking::panic_handler::{closure#0}, !>
   9:     0x7ffb104923bd - __rustc[e24c0e0bed34fbce]::rust_begin_unwind
  10:     0x7ffb0d1a3e8c - core[1338a38dbbf8640b]::panicking::panic_fmt
  11:     0x7ffb0c61df82 - core[1338a38dbbf8640b]::result::unwrap_failed
  12:     0x7ffb0dc928d0 - rustc_const_eval[74340a00061fdc10]::const_eval::valtrees::valtree_to_const_value
  13:     0x7ffb11f57aeb - <rustc_const_eval[74340a00061fdc10]::provide::{closure#1} as core[1338a38dbbf8640b]::ops::function::FnOnce<(rustc_middle[3307db12b2d0bcfe]::ty::context::TyCtxt, rustc_middle[3307db12b2d0bcfe]::ty::consts::valtree::Value)>>::call_once
  14:     0x7ffb11f57a9c - rustc_query_impl[a795fc8e0dec0451]::query_vtables::valtree_to_const_val::invoke_provider_fn::__rust_begin_short_backtrace
  15:     0x7ffb11f57314 - rustc_query_impl[a795fc8e0dec0451]::execution::try_execute_query::<rustc_middle[3307db12b2d0bcfe]::query::caches::DefaultCache<rustc_middle[3307db12b2d0bcfe]::ty::consts::valtree::Value, rustc_middle[3307db12b2d0bcfe]::query::erase::ErasedData<[u8; 24usize]>>, false>
  16:     0x7ffb11f5703e - rustc_query_impl[a795fc8e0dec0451]::query_vtables::valtree_to_const_val::execute_query_non_incr::__rust_end_short_backtrace
  17:     0x7ffb1182132c - <rustc_mir_transform[5ffca57c3928c519]::known_panics_lint::ConstPropagator as rustc_middle[3307db12b2d0bcfe]::mir::visit::Visitor>::visit_assign
  18:     0x7ffb11819a8e - <rustc_mir_transform[5ffca57c3928c519]::known_panics_lint::ConstPropagator as rustc_middle[3307db12b2d0bcfe]::mir::visit::Visitor>::visit_body
  19:     0x7ffb11814a6a - <rustc_mir_transform[5ffca57c3928c519]::known_panics_lint::KnownPanicsLint as rustc_mir_transform[5ffca57c3928c519]::pass_manager::MirLint>::run_lint
  20:     0x7ffb10c185ba - rustc_mir_transform[5ffca57c3928c519]::run_analysis_to_runtime_passes
  21:     0x7ffb115b4089 - rustc_mir_transform[5ffca57c3928c519]::mir_drops_elaborated_and_const_checked
  22:     0x7ffb113c7b35 - rustc_query_impl[a795fc8e0dec0451]::execution::try_execute_query::<rustc_data_structures[a20bf6f691e5a6d4]::vec_cache::VecCache<rustc_span[be290dbee5d4923]::def_id::LocalDefId, rustc_middle[3307db12b2d0bcfe]::query::erase::ErasedData<[u8; 8usize]>, rustc_middle[3307db12b2d0bcfe]::dep_graph::graph::DepNodeIndex>, false>
  23:     0x7ffb113c7667 - rustc_query_impl[a795fc8e0dec0451]::query_vtables::mir_drops_elaborated_and_const_checked::execute_query_non_incr::__rust_end_short_backtrace
  24:     0x7ffb113ca516 - <rustc_middle[3307db12b2d0bcfe]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_interface[55d539fc721ed361]::passes::run_required_analyses::{closure#2}::{closure#0}>::{closure#0}
  25:     0x7ffb113c964e - rustc_interface[55d539fc721ed361]::passes::analysis
  26:     0x7ffb11e3084a - rustc_query_impl[a795fc8e0dec0451]::execution::try_execute_query::<rustc_middle[3307db12b2d0bcfe]::query::caches::SingleCache<rustc_middle[3307db12b2d0bcfe]::query::erase::ErasedData<[u8; 0usize]>>, false>
  27:     0x7ffb11e3062b - rustc_query_impl[a795fc8e0dec0451]::query_vtables::analysis::execute_query_non_incr::__rust_end_short_backtrace
  28:     0x7ffb11f1f78c - rustc_interface[55d539fc721ed361]::interface::run_compiler::<(), rustc_driver_impl[542a485098bab399]::run_compiler::{closure#0}>::{closure#2}
  29:     0x7ffb1202f564 - std[7b8d936ff0591b4d]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[55d539fc721ed361]::util::run_in_thread_with_globals<rustc_interface[55d539fc721ed361]::util::run_in_thread_pool_with_globals<rustc_interface[55d539fc721ed361]::interface::run_compiler<(), rustc_driver_impl[542a485098bab399]::run_compiler::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  30:     0x7ffb1202f30b - <std[7b8d936ff0591b4d]::thread::lifecycle::spawn_unchecked<rustc_interface[55d539fc721ed361]::util::run_in_thread_with_globals<rustc_interface[55d539fc721ed361]::util::run_in_thread_pool_with_globals<rustc_interface[55d539fc721ed361]::interface::run_compiler<(), rustc_driver_impl[542a485098bab399]::run_compiler::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[1338a38dbbf8640b]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  31:     0x7ffb1202cd47 - <std[7b8d936ff0591b4d]::sys::thread::unix::Thread>::new::thread_start
  32:     0x7ffb0b0980a2 - <unknown>
  33:     0x7ffb0b12080c - <unknown>
  34:                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.100.0-nightly (da47efd27 2026-09-06) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [valtree_to_const_val] converting type-level constant value to MIR constant value
#1 [mir_drops_elaborated_and_const_checked] elaborating drops for `main`
#2 [analysis] running analysis passes on crate `mvce`
end of query stack
error: aborting due to 4 previous errors; 2 warnings emitted

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

@rustbot label +F-generic_const_args +F-min_generic_const_args

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.F-generic_const_args`#![feature(generic_const_args)]`F-min_generic_const_args`#![feature(min_generic_const_args)]`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.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions