Skip to content

Static cyclic references not compiled in current nightly rust version #62189

Closed
@chabapok

Description

@chabapok

Let's tying to compile this code.This code compiled ok on stable and on nightly-2019-06-17 (for example at rust play site)

struct Foo {
    foo: Option<&'static Foo>
}

static FOO: Foo = Foo {
    foo: Some(&FOO),
};

fn main() {
    println!("Hello, world!");
}

But in current rustc 1.37.0-nightly (d3e2cec 2019-06-26) compilation fails with message:

error[E0391]: cycle detected when const-evaluating `FOO`
 --> src/main.rs:6:1
  |
6 | static FOO: Foo = Foo {
  | ^^^^^^^^^^^^^^^^^^^^^
  |
note: ...which requires const-evaluating `FOO`...
 --> src/main.rs:6:1
  |
6 | static FOO: Foo = Foo {
  | ^^^^^^^^^^^^^^^^^^^^^
  = note: ...which again requires const-evaluating `FOO`, completing the cycle
note: cycle used when const-evaluating + checking `FOO`
 --> src/main.rs:6:1
  |
6 | static FOO: Foo = Foo {
  | ^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0391`.

Metadata

Metadata

Assignees

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-betaPerformance or correctness regression from stable to beta.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions