Ignore impl Trait
(s)
This commit is contained in:
parent
928349795f
commit
bdd05456b1
@ -1,7 +1,7 @@
|
||||
use clippy_utils::diagnostics::span_lint_and_help;
|
||||
use clippy_utils::ty::{implements_trait, is_must_use_ty, match_type};
|
||||
use clippy_utils::{is_must_use_func_call, paths};
|
||||
use rustc_hir::{Local, PatKind};
|
||||
use rustc_hir::{ExprKind, Local, PatKind};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::lint::in_external_macro;
|
||||
use rustc_middle::ty::subst::GenericArgKind;
|
||||
@ -189,7 +189,18 @@ fn check_local(&mut self, cx: &LateContext<'_>, local: &Local<'_>) {
|
||||
|
||||
if local.pat.default_binding_modes && local.ty.is_none() {
|
||||
// When `default_binding_modes` is true, the `let` keyword is present.
|
||||
span_lint_and_help(
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
span_lint_and_help(
|
||||
cx,
|
||||
LET_UNDERSCORE_UNTYPED,
|
||||
local.span,
|
||||
|
@ -28,6 +28,10 @@ fn f() -> Box<dyn Display> {
|
||||
Box::new(1)
|
||||
}
|
||||
|
||||
fn g() -> impl Fn() {
|
||||
|| {}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let _ = a();
|
||||
let _ = b(1);
|
||||
@ -35,6 +39,7 @@ fn main() {
|
||||
let _ = d(&1);
|
||||
let _ = e();
|
||||
let _ = f();
|
||||
let _ = g();
|
||||
|
||||
_ = a();
|
||||
_ = b(1);
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: non-binding `let` without a type annotation
|
||||
--> $DIR/let_underscore_untyped.rs:32:5
|
||||
--> $DIR/let_underscore_untyped.rs:36:5
|
||||
|
|
||||
LL | let _ = a();
|
||||
| ^^^^^^^^^^^^
|
||||
@ -8,7 +8,7 @@ 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:33:5
|
||||
--> $DIR/let_underscore_untyped.rs:37:5
|
||||
|
|
||||
LL | let _ = b(1);
|
||||
| ^^^^^^^^^^^^^
|
||||
@ -16,15 +16,7 @@ LL | let _ = b(1);
|
||||
= help: consider adding a type annotation or removing the `let` keyword
|
||||
|
||||
error: non-binding `let` without a type annotation
|
||||
--> $DIR/let_underscore_untyped.rs:34:5
|
||||
|
|
||||
LL | let _ = c();
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider adding a type annotation or removing the `let` keyword
|
||||
|
||||
error: non-binding `let` without a type annotation
|
||||
--> $DIR/let_underscore_untyped.rs:35:5
|
||||
--> $DIR/let_underscore_untyped.rs:39:5
|
||||
|
|
||||
LL | let _ = d(&1);
|
||||
| ^^^^^^^^^^^^^^
|
||||
@ -32,7 +24,7 @@ LL | let _ = d(&1);
|
||||
= help: consider adding a type annotation or removing the `let` keyword
|
||||
|
||||
error: non-binding `let` without a type annotation
|
||||
--> $DIR/let_underscore_untyped.rs:36:5
|
||||
--> $DIR/let_underscore_untyped.rs:40:5
|
||||
|
|
||||
LL | let _ = e();
|
||||
| ^^^^^^^^^^^^
|
||||
@ -40,12 +32,12 @@ LL | let _ = e();
|
||||
= help: consider adding a type annotation or removing the `let` keyword
|
||||
|
||||
error: non-binding `let` without a type annotation
|
||||
--> $DIR/let_underscore_untyped.rs:37:5
|
||||
--> $DIR/let_underscore_untyped.rs:41:5
|
||||
|
|
||||
LL | let _ = f();
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider adding a type annotation or removing the `let` keyword
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user