@@ -26,19 +26,16 @@ declare_clippy_lint! {
2626declare_lint_pass ! ( UnderscoreTyped => [ LET_WITH_TYPE_UNDERSCORE ] ) ;
2727
2828impl 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 < ' _ > ) {
3030 if_chain ! {
3131 if !in_external_macro( cx. tcx. sess, local. span) ;
3232 if let Some ( ty) = local. ty; // Ensure that it has a type defined
3333 if let TyKind :: Infer = & ty. kind; // that type is '_'
3434 if local. span. ctxt( ) == ty. span. ctxt( ) ;
3535 then {
36- let underscore_span = ty. span. with_lo( local. pat. span. hi( ) ) ;
37- let snippet = snippet( cx, underscore_span, ": _" ) ;
38-
3936 // NOTE: Using `is_from_proc_macro` on `init` will require that it's initialized,
4037 // 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( ) != "_" {
4239 return ;
4340 }
4441
@@ -47,7 +44,7 @@ impl LateLintPass<'_> for UnderscoreTyped {
4744 LET_WITH_TYPE_UNDERSCORE ,
4845 local. span,
4946 "variable declared with type underscore" ,
50- Some ( underscore_span ) ,
47+ Some ( ty . span . with_lo ( local . pat . span . hi ( ) ) ) ,
5148 "remove the explicit type `_` declaration"
5249 )
5350 }
0 commit comments