rust-lang / rust-lang/rust

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

Open
#141,590 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-ICE S-bug-has-test S-has-mcve T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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

@rustbot label +F-never_patterns

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Use the supplied never_2.rs reproducer and read compiler/rustc_const_eval/src/interpret/eval_context.rs around line 553. Run rustc on the example, compare the behavior with issue #138660, and use the reported bisect range to understand the regression. Done means the reproducer no longer triggers an internal compiler error while its diagnostics remain valid.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.