2023-04-20 09:37:15 -05:00
|
|
|
//@run-rustfix
|
2020-10-10 05:07:47 -05:00
|
|
|
#![allow(dead_code, unused_mut)]
|
2020-10-01 20:05:30 -05:00
|
|
|
#![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();
|
|
|
|
|
2020-10-01 21:54:44 -05:00
|
|
|
let mut value = value_mutex.lock().unwrap();
|
2020-10-01 20:05:30 -05:00
|
|
|
*value += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn no_owned_mutex_lock() {
|
|
|
|
let mut value_rc = Arc::new(Mutex::new(42_u8));
|
2020-10-01 21:54:44 -05:00
|
|
|
let mut value = value_rc.lock().unwrap();
|
2020-10-01 20:05:30 -05:00
|
|
|
*value += 1;
|
|
|
|
}
|
|
|
|
|
2022-09-02 13:28:00 -05:00
|
|
|
fn issue9415() {
|
|
|
|
let mut arc_mutex = Arc::new(Mutex::new(42_u8));
|
|
|
|
let arc_mutex: &mut Arc<Mutex<u8>> = &mut arc_mutex;
|
|
|
|
let mut guard = arc_mutex.lock().unwrap();
|
|
|
|
*guard += 1;
|
|
|
|
}
|
|
|
|
|
2020-10-01 20:05:30 -05:00
|
|
|
fn main() {}
|