mirror of
https://github.com/rust-lang/rust-clippy
synced 2025-02-17 06:28:42 +00:00
rc_mutex: update doc
This commit is contained in:
parent
e2ec85c697
commit
896c19e2cf
3 changed files with 8 additions and 20 deletions
|
@ -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;
|
||||
/// **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.
|
||||
///
|
||||
/// 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;
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// **Known problems:** `Rc<RefCell<T>>` may panic in runtime.
|
||||
/// **Known problems:** None.
|
||||
///
|
||||
/// **Example:**
|
||||
/// ```rust,ignore
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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>>>) {}
|
||||
|
|
Loading…
Add table
Reference in a new issue