1
1
use clippy_utils:: diagnostics:: span_lint_and_help;
2
- use clippy_utils:: source :: snippet ;
2
+ use clippy_utils:: is_from_proc_macro ;
3
3
use rustc_hir:: { LetStmt , TyKind } ;
4
4
use rustc_lint:: { LateContext , LateLintPass } ;
5
5
use rustc_middle:: lint:: in_external_macro;
@@ -25,19 +25,14 @@ declare_clippy_lint! {
25
25
}
26
26
declare_lint_pass ! ( UnderscoreTyped => [ LET_WITH_TYPE_UNDERSCORE ] ) ;
27
27
28
- impl LateLintPass < ' _ > for UnderscoreTyped {
29
- fn check_local ( & mut self , cx : & LateContext < ' _ > , local : & LetStmt < ' _ > ) {
30
- if !in_external_macro ( cx. tcx . sess , local. span )
31
- && let Some ( ty) = local. ty // Ensure that it has a type defined
28
+ impl < ' tcx > LateLintPass < ' tcx > for UnderscoreTyped {
29
+ fn check_local ( & mut self , cx : & LateContext < ' tcx > , local : & ' tcx LetStmt < ' _ > ) {
30
+ if let Some ( ty) = local. ty // Ensure that it has a type defined
32
31
&& let TyKind :: Infer = & ty. kind // that type is '_'
33
32
&& local. span . eq_ctxt ( ty. span )
33
+ && !in_external_macro ( cx. tcx . sess , local. span )
34
+ && !is_from_proc_macro ( cx, ty)
34
35
{
35
- // NOTE: Using `is_from_proc_macro` on `init` will require that it's initialized,
36
- // this doesn't. Alternatively, `WithSearchPat` can be implemented for `Ty`
37
- if snippet ( cx, ty. span , "_" ) . trim ( ) != "_" {
38
- return ;
39
- }
40
-
41
36
span_lint_and_help (
42
37
cx,
43
38
LET_WITH_TYPE_UNDERSCORE ,
0 commit comments