Skip to content

Commit 896c19e

Browse files
committed
rc_mutex: update doc
1 parent e2ec85c commit 896c19e

File tree

3 files changed

+8
-20
lines changed

3 files changed

+8
-20
lines changed

clippy_lints/src/types/mod.rs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -254,22 +254,10 @@ declare_clippy_lint! {
254254
declare_clippy_lint! {
255255
/// **What it does:** Checks for `Rc<Mutex<T>>`.
256256
///
257-
/// **Why is this bad?** `Rc<Mutex<T>>` may introduce a deadlock in single thread. Consider
258-
/// using `Rc<RefCell<T>>` instead.
259-
/// ```rust
260-
/// fn main() {
261-
/// use std::rc::Rc;
262-
/// use std::sync::Mutex;
263-
///
264-
/// let a: Rc<Mutex<i32>> = Rc::new(Mutex::new(1));
265-
/// let a_clone = a.clone();
266-
/// let mut data = a.lock().unwrap();
267-
/// println!("{:?}", *a_clone.lock().unwrap());
268-
/// *data = 10;
269-
/// }
270-
/// ```
257+
/// **Why is this bad?** `Rc` is used in single thread and `Mutex` is used in multi thread.
258+
/// Consider using `Rc<RefCell<T>>` in single thread or `Arc<Mutex<T>>` in multi thread.
271259
///
272-
/// **Known problems:** `Rc<RefCell<T>>` may panic in runtime.
260+
/// **Known problems:** None.
273261
///
274262
/// **Example:**
275263
/// ```rust,ignore

clippy_lints/src/types/rc_mutex.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_
1717
cx,
1818
RC_MUTEX,
1919
hir_ty.span,
20-
"found `Rc<Mutex<_>>`. Consider using `Rc<RefCell<_>>` instead",
20+
"found `Rc<Mutex<_>>`. Consider using `Rc<RefCell<_>>` or `Arc<Mutex<_>>` instead",
2121
);
2222
return true;
2323
}

tests/ui/rc_mutex.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
error: found `Rc<Mutex<_>>`. Consider using `Rc<RefCell<_>>` instead
1+
error: found `Rc<Mutex<_>>`. Consider using `Rc<RefCell<_>>` or `Arc<Mutex<_>>` instead
22
--> $DIR/rc_mutex.rs:9:10
33
|
44
LL | foo: Rc<Mutex<i32>>,
55
| ^^^^^^^^^^^^^^
66
|
77
= note: `-D clippy::rc-mutex` implied by `-D warnings`
88

9-
error: found `Rc<Mutex<_>>`. Consider using `Rc<RefCell<_>>` instead
9+
error: found `Rc<Mutex<_>>`. Consider using `Rc<RefCell<_>>` or `Arc<Mutex<_>>` instead
1010
--> $DIR/rc_mutex.rs:21:22
1111
|
1212
LL | pub fn test1<T>(foo: Rc<Mutex<T>>) {}
1313
| ^^^^^^^^^^^^
1414

15-
error: found `Rc<Mutex<_>>`. Consider using `Rc<RefCell<_>>` instead
15+
error: found `Rc<Mutex<_>>`. Consider using `Rc<RefCell<_>>` or `Arc<Mutex<_>>` instead
1616
--> $DIR/rc_mutex.rs:23:19
1717
|
1818
LL | pub fn test2(foo: Rc<Mutex<MyEnum>>) {}
1919
| ^^^^^^^^^^^^^^^^^
2020

21-
error: found `Rc<Mutex<_>>`. Consider using `Rc<RefCell<_>>` instead
21+
error: found `Rc<Mutex<_>>`. Consider using `Rc<RefCell<_>>` or `Arc<Mutex<_>>` instead
2222
--> $DIR/rc_mutex.rs:25:19
2323
|
2424
LL | pub fn test3(foo: Rc<Mutex<SubT<usize>>>) {}

0 commit comments

Comments
 (0)