@@ -26,19 +26,16 @@ declare_clippy_lint! {
26
26
declare_lint_pass ! ( UnderscoreTyped => [ LET_WITH_TYPE_UNDERSCORE ] ) ;
27
27
28
28
impl LateLintPass < ' _ > for UnderscoreTyped {
29
- fn check_local < ' tcx > ( & mut self , cx : & LateContext < ' tcx > , local : & ' tcx Local < ' tcx > ) {
29
+ fn check_local ( & mut self , cx : & LateContext < ' _ > , local : & Local < ' _ > ) {
30
30
if_chain ! {
31
31
if !in_external_macro( cx. tcx. sess, local. span) ;
32
32
if let Some ( ty) = local. ty; // Ensure that it has a type defined
33
33
if let TyKind :: Infer = & ty. kind; // that type is '_'
34
34
if local. span. ctxt( ) == ty. span. ctxt( ) ;
35
35
then {
36
- let underscore_span = ty. span. with_lo( local. pat. span. hi( ) ) ;
37
- let snippet = snippet( cx, underscore_span, ": _" ) ;
38
-
39
36
// NOTE: Using `is_from_proc_macro` on `init` will require that it's initialized,
40
37
// this doesn't. Alternatively, `WithSearchPat` can be implemented for `Ty`
41
- if ! snippet. trim ( ) . starts_with ( ':' ) && !snippet . trim( ) . ends_with ( '_' ) {
38
+ if snippet( cx , ty . span , "_" ) . trim( ) != "_" {
42
39
return ;
43
40
}
44
41
@@ -47,7 +44,7 @@ impl LateLintPass<'_> for UnderscoreTyped {
47
44
LET_WITH_TYPE_UNDERSCORE ,
48
45
local. span,
49
46
"variable declared with type underscore" ,
50
- Some ( underscore_span ) ,
47
+ Some ( ty . span . with_lo ( local . pat . span . hi ( ) ) ) ,
51
48
"remove the explicit type `_` declaration"
52
49
)
53
50
}
0 commit comments