1
1
use clippy_utils:: diagnostics:: span_lint_and_help;
2
- use clippy_utils:: ty:: { is_must_use_ty, match_type} ;
2
+ use clippy_utils:: ty:: { is_must_use_ty, is_type_diagnostic_item , match_type} ;
3
3
use clippy_utils:: { is_must_use_func_call, paths} ;
4
4
use if_chain:: if_chain;
5
5
use rustc_hir:: { Local , PatKind } ;
6
6
use rustc_lint:: { LateContext , LateLintPass } ;
7
7
use rustc_middle:: lint:: in_external_macro;
8
8
use rustc_middle:: ty:: subst:: GenericArgKind ;
9
9
use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
10
+ use rustc_span:: { sym, Symbol } ;
10
11
11
12
declare_clippy_lint ! {
12
13
/// ### What it does
@@ -99,10 +100,9 @@ declare_clippy_lint! {
99
100
100
101
declare_lint_pass ! ( LetUnderscore => [ LET_UNDERSCORE_MUST_USE , LET_UNDERSCORE_LOCK , LET_UNDERSCORE_DROP ] ) ;
101
102
102
- const SYNC_GUARD_PATHS : [ & [ & str ] ; 6 ] = [
103
- & paths:: MUTEX_GUARD ,
104
- & paths:: RWLOCK_READ_GUARD ,
105
- & paths:: RWLOCK_WRITE_GUARD ,
103
+ const SYNC_GUARD_SYMS : [ Symbol ; 3 ] = [ sym:: MutexGuard , sym:: RwLockReadGuard , sym:: RwLockWriteGuard ] ;
104
+
105
+ const SYNC_GUARD_PATHS : [ & [ & str ] ; 3 ] = [
106
106
& paths:: PARKING_LOT_MUTEX_GUARD ,
107
107
& paths:: PARKING_LOT_RWLOCK_READ_GUARD ,
108
108
& paths:: PARKING_LOT_RWLOCK_WRITE_GUARD ,
@@ -121,7 +121,10 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
121
121
let init_ty = cx. typeck_results( ) . expr_ty( init) ;
122
122
let contains_sync_guard = init_ty. walk( ) . any( |inner| match inner. unpack( ) {
123
123
GenericArgKind :: Type ( inner_ty) => {
124
- SYNC_GUARD_PATHS . iter( ) . any( |path| match_type( cx, inner_ty, path) )
124
+ SYNC_GUARD_SYMS
125
+ . iter( )
126
+ . any( |& sym| is_type_diagnostic_item( cx, inner_ty, sym) )
127
+ || SYNC_GUARD_PATHS . iter( ) . any( |path| match_type( cx, inner_ty, path) )
125
128
} ,
126
129
127
130
GenericArgKind :: Lifetime ( _) | GenericArgKind :: Const ( _) => false ,
0 commit comments