Skip to content

Commit 0cc1454

Browse files
committed
Fix #10498
1 parent 9524cff commit 0cc1454

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

clippy_lints/src/let_with_type_underscore.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use clippy_utils::diagnostics::span_lint_and_help;
1+
use clippy_utils::{diagnostics::span_lint_and_help, is_from_proc_macro};
22
use rustc_hir::{Local, TyKind};
33
use rustc_lint::{LateContext, LateLintPass};
44
use rustc_middle::lint::in_external_macro;
@@ -32,7 +32,12 @@ impl LateLintPass<'_> for UnderscoreTyped {
3232
if let TyKind::Infer = &ty.kind; // that type is '_'
3333
if local.span.ctxt() == ty.span.ctxt();
3434
then {
35-
span_lint_and_help(cx,
35+
if let Some(init) = local.init && is_from_proc_macro(cx, init) {
36+
return;
37+
}
38+
39+
span_lint_and_help(
40+
cx,
3641
LET_WITH_TYPE_UNDERSCORE,
3742
local.span,
3843
"variable declared with type underscore",

tests/ui/let_with_type_underscore.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
//@aux-build: proc_macros.rs
12
#![allow(unused)]
23
#![warn(clippy::let_with_type_underscore)]
34
#![allow(clippy::let_unit_value)]
45

6+
extern crate proc_macros;
7+
58
fn func() -> &'static str {
69
""
710
}
@@ -16,4 +19,10 @@ fn main() {
1619
let x = func();
1720
let x: Vec<_> = Vec::<u32>::new();
1821
let x: [_; 1] = [1];
22+
23+
// do not lint from procedural macros
24+
proc_macros::with_span! {
25+
span
26+
let x: _ = ();
27+
};
1928
}

tests/ui/let_with_type_underscore.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
error: variable declared with type underscore
2-
--> $DIR/let_with_type_underscore.rs:11:5
2+
--> $DIR/let_with_type_underscore.rs:14:5
33
|
44
LL | let x: _ = 1;
55
| ^^^^^^^^^^^^^
66
|
77
help: remove the explicit type `_` declaration
8-
--> $DIR/let_with_type_underscore.rs:11:10
8+
--> $DIR/let_with_type_underscore.rs:14:10
99
|
1010
LL | let x: _ = 1;
1111
| ^^^
1212
= note: `-D clippy::let-with-type-underscore` implied by `-D warnings`
1313

1414
error: variable declared with type underscore
15-
--> $DIR/let_with_type_underscore.rs:12:5
15+
--> $DIR/let_with_type_underscore.rs:15:5
1616
|
1717
LL | let _: _ = 2;
1818
| ^^^^^^^^^^^^^
1919
|
2020
help: remove the explicit type `_` declaration
21-
--> $DIR/let_with_type_underscore.rs:12:10
21+
--> $DIR/let_with_type_underscore.rs:15:10
2222
|
2323
LL | let _: _ = 2;
2424
| ^^^
2525

2626
error: variable declared with type underscore
27-
--> $DIR/let_with_type_underscore.rs:13:5
27+
--> $DIR/let_with_type_underscore.rs:16:5
2828
|
2929
LL | let x: _ = func();
3030
| ^^^^^^^^^^^^^^^^^^
3131
|
3232
help: remove the explicit type `_` declaration
33-
--> $DIR/let_with_type_underscore.rs:13:10
33+
--> $DIR/let_with_type_underscore.rs:16:10
3434
|
3535
LL | let x: _ = func();
3636
| ^^^

0 commit comments

Comments
 (0)