Skip to content

Commit f4b8039

Browse files
committed
Use Vec::with_capacity() as possible
1 parent 0da4dd0 commit f4b8039

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

clippy_lints/src/booleans.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
359359
}
360360
simplified.push(simple_negated);
361361
}
362-
let mut improvements = Vec::new();
362+
let mut improvements = Vec::with_capacity(simplified.len());
363363
'simplified: for suggestion in &simplified {
364364
let simplified_stats = terminal_stats(suggestion);
365365
let mut improvement = false;

clippy_lints/src/matches.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ fn is_panic_block(block: &Block<'_>) -> bool {
724724

725725
fn check_match_ref_pats(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>) {
726726
if has_only_ref_pats(arms) {
727-
let mut suggs = Vec::new();
727+
let mut suggs = Vec::with_capacity(arms.len() + 1);
728728
let (title, msg) = if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, ref inner) = ex.kind {
729729
let span = ex.span.source_callsite();
730730
suggs.push((span, Sugg::hir_with_macro_callsite(cx, inner, "..").to_string()));

clippy_lints/src/shadow.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Shadow {
101101
}
102102

103103
fn check_fn<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, decl: &'tcx FnDecl<'_>, body: &'tcx Body<'_>) {
104-
let mut bindings = Vec::new();
104+
let mut bindings = Vec::with_capacity(decl.inputs.len());
105105
for arg in iter_input_pats(decl, body) {
106106
if let PatKind::Binding(.., ident, _) = arg.pat.kind {
107107
bindings.push((ident.name, ident.span))

0 commit comments

Comments
 (0)