rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.79k stars 12.66k forks source link

ICE while inferring the type of a static LazyLock #131912

Closed V-Fries closed 1 hour ago

V-Fries commented 2 hours ago

Code

use std::sync::LazyLock;

static TEST = LazyLock::new(|| 42);

fn main() {}

Meta

rustc --version --verbose:

rustc 1.81.0 (eeb90cda1 2024-09-04)
binary: rustc
commit-hash: eeb90cda1969383f56a2637cbd3037bdf598841c
commit-date: 2024-09-04
host: x86_64-apple-darwin
release: 1.81.0
LLVM version: 18.1.7

The bug could not be reproduced in the nightly build

Error output

error: missing type for `static` item
 --> src/main.rs:3:11
  |
3 | static FOO = LazyLock::new(|| 42);
  |           ^
  |
note: however, the inferred type `LazyLock<i32, {closure@main.rs:3:28}>` cannot be named
 --> src/main.rs:3:14
  |
3 | static FOO = LazyLock::new(|| 42);
  |              ^^^^^^^^^^^^^^^^^^^^

thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/validity.rs:741:21:
assertion `left == right` failed
  left: Mut
 right: Not
Backtrace

``` 0: _rust_begin_unwind 1: core::panicking::panic_fmt 2: core::panicking::assert_failed_inner 3: core::panicking::assert_failed:: 4: rustc_const_eval::interpret::validity::mutability:: 5: as rustc_const_eval::interpret::visitor::ValueVisitor>::visit_value 6: as rustc_const_eval::interpret::visitor::ValueVisitor>::visit_field 7: as rustc_const_eval::interpret::visitor::ValueVisitor>::visit_value 8: as rustc_const_eval::interpret::visitor::ValueVisitor>::visit_field 9: as rustc_const_eval::interpret::visitor::ValueVisitor>::visit_value 10: as rustc_const_eval::interpret::visitor::ValueVisitor>::visit_field 11: as rustc_const_eval::interpret::visitor::ValueVisitor>::visit_value 12: as rustc_const_eval::interpret::visitor::ValueVisitor>::visit_field 13: as rustc_const_eval::interpret::visitor::ValueVisitor>::visit_value 14: >::validate_operand_internal 15: rustc_const_eval::const_eval::eval_queries::eval_static_initializer_provider [... omitted 2 frames ...] 16: rustc_hir_analysis::check_crate 17: rustc_interface::passes::run_required_analyses 18: rustc_interface::passes::analysis [... omitted 1 frame ...] 19: >::enter::, rustc_driver_impl::run_compiler::{closure#0}::{closu re#1}::{closure#5}> 20: rustc_interface::interface::run_compiler::, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1} ```

workingjubilee commented 1 hour ago

It does not reproduce on nightly because it is fixed.

Duplicate of https://github.com/rust-lang/rust/issues/124164