]> git.lizzy.rs Git - rust.git/commitdiff
Change lint doc test
authorFrancis Murillo <francis.murillo@protonmail.com>
Fri, 2 Oct 2020 02:54:44 +0000 (10:54 +0800)
committerFrancis Murillo <francis.murillo@protonmail.com>
Sun, 25 Oct 2020 09:41:24 +0000 (17:41 +0800)
clippy_lints/src/mut_mutex_lock.rs
tests/ui/mut_mutex_lock.rs
tests/ui/mut_mutex_lock.stderr

index 4f3108355ca7db037adab88a115158e702ebe44b..0680e578537c6a18ea9361ebbe5d883d9ddfc4cf 100644 (file)
@@ -21,8 +21,8 @@
     /// 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 @@
     /// 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,
index 516d44bb7a9eb92e16669f5bd4270a513da2b56b..9cd98e90c29df3b627e6f93484393140b76f7170 100644 (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;
 }
 
index 426e0240830e43d45b04aa14ea730c5646d01729..d521ebb56c4310970de892bff615a2312c0d5132 100644 (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`.