Skip to content

const Mutex<T> never makes sense, and therefore should raise a warning (or an error) #104031

Closed
@Trolldemorted

Description

@Trolldemorted

Given the following code:

use std::sync::Mutex;
const FOO: Mutex<u64> = Mutex::new(0);

fn main() {
    {
        let foo = &FOO;
        let a: &mut u64 = &mut foo.lock().unwrap();
        *a = 1;
    }
    println!("{:?}", &FOO);
}

The current output is:

   Compiling playground v0.0.1 (/playground)
    Finished dev [unoptimized + debuginfo] target(s) in 0.86s
     Running `target/debug/playground`
Mutex { data: 0, poisoned: false, .. }

The const expression causes every site to have their own Mutex<T>, which never makes any sense. Imho this should raise a warning, or even an error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-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