Skip to content

Commit

Permalink
Address items_after_statement
Browse files Browse the repository at this point in the history
  • Loading branch information
giraffate committed Sep 8, 2020
1 parent 952c046 commit 1d8ae3a
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions clippy_lints/src/loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,23 @@ fn detect_same_item_push<'tcx>(
body: &'tcx Expr<'_>,
_: &'tcx Expr<'_>,
) {
fn emit_lint(cx: &LateContext<'_>, vec: &Expr<'_>, pushed_item: &Expr<'_>) {
let vec_str = snippet_with_macro_callsite(cx, vec.span, "");
let item_str = snippet_with_macro_callsite(cx, pushed_item.span, "");

span_lint_and_help(
cx,
SAME_ITEM_PUSH,
vec.span,
"it looks like the same item is being pushed into this Vec",
None,
&format!(
"try using vec![{};SIZE] or {}.resize(NEW_SIZE, {})",
item_str, vec_str, item_str
),
)
}

if !matches!(pat.kind, PatKind::Wild) {
return;
}
Expand Down Expand Up @@ -1192,23 +1209,6 @@ fn detect_same_item_push<'tcx>(
}
}
}

fn emit_lint(cx: &LateContext<'_>, vec: &Expr<'_>, pushed_item: &Expr<'_>) {
let vec_str = snippet_with_macro_callsite(cx, vec.span, "");
let item_str = snippet_with_macro_callsite(cx, pushed_item.span, "");

span_lint_and_help(
cx,
SAME_ITEM_PUSH,
vec.span,
"it looks like the same item is being pushed into this Vec",
None,
&format!(
"try using vec![{};SIZE] or {}.resize(NEW_SIZE, {})",
item_str, vec_str, item_str
),
)
}
}

/// Checks for looping over a range and then indexing a sequence with it.
Expand Down

0 comments on commit 1d8ae3a

Please sign in to comment.