-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
978a2ca
commit 18bc948
Showing
4 changed files
with
36 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// run-rustfix | ||
#![allow(dead_code, unused_mut)] | ||
#![warn(clippy::mut_mutex_lock)] | ||
|
||
use std::sync::{Arc, Mutex}; | ||
|
||
fn mut_mutex_lock() { | ||
let mut value_rc = Arc::new(Mutex::new(42_u8)); | ||
let value_mutex = Arc::get_mut(&mut value_rc).unwrap(); | ||
|
||
let mut value = value_mutex.get_mut().unwrap(); | ||
*value += 1; | ||
} | ||
|
||
fn no_owned_mutex_lock() { | ||
let mut value_rc = Arc::new(Mutex::new(42_u8)); | ||
let mut value = value_rc.lock().unwrap(); | ||
*value += 1; | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// run-rustfix | ||
#![allow(dead_code, unused_mut)] | ||
#![warn(clippy::mut_mutex_lock)] | ||
|
||
use std::sync::{Arc, Mutex}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
error: calling `&mut Mutex::lock` unnecessarily locks an exclusive (mutable) reference | ||
--> $DIR/mut_mutex_lock.rs:9:21 | ||
--> $DIR/mut_mutex_lock.rs:11: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: use `&mut Mutex::get_mut` instead | ||
|
||
error: aborting due to previous error | ||
|