about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFrancis Murillo <francis.murillo@protonmail.com>2020-10-02 10:54:44 +0800
committerFrancis Murillo <francis.murillo@protonmail.com>2020-10-25 17:41:24 +0800
commitfb8a9cb38d73f3876b57f250502895c7cc60d421 (patch)
tree73e1f9e9e8fc6308ed332d3b1023dcaac3a2a00e
parentf82f9c2c55392ef9d7649bf2e485f7e509fd0038 (diff)
downloadrust-fb8a9cb38d73f3876b57f250502895c7cc60d421.tar.gz
rust-fb8a9cb38d73f3876b57f250502895c7cc60d421.zip
Change lint doc test
-rw-r--r--clippy_lints/src/mut_mutex_lock.rs6
-rw-r--r--tests/ui/mut_mutex_lock.rs4
-rw-r--r--tests/ui/mut_mutex_lock.stderr22
3 files changed, 12 insertions, 20 deletions
diff --git a/clippy_lints/src/mut_mutex_lock.rs b/clippy_lints/src/mut_mutex_lock.rs
index 4f3108355ca..0680e578537 100644
--- a/clippy_lints/src/mut_mutex_lock.rs
+++ b/clippy_lints/src/mut_mutex_lock.rs
@@ -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,
diff --git a/tests/ui/mut_mutex_lock.rs b/tests/ui/mut_mutex_lock.rs
index 516d44bb7a9..9cd98e90c29 100644
--- a/tests/ui/mut_mutex_lock.rs
+++ b/tests/ui/mut_mutex_lock.rs
@@ -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;
 }
 
diff --git a/tests/ui/mut_mutex_lock.stderr b/tests/ui/mut_mutex_lock.stderr
index 426e0240830..d521ebb56c4 100644
--- a/tests/ui/mut_mutex_lock.stderr
+++ b/tests/ui/mut_mutex_lock.stderr
@@ -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`.