Use Vec::with_capacity() as possible

This commit is contained in:
Yuki Okushi 2020-02-18 20:50:10 +09:00
parent 0da4dd009e
commit f4b80394d7
3 changed files with 3 additions and 3 deletions

View File

@ -359,7 +359,7 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
}
simplified.push(simple_negated);
}
let mut improvements = Vec::new();
let mut improvements = Vec::with_capacity(simplified.len());
'simplified: for suggestion in &simplified {
let simplified_stats = terminal_stats(suggestion);
let mut improvement = false;

View File

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

View File

@ -101,7 +101,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Shadow {
}
fn check_fn<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, decl: &'tcx FnDecl<'_>, body: &'tcx Body<'_>) {
let mut bindings = Vec::new();
let mut bindings = Vec::with_capacity(decl.inputs.len());
for arg in iter_input_pats(decl, body) {
if let PatKind::Binding(.., ident, _) = arg.pat.kind {
bindings.push((ident.name, ident.span))