diff options
| author | Takayuki Nakata <f.seasons017@gmail.com> | 2020-09-08 23:12:04 +0900 |
|---|---|---|
| committer | flip1995 <hello@philkrones.com> | 2020-09-10 18:05:04 +0200 |
| commit | 730ca457f580247667ed0cd5965bc08752ebc0b3 (patch) | |
| tree | 9dd95f3c39d721d5585af90f29e37be2da2a7be4 | |
| parent | 2972ad3ef661071531a61ec8999b668a6b734b74 (diff) | |
| download | rust-730ca457f580247667ed0cd5965bc08752ebc0b3.tar.gz rust-730ca457f580247667ed0cd5965bc08752ebc0b3.zip | |
Address `items_after_statement`
| -rw-r--r-- | clippy_lints/src/loops.rs | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index c59185bd7bd..6c54c07869a 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -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; } @@ -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. |
