about summary refs log tree commit diff
diff options
context:
space:
mode:
authorlyj <sjtu5140809011@gmail.com>2021-06-05 21:28:52 +0800
committerlyj <sjtu5140809011@gmail.com>2021-06-05 21:42:45 +0800
commit896c19e2cf314b4d1111afb3d89722a1e2878bd3 (patch)
tree65892e5fed68df40c6af695b7bb22b9f5d352ff0
parente2ec85c6977c4c22a11d346f4f94773c527eddbf (diff)
downloadrust-896c19e2cf314b4d1111afb3d89722a1e2878bd3.tar.gz
rust-896c19e2cf314b4d1111afb3d89722a1e2878bd3.zip
rc_mutex: update doc
-rw-r--r--clippy_lints/src/types/mod.rs18
-rw-r--r--clippy_lints/src/types/rc_mutex.rs2
-rw-r--r--tests/ui/rc_mutex.stderr8
3 files changed, 8 insertions, 20 deletions
diff --git a/clippy_lints/src/types/mod.rs b/clippy_lints/src/types/mod.rs
index 07dec2de827..30b04e4174c 100644
--- a/clippy_lints/src/types/mod.rs
+++ b/clippy_lints/src/types/mod.rs
@@ -254,22 +254,10 @@ declare_clippy_lint! {
 declare_clippy_lint! {
     /// **What it does:** Checks for `Rc<Mutex<T>>`.
     ///
-    /// **Why is this bad?** `Rc<Mutex<T>>` may introduce a deadlock in single thread. Consider
-    /// using `Rc<RefCell<T>>` instead.
-    /// ```rust
-    /// fn main() {
-    ///     use std::rc::Rc;
-    ///     use std::sync::Mutex;
-    ///
-    ///     let a: Rc<Mutex<i32>> = Rc::new(Mutex::new(1));
-    ///     let a_clone = a.clone();
-    ///     let mut data = a.lock().unwrap();
-    ///     println!("{:?}", *a_clone.lock().unwrap());
-    ///     *data = 10;
-    ///  }
-    /// ```
+    /// **Why is this bad?** `Rc` is used in single thread and `Mutex` is used in multi thread.
+    /// Consider using `Rc<RefCell<T>>` in single thread or `Arc<Mutex<T>>` in multi thread.
     ///
-    /// **Known problems:** `Rc<RefCell<T>>` may panic in runtime.
+    /// **Known problems:** None.
     ///
     /// **Example:**
     /// ```rust,ignore
diff --git a/clippy_lints/src/types/rc_mutex.rs b/clippy_lints/src/types/rc_mutex.rs
index e8109f12324..bd7a0ee6408 100644
--- a/clippy_lints/src/types/rc_mutex.rs
+++ b/clippy_lints/src/types/rc_mutex.rs
@@ -17,7 +17,7 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_
                 cx,
                 RC_MUTEX,
                 hir_ty.span,
-                "found `Rc<Mutex<_>>`. Consider using `Rc<RefCell<_>>` instead",
+                "found `Rc<Mutex<_>>`. Consider using `Rc<RefCell<_>>` or `Arc<Mutex<_>>` instead",
             );
             return true;
         }
diff --git a/tests/ui/rc_mutex.stderr b/tests/ui/rc_mutex.stderr
index ab59337a960..c32780acf9f 100644
--- a/tests/ui/rc_mutex.stderr
+++ b/tests/ui/rc_mutex.stderr
@@ -1,4 +1,4 @@
-error: found `Rc<Mutex<_>>`. Consider using `Rc<RefCell<_>>` instead
+error: found `Rc<Mutex<_>>`. Consider using `Rc<RefCell<_>>` or `Arc<Mutex<_>>` instead
   --> $DIR/rc_mutex.rs:9:10
    |
 LL |     foo: Rc<Mutex<i32>>,
@@ -6,19 +6,19 @@ LL |     foo: Rc<Mutex<i32>>,
    |
    = note: `-D clippy::rc-mutex` implied by `-D warnings`
 
-error: found `Rc<Mutex<_>>`. Consider using `Rc<RefCell<_>>` instead
+error: found `Rc<Mutex<_>>`. Consider using `Rc<RefCell<_>>` or `Arc<Mutex<_>>` instead
   --> $DIR/rc_mutex.rs:21:22
    |
 LL | pub fn test1<T>(foo: Rc<Mutex<T>>) {}
    |                      ^^^^^^^^^^^^
 
-error: found `Rc<Mutex<_>>`. Consider using `Rc<RefCell<_>>` instead
+error: found `Rc<Mutex<_>>`. Consider using `Rc<RefCell<_>>` or `Arc<Mutex<_>>` instead
   --> $DIR/rc_mutex.rs:23:19
    |
 LL | pub fn test2(foo: Rc<Mutex<MyEnum>>) {}
    |                   ^^^^^^^^^^^^^^^^^
 
-error: found `Rc<Mutex<_>>`. Consider using `Rc<RefCell<_>>` instead
+error: found `Rc<Mutex<_>>`. Consider using `Rc<RefCell<_>>` or `Arc<Mutex<_>>` instead
   --> $DIR/rc_mutex.rs:25:19
    |
 LL | pub fn test3(foo: Rc<Mutex<SubT<usize>>>) {}