rust/tests/ui/mut_mutex_lock.rs

22 lines
474 B
Rust
Raw Normal View History

2020-10-10 10:07:47 +00:00
// run-rustfix
#![allow(dead_code, unused_mut)]
2020-10-02 01:05:30 +00: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-02 02:54:44 +00:00
let mut value = value_mutex.lock().unwrap();
2020-10-02 01:05:30 +00:00
*value += 1;
}
fn no_owned_mutex_lock() {
let mut value_rc = Arc::new(Mutex::new(42_u8));
2020-10-02 02:54:44 +00:00
let mut value = value_rc.lock().unwrap();
2020-10-02 01:05:30 +00:00
*value += 1;
}
fn main() {}