Skip to content

ICE: interpret const eval failure of Unevaluated(..) which is not in required_consts #141590

Open
@cushionbadak

Description

@cushionbadak

Code

#![feature(never_patterns)]
#![allow(incomplete_features)]

use std::sync::OnceLock;

enum Void {}

static LAZY_INIT: Void = OnceLock::new();
static LAZY_INIT_REF: &[&Void] = &[&LAZY_INIT];

fn main() {}

A mutant of tests/ui/consts/static-promoted-to-mutable-static.rs

Meta

rustc --version --verbose:

rustc 1.89.0-nightly (283db70ac 2025-05-25)
binary: rustc
commit-hash: 283db70ace62a0ae704a624e43b68c2ee44b87a6
commit-date: 2025-05-25
host: aarch64-apple-darwin
release: 1.89.0-nightly
LLVM version: 20.1.5

Error output

command: rustc

warning: static of uninhabited type
 --> never_2.rs:8:1
  |
8 | static LAZY_INIT: Void = OnceLock::new();
  | ^^^^^^^^^^^^^^^^^^^^^^
  |
  = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
  = note: for more information, see issue #74840 <https://github.com/rust-lang/rust/issues/74840>
  = note: uninhabited statics cannot be initialized, and any access would be an immediate error
  = note: `#[warn(uninhabited_static)]` on by default

error[E0308]: mismatched types
 --> never_2.rs:8:26
  |
8 | static LAZY_INIT: Void = OnceLock::new();
  |                          ^^^^^^^^^^^^^^^ expected `Void`, found `OnceLock<_>`
  |
  = note: expected enum `Void`
           found struct `OnceLock<_>`

error[E0080]: it is undefined behavior to use this value
 --> never_2.rs:9:1
  |
9 | static LAZY_INIT_REF: &[&Void] = &[&LAZY_INIT];
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered a reference pointing to uninhabited type Void
  |
  = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
  = note: the raw bytes of the constant (size: 8, align: 8) {
              ╾─────alloc4<imm>─────╼                         │ ╾──────╼
          }

error: internal compiler error: compiler/rustc_const_eval/src/interpret/eval_context.rs:553:33: interpret const eval failure of Unevaluated(UnevaluatedConst { def: DefId(0:6 ~ never_2[57e3]::LAZY_INIT_REF), args: [], promoted: Some(promoted[0]) }, &'{erased} [&'{erased} Void; 1_usize]) which is not in required_consts
 --> never_2.rs:9:34
  |
9 | static LAZY_INIT_REF: &[&Void] = &[&LAZY_INIT];
  |                                  ^^^^^^^^^^^^^


thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/eval_context.rs:553:33:
Box<dyn Any>
Backtrace

thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/eval_context.rs:553:33:
Box<dyn Any>
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: <rustc_errors::diagnostic::BugAbort as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
   2: <rustc_errors::DiagCtxtHandle>::span_bug::<rustc_span::span_encoding::Span, alloc::string::String>
   3: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0}
   4: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}
   5: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_opt<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
   6: rustc_middle::util::bug::span_bug_fmt::<rustc_span::span_encoding::Span>
   7: <rustc_const_eval::interpret::eval_context::InterpCx<rustc_const_eval::const_eval::machine::CompileTimeMachine>>::eval_operand
   8: <rustc_const_eval::interpret::eval_context::InterpCx<rustc_const_eval::const_eval::machine::CompileTimeMachine>>::eval_rvalue_into_place
   9: <rustc_const_eval::interpret::eval_context::InterpCx<rustc_const_eval::const_eval::machine::CompileTimeMachine>>::eval_statement
  10: rustc_const_eval::const_eval::eval_queries::eval_static_initializer_provider
      [... omitted 1 frame ...]
  11: <rustc_middle::ty::context::TyCtxt>::par_hir_body_owners::<rustc_hir_analysis::check_crate::{closure#1}>::{closure#0}
  12: rustc_hir_analysis::check_crate
  13: rustc_interface::passes::run_required_analyses
  14: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  15: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>
  16: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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: please attach the file at `/Users/jisukbyun/workspace/250203 scratch/rustc-ice-2025-05-26T14_07_15-75713.txt` to your bug report

query stack during panic:
#0 [eval_static_initializer] evaluating initializer of static `LAZY_INIT_REF`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 3 previous errors; 1 warning emitted

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

Bisects to

tool version: cargo-bisect-rustc 0.6.9
command: cargo-bisect-rustc --start=2023-05-01 --end=2024-05-01 --regress ice --preserve --script rustc -- never_2.rs

********************************************************************************
Regression in nightly-2024-04-25
********************************************************************************

fetching https://static.rust-lang.org/dist/2024-04-24/channel-rust-nightly-git-commit-hash.txt
nightly manifest 2024-04-24: 40 B / 40 B [=======================================================] 100.00 % 798.19 KB/s converted 2024-04-24 to 244da22fabd9fa677bbd0ac601a88e5ca6917526
fetching https://static.rust-lang.org/dist/2024-04-25/channel-rust-nightly-git-commit-hash.txt
nightly manifest 2024-04-25: 40 B / 40 B [=======================================================] 100.00 % 713.35 KB/s converted 2024-04-25 to ef8b9dcf23700f2e2265317611460d3a65c19eff
looking for regression commit between 2024-04-24 and 2024-04-25
fetching (via remote github) commits from max(244da22fabd9fa677bbd0ac601a88e5ca6917526, 2024-04-22) to ef8b9dcf23700f2e2265317611460d3a65c19eff
ending github query because we found starting sha: 244da22fabd9fa677bbd0ac601a88e5ca6917526
get_commits_between returning commits, len: 9
  commit[0] 2024-04-23: Auto merge of #123126 - oli-obk:feed_crate_num, r=davidtwco
  commit[1] 2024-04-23: Auto merge of #121557 - RalfJung:const-fn-call-promotion, r=oli-obk
  commit[2] 2024-04-24: Auto merge of #124312 - weihanglo:update-cargo, r=weihanglo
  commit[3] 2024-04-24: Auto merge of #122053 - erikdesjardins:alloca, r=nikic
  commit[4] 2024-04-24: Auto merge of #124175 - Kobzol:ci-dynamic-job, r=pietroalbini
  commit[5] 2024-04-24: Auto merge of #123792 - oli-obk:coroutine_closures, r=compiler-errors
  commit[6] 2024-04-24: Auto merge of #122500 - petrochenkov:deleg, r=fmease
  commit[7] 2024-04-24: Auto merge of #104087 - nbdd0121:const, r=scottmcm
  commit[8] 2024-04-24: Auto merge of #124330 - fmease:rollup-a98y7jf, r=fmease
ERROR: no CI builds available between 244da22fabd9fa677bbd0ac601a88e5ca6917526 and ef8b9dcf23700f2e2265317611460d3a65c19eff within last 167 days

Notes

  • ICE location: compiler/rustc_const_eval/src/interpret/eval_context.rs Line-553

    pub fn eval_mir_constant(
    &self,
    val: &mir::Const<'tcx>,
    span: Span,
    layout: Option<TyAndLayout<'tcx>>,
    ) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>> {
    M::eval_mir_constant(self, *val, span, layout, |ecx, val, span, layout| {
    let const_val = val.eval(*ecx.tcx, ecx.typing_env, span).map_err(|err| {
    if M::ALL_CONSTS_ARE_PRECHECKED {
    match err {
    ErrorHandled::TooGeneric(..) => {},
    ErrorHandled::Reported(reported, span) => {
    if reported.is_allowed_in_infallible() {
    // These errors can just sometimes happen, even when the expression
    // is nominally "infallible", e.g. when running out of memory
    // or when some layout could not be computed.
    } else {
    // Looks like the const is not captured by `required_consts`, that's bad.
    span_bug!(span, "interpret const eval failure of {val:?} which is not in required_consts");
    }
    }

  • Issue-138660 has the same ICE location & also regression in 2024-04-25, but has different query stack and it does not use the never_patterns feature. I'm not sure if this report is a duplicated one.

@rustbot label +F-never_patterns

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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions