Skip to content

Commit 15f640a

Browse files
committed
let_with_type_underscore:
* Delay macro check. * Use `is_from_proc_macro
1 parent 5332def commit 15f640a

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

clippy_lints/src/let_with_type_underscore.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clippy_utils::diagnostics::span_lint_and_help;
2-
use clippy_utils::source::snippet;
2+
use clippy_utils::is_from_proc_macro;
33
use rustc_hir::{LetStmt, TyKind};
44
use rustc_lint::{LateContext, LateLintPass};
55
use rustc_middle::lint::in_external_macro;
@@ -25,19 +25,14 @@ declare_clippy_lint! {
2525
}
2626
declare_lint_pass!(UnderscoreTyped => [LET_WITH_TYPE_UNDERSCORE]);
2727

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
3231
&& let TyKind::Infer = &ty.kind // that type is '_'
3332
&& local.span.eq_ctxt(ty.span)
33+
&& !in_external_macro(cx.tcx.sess, local.span)
34+
&& !is_from_proc_macro(cx, ty)
3435
{
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-
4136
span_lint_and_help(
4237
cx,
4338
LET_WITH_TYPE_UNDERSCORE,

0 commit comments

Comments
 (0)