Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
rusty-bytes opened this issue Apr 17, 2025 · 1 comment · May be fixed by #140056
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-edition-2024 Area: The 2024 edition D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@rusty-bytes
Copy link

rusty-bytes commented Apr 17, 2025

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

@rusty-bytes rusty-bytes added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 17, 2025
@fmease fmease added D-papercut Diagnostics: An error or lint that needs small tweaks. A-edition-2024 Area: The 2024 edition labels Apr 17, 2025
@yuk1ty
Copy link
Contributor

yuk1ty commented Apr 19, 2025

@rustbot claim

@yuk1ty yuk1ty linked a pull request Apr 20, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-edition-2024 Area: The 2024 edition D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants