File tree 3 files changed +22
-8
lines changed
3 files changed +22
-8
lines changed Original file line number Diff line number Diff line change 1
- use clippy_utils:: diagnostics:: span_lint_and_help;
1
+ use clippy_utils:: { diagnostics:: span_lint_and_help, is_from_proc_macro } ;
2
2
use rustc_hir:: { Local , TyKind } ;
3
3
use rustc_lint:: { LateContext , LateLintPass } ;
4
4
use rustc_middle:: lint:: in_external_macro;
@@ -32,7 +32,12 @@ impl LateLintPass<'_> for UnderscoreTyped {
32
32
if let TyKind :: Infer = & ty. kind; // that type is '_'
33
33
if local. span. ctxt( ) == ty. span. ctxt( ) ;
34
34
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,
36
41
LET_WITH_TYPE_UNDERSCORE ,
37
42
local. span,
38
43
"variable declared with type underscore" ,
Original file line number Diff line number Diff line change
1
+ //@aux-build: proc_macros.rs
1
2
#![ allow( unused) ]
2
3
#![ warn( clippy:: let_with_type_underscore) ]
3
4
#![ allow( clippy:: let_unit_value) ]
4
5
6
+ extern crate proc_macros;
7
+
5
8
fn func ( ) -> & ' static str {
6
9
""
7
10
}
@@ -16,4 +19,10 @@ fn main() {
16
19
let x = func ( ) ;
17
20
let x: Vec < _ > = Vec :: < u32 > :: new ( ) ;
18
21
let x: [ _ ; 1 ] = [ 1 ] ;
22
+
23
+ // do not lint from procedural macros
24
+ proc_macros:: with_span! {
25
+ span
26
+ let x: _ = ( ) ;
27
+ } ;
19
28
}
Original file line number Diff line number Diff line change 1
1
error: variable declared with type underscore
2
- --> $DIR/let_with_type_underscore.rs:11 :5
2
+ --> $DIR/let_with_type_underscore.rs:14 :5
3
3
|
4
4
LL | let x: _ = 1;
5
5
| ^^^^^^^^^^^^^
6
6
|
7
7
help: remove the explicit type `_` declaration
8
- --> $DIR/let_with_type_underscore.rs:11 :10
8
+ --> $DIR/let_with_type_underscore.rs:14 :10
9
9
|
10
10
LL | let x: _ = 1;
11
11
| ^^^
12
12
= note: `-D clippy::let-with-type-underscore` implied by `-D warnings`
13
13
14
14
error: variable declared with type underscore
15
- --> $DIR/let_with_type_underscore.rs:12 :5
15
+ --> $DIR/let_with_type_underscore.rs:15 :5
16
16
|
17
17
LL | let _: _ = 2;
18
18
| ^^^^^^^^^^^^^
19
19
|
20
20
help: remove the explicit type `_` declaration
21
- --> $DIR/let_with_type_underscore.rs:12 :10
21
+ --> $DIR/let_with_type_underscore.rs:15 :10
22
22
|
23
23
LL | let _: _ = 2;
24
24
| ^^^
25
25
26
26
error: variable declared with type underscore
27
- --> $DIR/let_with_type_underscore.rs:13 :5
27
+ --> $DIR/let_with_type_underscore.rs:16 :5
28
28
|
29
29
LL | let x: _ = func();
30
30
| ^^^^^^^^^^^^^^^^^^
31
31
|
32
32
help: remove the explicit type `_` declaration
33
- --> $DIR/let_with_type_underscore.rs:13 :10
33
+ --> $DIR/let_with_type_underscore.rs:16 :10
34
34
|
35
35
LL | let x: _ = func();
36
36
| ^^^
You can’t perform that action at this time.
0 commit comments