1- use clippy_utils:: diagnostics:: span_lint_and_sugg;
2- use clippy_utils:: source:: snippet_with_applicability;
3- use clippy_utils:: { get_qpath_generic_tys, is_ty_param_diagnostic_item} ;
1+ use clippy_utils:: diagnostics:: span_lint;
2+ use clippy_utils:: is_ty_param_diagnostic_item;
43use if_chain:: if_chain;
5- use rustc_errors:: Applicability ;
6- use rustc_hir:: { self as hir, def_id:: DefId , QPath , TyKind } ;
4+ use rustc_hir:: { self as hir, def_id:: DefId , QPath } ;
75use rustc_lint:: LateContext ;
86use rustc_span:: symbol:: sym;
97
@@ -12,28 +10,14 @@ use super::RC_MUTEX;
1210pub ( super ) fn check ( cx : & LateContext < ' _ > , hir_ty : & hir:: Ty < ' _ > , qpath : & QPath < ' _ > , def_id : DefId ) -> bool {
1311 if_chain ! {
1412 if cx. tcx. is_diagnostic_item( sym:: Rc , def_id) ;
15- if let Some ( ty) = is_ty_param_diagnostic_item( cx, qpath, sym!( mutex_type) ) ;
16- if let TyKind :: Path ( ref qpath_inner) =ty. kind;
13+ if let Some ( _) = is_ty_param_diagnostic_item( cx, qpath, sym!( mutex_type) ) ;
1714
1815 then{
19- let mut applicability = Applicability :: MachineApplicable ;
20-
21- let inner_span = match get_qpath_generic_tys( qpath_inner) . next( ) {
22- Some ( ty) => ty. span,
23- None => return false ,
24- } ;
25-
26- span_lint_and_sugg(
16+ span_lint(
2717 cx,
2818 RC_MUTEX ,
2919 hir_ty. span,
30- "you seem to be trying to use `Rc<Mutex<T>>`. Consider using `Rc<RefCell<T>>`" ,
31- "try" ,
32- format!(
33- "Rc<RefCell<{}>>" ,
34- snippet_with_applicability( cx, inner_span, ".." , & mut applicability)
35- ) ,
36- applicability,
20+ "found `Rc<Mutex<_>>`. Consider using `Rc<RefCell<_>>` instead" ,
3721 ) ;
3822 return true ;
3923 }
0 commit comments