Skip to content

Regression: Fail to evaluate self-referential static slices #120949

Closed
@nvzqz

Description

@nvzqz

Code

I tried this code:

struct Value {
    values: &'static [&'static Value],
}

static VALUE: Value = Value {
    values: &[&VALUE],
};

I expected to see this happen: compile fine, with the VALUE static containing a slice that references VALUE.

Instead, this happened:

error[E0391]: cycle detected when const-evaluating + checking `VALUE`
 --> src/main.rs:6:13
  |
6 |     values: &[&VALUE],
  |             ^^^^^^^^^
  |
note: ...which requires simplifying constant for the type system `VALUE::promoted[0]`...
 --> src/main.rs:5:1
  |
5 | static VALUE: Value = Value {
  | ^^^^^^^^^^^^^^^^^^^
note: ...which requires const-evaluating + checking `VALUE::promoted[0]`...
 --> src/main.rs:5:1
  |
5 | static VALUE: Value = Value {
  | ^^^^^^^^^^^^^^^^^^^
  = note: ...which again requires const-evaluating + checking `VALUE`, completing the cycle
note: cycle used when linting top-level module
 --> src/main.rs:1:1
  |
1 | / struct Value {
2 | |     values: &'static [&'static Value],
3 | | }
4 | |
... |
8 | |
9 | | fn main() {}
  | |____________^
  = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information

Version it worked on

It most recently worked on: nightly-2024-02-10

Version with regression

nightly-2024-02-11

rustc --version --verbose:

rustc 1.78.0-nightly (6cc484351 2024-02-10)
binary: rustc
commit-hash: 6cc4843512d613f51ec81aba689180c31b0b28b6
commit-date: 2024-02-10
host: aarch64-apple-darwin
release: 1.78.0-nightly
LLVM version: 17.0.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions