Code
use std::sync::Mutex;
fn main() {
let m = Mutex::new(0);
m.lock().unwrap();
}
Current output
warning: unused `std::sync::MutexGuard` that must be used
--> src/main.rs:6:5
|
6 | m.lock().unwrap();
| ^^^^^^^^^^^^^^^^^
|
= note: if unused the Mutex will immediately unlock
= note: `#[warn(unused_must_use)]` (part of `#[warn(unused)]`) on by default
help: use `let _ = ...` to ignore the resulting value
|
6 | let _ = m.lock().unwrap();
| +++++++
Desired output
warning: unused `std::sync::MutexGuard` that must be used
--> src/main.rs:6:5
|
6 | m.lock().unwrap();
| ^^^^^^^^^^^^^^^^^
|
= note: if unused the Mutex will immediately unlock
= note: `#[warn(unused_must_use)]` (part of `#[warn(unused)]`) on by default
help: use `let _guard = ...` to ignore the resulting value while keeping the Mutex locked
|
6 | let _guard = m.lock().unwrap();
| ++++++++++++
Rationale and extra context
The suggestion we provide causes another lint to trigger:
error: non-binding let on a synchronization lock
--> src/main.rs:6:9
|
6 | let _ = m.lock().unwrap();
| ^ this lock is not assigned to a binding and is immediately dropped
|
= note: `#[deny(let_underscore_lock)]` (part of `#[deny(let_underscore)]`) on by default
help: consider binding to an unused variable to avoid immediately dropping the value
|
6 | let _unused = m.lock().unwrap();
| ++++++
help: consider immediately dropping the value
|
6 - let _ = m.lock().unwrap();
6 + drop(m.lock().unwrap());
|
That's a bad user experience.
Other cases
Rust Version
Anything else?
Cc @kpreid
Code
Current output
Desired output
Rationale and extra context
The suggestion we provide causes another lint to trigger:
That's a bad user experience.
Other cases
Rust Version
Anything else?
Cc @kpreid