Ignoring let_underscore_untyped
warnings in code from proc macros
This commit is contained in:
parent
a167973e81
commit
e234dfa63e
@ -1,4 +1,5 @@
|
||||
use clippy_utils::diagnostics::span_lint_and_help;
|
||||
use clippy_utils::is_from_proc_macro;
|
||||
use clippy_utils::ty::{implements_trait, is_must_use_ty, match_type};
|
||||
use clippy_utils::{is_must_use_func_call, paths};
|
||||
use rustc_hir::{ExprKind, Local, PatKind};
|
||||
@ -138,7 +139,7 @@ const SYNC_GUARD_PATHS: [&[&str]; 3] = [
|
||||
];
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
|
||||
fn check_local(&mut self, cx: &LateContext<'_>, local: &Local<'_>) {
|
||||
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &Local<'tcx>) {
|
||||
if !in_external_macro(cx.tcx.sess, local.span)
|
||||
&& let PatKind::Wild = local.pat.kind
|
||||
&& let Some(init) = local.init
|
||||
@ -191,15 +192,20 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
|
||||
if local.pat.default_binding_modes && local.ty.is_none() {
|
||||
// When `default_binding_modes` is true, the `let` keyword is present.
|
||||
|
||||
// Ignore function calls that return impl traits...
|
||||
if let Some(init) = local.init &&
|
||||
matches!(init.kind, ExprKind::Call(_, _) | ExprKind::MethodCall(_, _, _, _)) {
|
||||
let expr_ty = cx.typeck_results().expr_ty(init);
|
||||
if expr_ty.is_impl_trait() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(init) = local.init {
|
||||
// Ignore function calls that return impl traits...
|
||||
if matches!(init.kind, ExprKind::Call(_, _) | ExprKind::MethodCall(_, _, _, _)) {
|
||||
let expr_ty = cx.typeck_results().expr_ty(init);
|
||||
if expr_ty.is_impl_trait() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Ignore if it is from a procedural macro...
|
||||
if is_from_proc_macro(cx, init) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
span_lint_and_help(
|
||||
cx,
|
||||
|
@ -1,6 +1,12 @@
|
||||
//@aux-build: proc_macros.rs
|
||||
|
||||
#![allow(unused)]
|
||||
#![warn(clippy::let_underscore_untyped)]
|
||||
|
||||
extern crate proc_macros;
|
||||
use proc_macros::with_span;
|
||||
|
||||
use clippy_utils::is_from_proc_macro;
|
||||
use std::future::Future;
|
||||
use std::{boxed::Box, fmt::Display};
|
||||
|
||||
@ -32,6 +38,14 @@ fn g() -> impl Fn() {
|
||||
|| {}
|
||||
}
|
||||
|
||||
with_span!(
|
||||
span
|
||||
|
||||
fn dont_lint_proc_macro() {
|
||||
let _ = a();
|
||||
}
|
||||
);
|
||||
|
||||
fn main() {
|
||||
let _ = a();
|
||||
let _ = b(1);
|
||||
|
@ -1,60 +1,60 @@
|
||||
error: non-binding `let` without a type annotation
|
||||
--> $DIR/let_underscore_untyped.rs:36:5
|
||||
--> $DIR/let_underscore_untyped.rs:50:5
|
||||
|
|
||||
LL | let _ = a();
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
help: consider adding a type annotation
|
||||
--> $DIR/let_underscore_untyped.rs:36:10
|
||||
--> $DIR/let_underscore_untyped.rs:50:10
|
||||
|
|
||||
LL | let _ = a();
|
||||
| ^
|
||||
= note: `-D clippy::let-underscore-untyped` implied by `-D warnings`
|
||||
|
||||
error: non-binding `let` without a type annotation
|
||||
--> $DIR/let_underscore_untyped.rs:37:5
|
||||
--> $DIR/let_underscore_untyped.rs:51:5
|
||||
|
|
||||
LL | let _ = b(1);
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
help: consider adding a type annotation
|
||||
--> $DIR/let_underscore_untyped.rs:37:10
|
||||
--> $DIR/let_underscore_untyped.rs:51:10
|
||||
|
|
||||
LL | let _ = b(1);
|
||||
| ^
|
||||
|
||||
error: non-binding `let` without a type annotation
|
||||
--> $DIR/let_underscore_untyped.rs:39:5
|
||||
--> $DIR/let_underscore_untyped.rs:53:5
|
||||
|
|
||||
LL | let _ = d(&1);
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
help: consider adding a type annotation
|
||||
--> $DIR/let_underscore_untyped.rs:39:10
|
||||
--> $DIR/let_underscore_untyped.rs:53:10
|
||||
|
|
||||
LL | let _ = d(&1);
|
||||
| ^
|
||||
|
||||
error: non-binding `let` without a type annotation
|
||||
--> $DIR/let_underscore_untyped.rs:40:5
|
||||
--> $DIR/let_underscore_untyped.rs:54:5
|
||||
|
|
||||
LL | let _ = e();
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
help: consider adding a type annotation
|
||||
--> $DIR/let_underscore_untyped.rs:40:10
|
||||
--> $DIR/let_underscore_untyped.rs:54:10
|
||||
|
|
||||
LL | let _ = e();
|
||||
| ^
|
||||
|
||||
error: non-binding `let` without a type annotation
|
||||
--> $DIR/let_underscore_untyped.rs:41:5
|
||||
--> $DIR/let_underscore_untyped.rs:55:5
|
||||
|
|
||||
LL | let _ = f();
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
help: consider adding a type annotation
|
||||
--> $DIR/let_underscore_untyped.rs:41:10
|
||||
--> $DIR/let_underscore_untyped.rs:55:10
|
||||
|
|
||||
LL | let _ = f();
|
||||
| ^
|
||||
|
Loading…
x
Reference in New Issue
Block a user