Skip to content

Access to mutable static within items inside unsafe blocks leads to poor user experience #35716

Closed
@DanielShaulov

Description

@DanielShaulov

The following produces an error about needing an unsafe block while already being in an unsafe block. It should produce an error about not being able to use a static value in another static.

struct A{
    x: u32
}

fn main() {
    unsafe {
        static mut NUM: u32 = 7;
        static a: A = A {
            x: NUM
        };
    }
}

https://is.gd/OgeJ7e

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.D-papercutDiagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions