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;
4
3
use 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 } ;
7
5
use rustc_lint:: LateContext ;
8
6
use rustc_span:: symbol:: sym;
9
7
@@ -12,28 +10,14 @@ use super::RC_MUTEX;
12
10
pub ( super ) fn check ( cx : & LateContext < ' _ > , hir_ty : & hir:: Ty < ' _ > , qpath : & QPath < ' _ > , def_id : DefId ) -> bool {
13
11
if_chain ! {
14
12
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) ) ;
17
14
18
15
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(
27
17
cx,
28
18
RC_MUTEX ,
29
19
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" ,
37
21
) ;
38
22
return true ;
39
23
}
0 commit comments