@@ -3,11 +3,11 @@ mod box_vec;
33mod linked_list;
44mod option_option;
55mod rc_buffer;
6+ mod rc_mutex;
67mod redundant_allocation;
78mod type_complexity;
89mod utils;
910mod vec_box;
10- mod rc_mutex;
1111
1212use rustc_hir as hir;
1313use rustc_hir:: intravisit:: FnKind ;
@@ -252,18 +252,50 @@ declare_clippy_lint! {
252252}
253253
254254declare_clippy_lint ! {
255- /// TODO
255+ /// **What it does:** Checks for `Rc<Mutex<T>>`.
256+ ///
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+ /// ```
271+ ///
272+ /// **Known problems:** `Rc<RefCell<T>>` may panic in runtime.
273+ ///
274+ /// **Example:**
275+ /// ```rust,ignore
276+ /// use std::rc::Rc;
277+ /// use std::sync::Mutex;
278+ /// fn foo(interned: Rc<Mutex<i32>>) { ... }
279+ /// ```
280+ ///
281+ /// Better:
282+ ///
283+ /// ```rust,ignore
284+ /// use std::rc::Rc;
285+ /// use std::cell::RefCell
286+ /// fn foo(interned: Rc<RefCell<i32>>) { ... }
287+ /// ```
256288 pub RC_MUTEX ,
257289 restriction,
258- "usage of Mutex inside Rc "
290+ "usage of `Rc<Mutex<T>>` "
259291}
260292
261293pub struct Types {
262294 vec_box_size_threshold : u64 ,
263295 type_complexity_threshold : u64 ,
264296}
265297
266- impl_lint_pass ! ( Types => [ BOX_VEC , VEC_BOX , OPTION_OPTION , LINKEDLIST , BORROWED_BOX , REDUNDANT_ALLOCATION , RC_BUFFER , TYPE_COMPLEXITY , RC_MUTEX ] ) ;
298+ impl_lint_pass ! ( Types => [ BOX_VEC , VEC_BOX , OPTION_OPTION , LINKEDLIST , BORROWED_BOX , REDUNDANT_ALLOCATION , RC_BUFFER , RC_MUTEX , TYPE_COMPLEXITY ] ) ;
267299
268300impl < ' tcx > LateLintPass < ' tcx > for Types {
269301 fn check_fn ( & mut self , cx : & LateContext < ' _ > , _: FnKind < ' _ > , decl : & FnDecl < ' _ > , _: & Body < ' _ > , _: Span , id : HirId ) {
0 commit comments