- if_chain! {
- if let ExprKind::MethodCall(_, _, _) = init.kind;
- let method_did = cx.tables.type_dependent_def_id(init.hir_id).unwrap();
- if LOCK_METHODS_PATHS.iter().any(|path| match_def_path(cx, method_did, path));
- then {
- span_lint_and_help(
- cx,
- LET_UNDERSCORE_LOCK,
- stmt.span,
- "non-binding let on a synchronization lock",
- "consider using an underscore-prefixed named binding"
- )
- } else {
- if is_must_use_ty(cx, cx.tables.expr_ty(init)) {
- span_lint_and_help(
- cx,
- LET_UNDERSCORE_MUST_USE,
- stmt.span,
- "non-binding let on an expression with `#[must_use]` type",
- "consider explicitly using expression value"
- )
- } else if is_must_use_func_call(cx, init) {
- span_lint_and_help(
- cx,
- LET_UNDERSCORE_MUST_USE,
- stmt.span,
- "non-binding let on a result of a `#[must_use]` function",
- "consider explicitly using function result"
- )
- }
- }
+ let check_ty = |ty| SYNC_GUARD_PATHS.iter().any(|path| match_type(cx, ty, path));
+ if cx.tables.expr_ty(init).walk().any(check_ty) {
+ span_lint_and_help(
+ cx,
+ LET_UNDERSCORE_LOCK,
+ stmt.span,
+ "non-binding let on a synchronization lock",
+ "consider using an underscore-prefixed named \
+ binding or dropping explicitly with `std::mem::drop`"
+ )
+ } else if is_must_use_ty(cx, cx.tables.expr_ty(init)) {
+ span_lint_and_help(
+ cx,
+ LET_UNDERSCORE_MUST_USE,
+ stmt.span,
+ "non-binding let on an expression with `#[must_use]` type",
+ "consider explicitly using expression value"
+ )
+ } else if is_must_use_func_call(cx, init) {
+ span_lint_and_help(
+ cx,
+ LET_UNDERSCORE_MUST_USE,
+ stmt.span,
+ "non-binding let on a result of a `#[must_use]` function",
+ "consider explicitly using function result"
+ )