mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 15:11:30 +00:00
Change lint doc test
This commit is contained in:
parent
f82f9c2c55
commit
fb8a9cb38d
3 changed files with 12 additions and 20 deletions
|
@ -21,8 +21,8 @@ declare_clippy_lint! {
|
||||||
/// let mut value_rc = Arc::new(Mutex::new(42_u8));
|
/// let mut value_rc = Arc::new(Mutex::new(42_u8));
|
||||||
/// let value_mutex = Arc::get_mut(&mut value_rc).unwrap();
|
/// let value_mutex = Arc::get_mut(&mut value_rc).unwrap();
|
||||||
///
|
///
|
||||||
/// let value = value_mutex.lock().unwrap();
|
/// let mut value = value_mutex.lock().unwrap();
|
||||||
/// do_stuff(value);
|
/// *value += 1;
|
||||||
/// ```
|
/// ```
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
@ -32,7 +32,7 @@ declare_clippy_lint! {
|
||||||
/// let value_mutex = Arc::get_mut(&mut value_rc).unwrap();
|
/// let value_mutex = Arc::get_mut(&mut value_rc).unwrap();
|
||||||
///
|
///
|
||||||
/// let value = value_mutex.get_mut().unwrap();
|
/// let value = value_mutex.get_mut().unwrap();
|
||||||
/// do_stuff(value);
|
/// *value += 1;
|
||||||
/// ```
|
/// ```
|
||||||
pub MUT_MUTEX_LOCK,
|
pub MUT_MUTEX_LOCK,
|
||||||
correctness,
|
correctness,
|
||||||
|
|
|
@ -6,13 +6,13 @@ fn mut_mutex_lock() {
|
||||||
let mut value_rc = Arc::new(Mutex::new(42_u8));
|
let mut value_rc = Arc::new(Mutex::new(42_u8));
|
||||||
let value_mutex = Arc::get_mut(&mut value_rc).unwrap();
|
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;
|
*value += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn no_owned_mutex_lock() {
|
fn no_owned_mutex_lock() {
|
||||||
let mut value_rc = Arc::new(Mutex::new(42_u8));
|
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;
|
*value += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,11 @@
|
||||||
error[E0596]: cannot borrow `value` as mutable, as it is not declared as mutable
|
error: calling `&mut Mutex::lock` unnecessarily locks an exclusive (mutable) reference
|
||||||
--> $DIR/mut_mutex_lock.rs:10:6
|
--> $DIR/mut_mutex_lock.rs:9:21
|
||||||
|
|
|
|
||||||
LL | let value = value_mutex.lock().unwrap();
|
LL | let mut 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 value = value_rc.lock().unwrap();
|
= note: `-D clippy::mut-mutex-lock` implied by `-D warnings`
|
||||||
| ----- help: consider changing this to be mutable: `mut value`
|
= help: use `&mut Mutex::get_mut` instead
|
||||||
LL | *value += 1;
|
|
||||||
| ^^^^^ cannot borrow as mutable
|
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to previous error
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0596`.
|
|
||||||
|
|
Loading…
Reference in a new issue