Skip to content

In edition 2024 error message "error: creating a shared reference to mutable static is discouraged" is wrong #139952

@rusty-bytes

Description

@rusty-bytes

Code

static mut COUNTER: u32 = 0;

unsafe fn add_to_count(inc: u32) {
    unsafe {
        COUNTER += inc;
    }
}

fn main() {
    unsafe {
        add_to_count(3);
        println!("COUNTER: {}", COUNTER);
    }
}

Current output

error: creating a shared reference to mutable static is discouraged

Desired output

error: creating a shared reference to mutable static is not allowed

Rationale and extra context

Edition 2021 warning "warning: creating a shared reference to mutable static is discouraged" has become edition 2024 error "error: creating a shared reference to mutable static is discouraged", which is wrong.
That behaviour is no longer discouraged but it is now not allowed.

Other cases

Rust Version

rustc 1.86.0, edition 2024.

Anything else?

No response

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-edition-2024Area: The 2024 editionD-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