diff options
| author | Takayuki Nakata <f.seasons017@gmail.com> | 2020-09-08 08:34:51 +0900 |
|---|---|---|
| committer | flip1995 <hello@philkrones.com> | 2020-09-10 18:05:04 +0200 |
| commit | b80576fba633e1fc214c9f6900d7ca3424bda6d0 (patch) | |
| tree | 05f36218b3c6abbc496315b345faa29702608832 | |
| parent | 0117ea2b016133145f9e02e27421ac3672b42f57 (diff) | |
| download | rust-b80576fba633e1fc214c9f6900d7ca3424bda6d0.tar.gz rust-b80576fba633e1fc214c9f6900d7ca3424bda6d0.zip | |
Some refactoring
| -rw-r--r-- | clippy_lints/src/loops.rs | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index c27acdd2236..c59185bd7bd 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -1131,6 +1131,10 @@ fn detect_same_item_push<'tcx>( body: &'tcx Expr<'_>, _: &'tcx Expr<'_>, ) { + if !matches!(pat.kind, PatKind::Wild) { + return; + } + // Determine whether it is safe to lint the body let mut same_item_push_visitor = SameItemPushVisitor { should_lint: true, @@ -1149,8 +1153,8 @@ fn detect_same_item_push<'tcx>( .map_or(false, |id| implements_trait(cx, ty, id, &[])) { // Make sure that the push does not involve possibly mutating values - if let PatKind::Wild = pat.kind { - if let ExprKind::Path(ref qpath) = pushed_item.kind { + match pushed_item.kind { + ExprKind::Path(ref qpath) => { match qpath_res(cx, qpath, pushed_item.hir_id) { // immutable bindings that are initialized with literal or constant Res::Local(hir_id) => { @@ -1161,7 +1165,7 @@ fn detect_same_item_push<'tcx>( if !matches!(bind_ann, BindingAnnotation::RefMut | BindingAnnotation::Mutable); let parent_node = cx.tcx.hir().get_parent_node(hir_id); if let Some(Node::Local(parent_let_expr)) = cx.tcx.hir().find(parent_node); - if let rustc_hir::Local { init: Some(init), .. } = parent_let_expr; + if let Some(init) = parent_let_expr.init; then { match init.kind { // immutable bindings that are initialized with literal @@ -1181,10 +1185,9 @@ fn detect_same_item_push<'tcx>( Res::Def(DefKind::Const, ..) => emit_lint(cx, vec, pushed_item), _ => {}, } - } else if let ExprKind::Lit(..) = pushed_item.kind { - // literal - emit_lint(cx, vec, pushed_item); - } + }, + ExprKind::Lit(..) => emit_lint(cx, vec, pushed_item), + _ => {}, } } } |
