diff options
| author | bors <bors@rust-lang.org> | 2020-04-01 21:43:44 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-04-01 21:43:44 +0000 |
| commit | 7ebb3aa55dd2256def70e5df8a7c6c4b7ba53040 (patch) | |
| tree | 15a49c0b58157d2cd258f7d9c5f9ae99da8eb0a3 | |
| parent | 42796e11c5187be4e2ad962db17f333a52c3a88a (diff) | |
| parent | c9978b69bdd169777ec0befeeb75d2c7bd560526 (diff) | |
| download | rust-7ebb3aa55dd2256def70e5df8a7c6c4b7ba53040.tar.gz rust-7ebb3aa55dd2256def70e5df8a7c6c4b7ba53040.zip | |
Auto merge of #5402 - pmk21:allow-let-underscore-must-use, r=flip1995
Allow let_underscore_must_use to be ignored changelog: none Fixes #5366
| -rw-r--r-- | clippy_lints/src/let_underscore.rs | 13 | ||||
| -rw-r--r-- | tests/ui/let_underscore_must_use.rs | 3 |
2 files changed, 9 insertions, 7 deletions
diff --git a/clippy_lints/src/let_underscore.rs b/clippy_lints/src/let_underscore.rs index 1f5a6b77ed3..a68f7edd837 100644 --- a/clippy_lints/src/let_underscore.rs +++ b/clippy_lints/src/let_underscore.rs @@ -1,5 +1,5 @@ use if_chain::if_chain; -use rustc_hir::{PatKind, Stmt, StmtKind}; +use rustc_hir::{Local, PatKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::lint::in_external_macro; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -66,13 +66,12 @@ const SYNC_GUARD_PATHS: [&[&str]; 3] = [ ]; impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnderscore { - fn check_stmt(&mut self, cx: &LateContext<'_, '_>, stmt: &Stmt<'_>) { - if in_external_macro(cx.tcx.sess, stmt.span) { + fn check_local(&mut self, cx: &LateContext<'_, '_>, local: &Local<'_>) { + if in_external_macro(cx.tcx.sess, local.span) { return; } if_chain! { - if let StmtKind::Local(ref local) = stmt.kind; if let PatKind::Wild = local.pat.kind; if let Some(ref init) = local.init; then { @@ -81,7 +80,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnderscore { span_lint_and_help( cx, LET_UNDERSCORE_LOCK, - stmt.span, + local.span, "non-binding let on a synchronization lock", "consider using an underscore-prefixed named \ binding or dropping explicitly with `std::mem::drop`" @@ -90,7 +89,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnderscore { span_lint_and_help( cx, LET_UNDERSCORE_MUST_USE, - stmt.span, + local.span, "non-binding let on an expression with `#[must_use]` type", "consider explicitly using expression value" ) @@ -98,7 +97,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnderscore { span_lint_and_help( cx, LET_UNDERSCORE_MUST_USE, - stmt.span, + local.span, "non-binding let on a result of a `#[must_use]` function", "consider explicitly using function result" ) diff --git a/tests/ui/let_underscore_must_use.rs b/tests/ui/let_underscore_must_use.rs index 7f481542fa7..27dda606067 100644 --- a/tests/ui/let_underscore_must_use.rs +++ b/tests/ui/let_underscore_must_use.rs @@ -88,4 +88,7 @@ fn main() { let _ = a.map(|_| ()); let _ = a; + + #[allow(clippy::let_underscore_must_use)] + let _ = a; } |
