Skip to content

Commit c9978b6

Browse files
committed
Allow let_underscore
1 parent 97acabe commit c9978b6

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

clippy_lints/src/let_underscore.rs

Lines changed: 6 additions & 7 deletions
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
)

0 commit comments

Comments
 (0)