File tree Expand file tree Collapse file tree 3 files changed +22
-8
lines changed Expand file tree Collapse file tree 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 } ;
22use rustc_hir:: { Local , TyKind } ;
33use rustc_lint:: { LateContext , LateLintPass } ;
44use 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" ,
Original file line number Diff line number Diff line change 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+
58fn 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}
Original file line number Diff line number Diff line change 11error: variable declared with type underscore
2- --> $DIR/let_with_type_underscore.rs:11 :5
2+ --> $DIR/let_with_type_underscore.rs:14 :5
33 |
44LL | let x: _ = 1;
55 | ^^^^^^^^^^^^^
66 |
77help: remove the explicit type `_` declaration
8- --> $DIR/let_with_type_underscore.rs:11 :10
8+ --> $DIR/let_with_type_underscore.rs:14 :10
99 |
1010LL | let x: _ = 1;
1111 | ^^^
1212 = note: `-D clippy::let-with-type-underscore` implied by `-D warnings`
1313
1414error: variable declared with type underscore
15- --> $DIR/let_with_type_underscore.rs:12 :5
15+ --> $DIR/let_with_type_underscore.rs:15 :5
1616 |
1717LL | let _: _ = 2;
1818 | ^^^^^^^^^^^^^
1919 |
2020help: remove the explicit type `_` declaration
21- --> $DIR/let_with_type_underscore.rs:12 :10
21+ --> $DIR/let_with_type_underscore.rs:15 :10
2222 |
2323LL | let _: _ = 2;
2424 | ^^^
2525
2626error: variable declared with type underscore
27- --> $DIR/let_with_type_underscore.rs:13 :5
27+ --> $DIR/let_with_type_underscore.rs:16 :5
2828 |
2929LL | let x: _ = func();
3030 | ^^^^^^^^^^^^^^^^^^
3131 |
3232help: remove the explicit type `_` declaration
33- --> $DIR/let_with_type_underscore.rs:13 :10
33+ --> $DIR/let_with_type_underscore.rs:16 :10
3434 |
3535LL | let x: _ = func();
3636 | ^^^
You can’t perform that action at this time.
0 commit comments