Skip to content

Wrong error when trying to write to static in a static initializer #51251

Closed
@oli-obk

Description

@oli-obk

http://play.rust-lang.org/?gist=d719594f15f35f8be13987e2f722d1ab&version=nightly&mode=debug

#![feature(const_let)]

static mut FOO: usize = unsafe {
    FOO = 42;
    5
};

fn main() {
}

results in

error[E0658]: statements in statics are unstable (see issue #48821)
 --> src/main.rs:4:5
  |
4 |     FOO = 42;
  |     ^^^^^^^^
  |
  = help: add #![feature(const_let)] to the crate attributes to enable

even though the feature gate is active (it should still error, but with a more targeted error message)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions