mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-12-01 00:49:30 +00:00
c88cb08afc
When there is are multiple references where one of the references isn't mutable then this results in a false-positive for `mut_mutex_lock` as it only checks the mutability of the first reference level. Fix this by using `peel_mid_ty_refs_is_mutable` which correctly determines whether the reference is ultimately mutable and thus whether `Mutex::get_lock()` can actually be used. Fixes #9854
17 lines
727 B
Text
17 lines
727 B
Text
error: calling `&mut Mutex::lock` unnecessarily locks an exclusive (mutable) reference
|
|
--> tests/ui/mut_mutex_lock.rs:10:33
|
|
|
|
|
LL | let mut value = value_mutex.lock().unwrap();
|
|
| ^^^^ help: change this to: `get_mut`
|
|
|
|
|
= note: `-D clippy::mut-mutex-lock` implied by `-D warnings`
|
|
= help: to override `-D warnings` add `#[allow(clippy::mut_mutex_lock)]`
|
|
|
|
error: calling `&mut Mutex::lock` unnecessarily locks an exclusive (mutable) reference
|
|
--> tests/ui/mut_mutex_lock.rs:15:43
|
|
|
|
|
LL | let mut value = mut_ref_mut_ref_mutex.lock().unwrap();
|
|
| ^^^^ help: change this to: `get_mut`
|
|
|
|
error: aborting due to 2 previous errors
|
|
|