Skip to content

Commit 7ebb3aa

Browse files
committed
Auto merge of #5402 - pmk21:allow-let-underscore-must-use, r=flip1995
Allow let_underscore_must_use to be ignored changelog: none Fixes #5366
2 parents 42796e1 + c9978b6 commit 7ebb3aa

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

clippy_lints/src/let_underscore.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use if_chain::if_chain;
2-
use rustc_hir::{PatKind, Stmt, StmtKind};
2+
use rustc_hir::{Local, PatKind};
33
use rustc_lint::{LateContext, LateLintPass};
44
use rustc_middle::lint::in_external_macro;
55
use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -66,13 +66,12 @@ const SYNC_GUARD_PATHS: [&[&str]; 3] = [
6666
];
6767

6868
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnderscore {
69-
fn check_stmt(&mut self, cx: &LateContext<'_, '_>, stmt: &Stmt<'_>) {
70-
if in_external_macro(cx.tcx.sess, stmt.span) {
69+
fn check_local(&mut self, cx: &LateContext<'_, '_>, local: &Local<'_>) {
70+
if in_external_macro(cx.tcx.sess, local.span) {
7171
return;
7272
}
7373

7474
if_chain! {
75-
if let StmtKind::Local(ref local) = stmt.kind;
7675
if let PatKind::Wild = local.pat.kind;
7776
if let Some(ref init) = local.init;
7877
then {
@@ -81,7 +80,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnderscore {
8180
span_lint_and_help(
8281
cx,
8382
LET_UNDERSCORE_LOCK,
84-
stmt.span,
83+
local.span,
8584
"non-binding let on a synchronization lock",
8685
"consider using an underscore-prefixed named \
8786
binding or dropping explicitly with `std::mem::drop`"
@@ -90,15 +89,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnderscore {
9089
span_lint_and_help(
9190
cx,
9291
LET_UNDERSCORE_MUST_USE,
93-
stmt.span,
92+
local.span,
9493
"non-binding let on an expression with `#[must_use]` type",
9594
"consider explicitly using expression value"
9695
)
9796
} else if is_must_use_func_call(cx, init) {
9897
span_lint_and_help(
9998
cx,
10099
LET_UNDERSCORE_MUST_USE,
101-
stmt.span,
100+
local.span,
102101
"non-binding let on a result of a `#[must_use]` function",
103102
"consider explicitly using function result"
104103
)

tests/ui/let_underscore_must_use.rs

+3
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,7 @@ fn main() {
8888
let _ = a.map(|_| ());
8989

9090
let _ = a;
91+
92+
#[allow(clippy::let_underscore_must_use)]
93+
let _ = a;
9194
}

0 commit comments

Comments
 (0)