diff options
| author | F3real <stefan92ff@yandex.com> | 2021-08-11 23:46:13 +0200 |
|---|---|---|
| committer | F3real <stefan92ff@yandex.com> | 2021-08-12 01:05:41 +0200 |
| commit | 979ce29086fb6bde6ac88700e1b4072d68739564 (patch) | |
| tree | 0a25bc641944702dbd88db417c3227a702ec3843 /clippy_lints | |
| parent | b1b38604f23b3a51620e2f9454353eb2fbf028a3 (diff) | |
| download | rust-979ce29086fb6bde6ac88700e1b4072d68739564.tar.gz rust-979ce29086fb6bde6ac88700e1b4072d68739564.zip | |
Correctly report inclusive range in no_effect lint
Diffstat (limited to 'clippy_lints')
| -rw-r--r-- | clippy_lints/src/no_effect.rs | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/clippy_lints/src/no_effect.rs b/clippy_lints/src/no_effect.rs index e07518b2586..28e9e6f438e 100644 --- a/clippy_lints/src/no_effect.rs +++ b/clippy_lints/src/no_effect.rs @@ -3,7 +3,7 @@ use clippy_utils::source::snippet_opt; use clippy_utils::ty::has_drop; use rustc_errors::Applicability; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::{BinOpKind, BlockCheckMode, Expr, ExprKind, Stmt, StmtKind, UnsafeSource}; +use rustc_hir::{is_range_literal, BinOpKind, BlockCheckMode, Expr, ExprKind, Stmt, StmtKind, UnsafeSource}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use std::ops::Deref; @@ -68,12 +68,14 @@ fn has_no_effect(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { ExprKind::Call(callee, args) => { if let ExprKind::Path(ref qpath) = callee.kind { let res = cx.qpath_res(qpath, callee.hir_id); - match res { - Res::Def(DefKind::Struct | DefKind::Variant | DefKind::Ctor(..), ..) => { - !has_drop(cx, cx.typeck_results().expr_ty(expr)) - && args.iter().all(|arg| has_no_effect(cx, arg)) - }, - _ => false, + let def_matched = matches!( + res, + Res::Def(DefKind::Struct | DefKind::Variant | DefKind::Ctor(..), ..) + ); + if def_matched || is_range_literal(expr) { + !has_drop(cx, cx.typeck_results().expr_ty(expr)) && args.iter().all(|arg| has_no_effect(cx, arg)) + } else { + false } } else { false |
