11use 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} ;
33use clippy_utils:: { is_must_use_func_call, paths} ;
44use if_chain:: if_chain;
55use rustc_hir:: { Local , PatKind } ;
66use rustc_lint:: { LateContext , LateLintPass } ;
77use rustc_middle:: lint:: in_external_macro;
88use rustc_middle:: ty:: subst:: GenericArgKind ;
99use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
10+ use rustc_span:: { sym, Symbol } ;
1011
1112declare_clippy_lint ! {
1213 /// ### What it does
@@ -99,10 +100,9 @@ declare_clippy_lint! {
99100
100101declare_lint_pass ! ( LetUnderscore => [ LET_UNDERSCORE_MUST_USE , LET_UNDERSCORE_LOCK , LET_UNDERSCORE_DROP ] ) ;
101102
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 ] = [
106106 & paths:: PARKING_LOT_MUTEX_GUARD ,
107107 & paths:: PARKING_LOT_RWLOCK_READ_GUARD ,
108108 & paths:: PARKING_LOT_RWLOCK_WRITE_GUARD ,
@@ -121,7 +121,10 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
121121 let init_ty = cx. typeck_results( ) . expr_ty( init) ;
122122 let contains_sync_guard = init_ty. walk( ) . any( |inner| match inner. unpack( ) {
123123 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) )
125128 } ,
126129
127130 GenericArgKind :: Lifetime ( _) | GenericArgKind :: Const ( _) => false ,
0 commit comments