Change lint doc test

This commit is contained in:
Francis Murillo 2020-10-02 10:54:44 +08:00
parent f82f9c2c55
commit fb8a9cb38d
3 changed files with 12 additions and 20 deletions

View file

@ -21,8 +21,8 @@ declare_clippy_lint! {
/// let mut value_rc = Arc::new(Mutex::new(42_u8));
/// let value_mutex = Arc::get_mut(&mut value_rc).unwrap();
///
/// let value = value_mutex.lock().unwrap();
/// do_stuff(value);
/// let mut value = value_mutex.lock().unwrap();
/// *value += 1;
/// ```
/// Use instead:
/// ```rust
@ -32,7 +32,7 @@ declare_clippy_lint! {
/// let value_mutex = Arc::get_mut(&mut value_rc).unwrap();
///
/// let value = value_mutex.get_mut().unwrap();
/// do_stuff(value);
/// *value += 1;
/// ```
pub MUT_MUTEX_LOCK,
correctness,

View file

@ -6,13 +6,13 @@ 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 value = value_mutex.lock().unwrap();
let mut value = value_mutex.lock().unwrap();
*value += 1;
}
fn no_owned_mutex_lock() {
let mut value_rc = Arc::new(Mutex::new(42_u8));
let value = value_rc.lock().unwrap();
let mut value = value_rc.lock().unwrap();
*value += 1;
}

View file

@ -1,19 +1,11 @@
error[E0596]: cannot borrow `value` as mutable, as it is not declared as mutable
--> $DIR/mut_mutex_lock.rs:10:6
error: calling `&mut Mutex::lock` unnecessarily locks an exclusive (mutable) reference
--> $DIR/mut_mutex_lock.rs:9:21
|
LL | let value = value_mutex.lock().unwrap();
| ----- help: consider changing this to be mutable: `mut value`
LL | *value += 1;
| ^^^^^ cannot borrow as mutable
error[E0596]: cannot borrow `value` as mutable, as it is not declared as mutable
--> $DIR/mut_mutex_lock.rs:16:6
LL | let mut value = value_mutex.lock().unwrap();
| ^^^^^^^^^^^^^^^^^^
|
LL | let value = value_rc.lock().unwrap();
| ----- help: consider changing this to be mutable: `mut value`
LL | *value += 1;
| ^^^^^ cannot borrow as mutable
= note: `-D clippy::mut-mutex-lock` implied by `-D warnings`
= help: use `&mut Mutex::get_mut` instead
error: aborting due to 2 previous errors
error: aborting due to previous error
For more information about this error, try `rustc --explain E0596`.