]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/src/docs/rc_mutex.txt
Rollup merge of #101340 - andrewpollack:fuchsia-zxdb-docs, r=tmandry
[rust.git] / src / tools / clippy / src / docs / rc_mutex.txt
1 ### What it does
2 Checks for `Rc<Mutex<T>>`.
3
4 ### Why is this bad?
5 `Rc` is used in single thread and `Mutex` is used in multi thread.
6 Consider using `Rc<RefCell<T>>` in single thread or `Arc<Mutex<T>>` in multi thread.
7
8 ### Known problems
9 Sometimes combining generic types can lead to the requirement that a
10 type use Rc in conjunction with Mutex. We must consider those cases false positives, but
11 alas they are quite hard to rule out. Luckily they are also rare.
12
13 ### Example
14 ```
15 use std::rc::Rc;
16 use std::sync::Mutex;
17 fn foo(interned: Rc<Mutex<i32>>) { ... }
18 ```
19
20 Better:
21
22 ```
23 use std::rc::Rc;
24 use std::cell::RefCell
25 fn foo(interned: Rc<RefCell<i32>>) { ... }
26 ```