about summary refs log tree commit diff
path: root/clippy_lints/src/let_underscore.rs
diff options
context:
space:
mode:
Diffstat (limited to 'clippy_lints/src/let_underscore.rs')
-rw-r--r--clippy_lints/src/let_underscore.rs23
1 files changed, 13 insertions, 10 deletions
diff --git a/clippy_lints/src/let_underscore.rs b/clippy_lints/src/let_underscore.rs
index 176787497eb..b7798b1c1d7 100644
--- a/clippy_lints/src/let_underscore.rs
+++ b/clippy_lints/src/let_underscore.rs
@@ -1,5 +1,5 @@
 use clippy_utils::diagnostics::span_lint_and_help;
-use clippy_utils::ty::{is_must_use_ty, match_type};
+use clippy_utils::ty::{is_must_use_ty, is_type_diagnostic_item, match_type};
 use clippy_utils::{is_must_use_func_call, paths};
 use if_chain::if_chain;
 use rustc_hir::{Local, PatKind};
@@ -7,6 +7,7 @@ use rustc_lint::{LateContext, LateLintPass};
 use rustc_middle::lint::in_external_macro;
 use rustc_middle::ty::subst::GenericArgKind;
 use rustc_session::{declare_lint_pass, declare_tool_lint};
+use rustc_span::{sym, Symbol};
 
 declare_clippy_lint! {
     /// ### What it does
@@ -99,10 +100,9 @@ declare_clippy_lint! {
 
 declare_lint_pass!(LetUnderscore => [LET_UNDERSCORE_MUST_USE, LET_UNDERSCORE_LOCK, LET_UNDERSCORE_DROP]);
 
-const SYNC_GUARD_PATHS: [&[&str]; 6] = [
-    &paths::MUTEX_GUARD,
-    &paths::RWLOCK_READ_GUARD,
-    &paths::RWLOCK_WRITE_GUARD,
+const SYNC_GUARD_SYMS: [Symbol; 3] = [sym::MutexGuard, sym::RwLockReadGuard, sym::RwLockWriteGuard];
+
+const SYNC_GUARD_PATHS: [&[&str]; 3] = [
     &paths::PARKING_LOT_MUTEX_GUARD,
     &paths::PARKING_LOT_RWLOCK_READ_GUARD,
     &paths::PARKING_LOT_RWLOCK_WRITE_GUARD,
@@ -121,7 +121,10 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
                 let init_ty = cx.typeck_results().expr_ty(init);
                 let contains_sync_guard = init_ty.walk().any(|inner| match inner.unpack() {
                     GenericArgKind::Type(inner_ty) => {
-                        SYNC_GUARD_PATHS.iter().any(|path| match_type(cx, inner_ty, path))
+                        SYNC_GUARD_SYMS
+                            .iter()
+                            .any(|&sym| is_type_diagnostic_item(cx, inner_ty, sym))
+                            || SYNC_GUARD_PATHS.iter().any(|path| match_type(cx, inner_ty, path))
                     },
 
                     GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => false,
@@ -134,7 +137,7 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
                         "non-binding let on a synchronization lock",
                         None,
                         "consider using an underscore-prefixed named \
-                            binding or dropping explicitly with `std::mem::drop`"
+                            binding or dropping explicitly with `std::mem::drop`",
                     );
                 } else if init_ty.needs_drop(cx.tcx, cx.param_env) {
                     span_lint_and_help(
@@ -144,7 +147,7 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
                         "non-binding `let` on a type that implements `Drop`",
                         None,
                         "consider using an underscore-prefixed named \
-                            binding or dropping explicitly with `std::mem::drop`"
+                            binding or dropping explicitly with `std::mem::drop`",
                     );
                 } else if is_must_use_ty(cx, cx.typeck_results().expr_ty(init)) {
                     span_lint_and_help(
@@ -153,7 +156,7 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
                         local.span,
                         "non-binding let on an expression with `#[must_use]` type",
                         None,
-                        "consider explicitly using expression value"
+                        "consider explicitly using expression value",
                     );
                 } else if is_must_use_func_call(cx, init) {
                     span_lint_and_help(
@@ -162,7 +165,7 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
                         local.span,
                         "non-binding let on a result of a `#[must_use]` function",
                         None,
-                        "consider explicitly using function result"
+                        "consider explicitly using function result",
                     );
                 }
             }