Skip to content

Commit f3f6fd8

Browse files
committed
Auto merge of #10775 - lochetti:fix_10723, r=xFrednet
Ignoring `let_underscore_untyped` warnings in code from proc macros Don't linting let_underscore_untyped if code was generated by procedural macro. This PR fixes #10723 --- closes: #10723 changelog: Fix: [`let_underscore_untyped`]: No longer lints inside proc macros [#10775](#10775) <!-- changelog_checked -->
2 parents 223f518 + 2d9d81f commit f3f6fd8

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

clippy_lints/src/let_underscore.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use clippy_utils::diagnostics::span_lint_and_help;
2+
use clippy_utils::is_from_proc_macro;
23
use clippy_utils::ty::{implements_trait, is_must_use_ty, match_type};
34
use clippy_utils::{is_must_use_func_call, paths};
45
use rustc_hir::{ExprKind, Local, PatKind};
@@ -138,7 +139,7 @@ const SYNC_GUARD_PATHS: [&[&str]; 3] = [
138139
];
139140

140141
impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
141-
fn check_local(&mut self, cx: &LateContext<'_>, local: &Local<'_>) {
142+
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &Local<'tcx>) {
142143
if !in_external_macro(cx.tcx.sess, local.span)
143144
&& let PatKind::Wild = local.pat.kind
144145
&& let Some(init) = local.init
@@ -200,6 +201,10 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
200201
}
201202
}
202203

204+
// Ignore if it is from a procedural macro...
205+
if is_from_proc_macro(cx, init) {
206+
return;
207+
}
203208

204209
span_lint_and_help(
205210
cx,

tests/ui/let_underscore_untyped.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
//@aux-build: proc_macros.rs
2+
13
#![allow(unused)]
24
#![warn(clippy::let_underscore_untyped)]
35

6+
extern crate proc_macros;
7+
use proc_macros::with_span;
8+
9+
use clippy_utils::is_from_proc_macro;
410
use std::future::Future;
511
use std::{boxed::Box, fmt::Display};
612

@@ -32,6 +38,14 @@ fn g() -> impl Fn() {
3238
|| {}
3339
}
3440

41+
with_span!(
42+
span
43+
44+
fn dont_lint_proc_macro() {
45+
let _ = a();
46+
}
47+
);
48+
3549
fn main() {
3650
let _ = a();
3751
let _ = b(1);

tests/ui/let_underscore_untyped.stderr

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,60 @@
11
error: non-binding `let` without a type annotation
2-
--> $DIR/let_underscore_untyped.rs:36:5
2+
--> $DIR/let_underscore_untyped.rs:50:5
33
|
44
LL | let _ = a();
55
| ^^^^^^^^^^^^
66
|
77
help: consider adding a type annotation
8-
--> $DIR/let_underscore_untyped.rs:36:10
8+
--> $DIR/let_underscore_untyped.rs:50:10
99
|
1010
LL | let _ = a();
1111
| ^
1212
= note: `-D clippy::let-underscore-untyped` implied by `-D warnings`
1313

1414
error: non-binding `let` without a type annotation
15-
--> $DIR/let_underscore_untyped.rs:37:5
15+
--> $DIR/let_underscore_untyped.rs:51:5
1616
|
1717
LL | let _ = b(1);
1818
| ^^^^^^^^^^^^^
1919
|
2020
help: consider adding a type annotation
21-
--> $DIR/let_underscore_untyped.rs:37:10
21+
--> $DIR/let_underscore_untyped.rs:51:10
2222
|
2323
LL | let _ = b(1);
2424
| ^
2525

2626
error: non-binding `let` without a type annotation
27-
--> $DIR/let_underscore_untyped.rs:39:5
27+
--> $DIR/let_underscore_untyped.rs:53:5
2828
|
2929
LL | let _ = d(&1);
3030
| ^^^^^^^^^^^^^^
3131
|
3232
help: consider adding a type annotation
33-
--> $DIR/let_underscore_untyped.rs:39:10
33+
--> $DIR/let_underscore_untyped.rs:53:10
3434
|
3535
LL | let _ = d(&1);
3636
| ^
3737

3838
error: non-binding `let` without a type annotation
39-
--> $DIR/let_underscore_untyped.rs:40:5
39+
--> $DIR/let_underscore_untyped.rs:54:5
4040
|
4141
LL | let _ = e();
4242
| ^^^^^^^^^^^^
4343
|
4444
help: consider adding a type annotation
45-
--> $DIR/let_underscore_untyped.rs:40:10
45+
--> $DIR/let_underscore_untyped.rs:54:10
4646
|
4747
LL | let _ = e();
4848
| ^
4949

5050
error: non-binding `let` without a type annotation
51-
--> $DIR/let_underscore_untyped.rs:41:5
51+
--> $DIR/let_underscore_untyped.rs:55:5
5252
|
5353
LL | let _ = f();
5454
| ^^^^^^^^^^^^
5555
|
5656
help: consider adding a type annotation
57-
--> $DIR/let_underscore_untyped.rs:41:10
57+
--> $DIR/let_underscore_untyped.rs:55:10
5858
|
5959
LL | let _ = f();
6060
| ^

0 commit comments

Comments
 (0)