let_with_type_underscore:
* Delay macro check. * Use `is_from_proc_macro
This commit is contained in:
parent
5332def0fd
commit
15f640a7cb
1 changed files with 6 additions and 11 deletions
|
|
@ -1,5 +1,5 @@
|
|||
use clippy_utils::diagnostics::span_lint_and_help;
|
||||
use clippy_utils::source::snippet;
|
||||
use clippy_utils::is_from_proc_macro;
|
||||
use rustc_hir::{LetStmt, TyKind};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::lint::in_external_macro;
|
||||
|
|
@ -25,19 +25,14 @@ declare_clippy_lint! {
|
|||
}
|
||||
declare_lint_pass!(UnderscoreTyped => [LET_WITH_TYPE_UNDERSCORE]);
|
||||
|
||||
impl LateLintPass<'_> for UnderscoreTyped {
|
||||
fn check_local(&mut self, cx: &LateContext<'_>, local: &LetStmt<'_>) {
|
||||
if !in_external_macro(cx.tcx.sess, local.span)
|
||||
&& let Some(ty) = local.ty // Ensure that it has a type defined
|
||||
impl<'tcx> LateLintPass<'tcx> for UnderscoreTyped {
|
||||
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'_>) {
|
||||
if let Some(ty) = local.ty // Ensure that it has a type defined
|
||||
&& let TyKind::Infer = &ty.kind // that type is '_'
|
||||
&& local.span.eq_ctxt(ty.span)
|
||||
&& !in_external_macro(cx.tcx.sess, local.span)
|
||||
&& !is_from_proc_macro(cx, ty)
|
||||
{
|
||||
// NOTE: Using `is_from_proc_macro` on `init` will require that it's initialized,
|
||||
// this doesn't. Alternatively, `WithSearchPat` can be implemented for `Ty`
|
||||
if snippet(cx, ty.span, "_").trim() != "_" {
|
||||
return;
|
||||
}
|
||||
|
||||
span_lint_and_help(
|
||||
cx,
|
||||
LET_WITH_TYPE_UNDERSCORE,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue