Skip to content

Commit ba1fb74

Browse files
committed
check for _ instead
1 parent 143ff2d commit ba1fb74

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

clippy_lints/src/let_with_type_underscore.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,16 @@ declare_clippy_lint! {
2626
declare_lint_pass!(UnderscoreTyped => [LET_WITH_TYPE_UNDERSCORE]);
2727

2828
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<'_>) {
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

Comments
 (0)