Skip to content

Commit

Permalink
Some refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
giraffate authored and flip1995 committed Sep 10, 2020
1 parent 0117ea2 commit b80576f
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions clippy_lints/src/loops.rs
Expand Up @@ -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,
Expand All @@ -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) => {
Expand All @@ -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
Expand All @@ -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),
_ => {},
}
}
}
Expand Down

0 comments on commit b80576f

Please sign in to comment.