about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser/expr.rs
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-01-14 18:45:28 +0100
committerGitHub <noreply@github.com>2023-01-14 18:45:28 +0100
commit9db8e6d5e9d6a4e87105ee556c54a4d30d1b261b (patch)
tree4b7b368f79d8eb348fc91f5cbcf0e56717a4e83c /compiler/rustc_parse/src/parser/expr.rs
parent14fbc214662c32be928479205154438ba58841ab (diff)
parentea13023b367d56ac3a8fcb72c9bbe636cf9ae1e7 (diff)
downloadrust-9db8e6d5e9d6a4e87105ee556c54a4d30d1b261b.tar.gz
rust-9db8e6d5e9d6a4e87105ee556c54a4d30d1b261b.zip
Rollup merge of #106849 - WaffleLapkin:unvec, r=Nilstrieb
Allocate one less vec while parsing arrays

Probably does not matter, but imo a little bit nicer.
Diffstat (limited to 'compiler/rustc_parse/src/parser/expr.rs')
-rw-r--r--compiler/rustc_parse/src/parser/expr.rs5
1 files changed, 2 insertions, 3 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs
index 645f8633941..d58afcd4c9f 100644
--- a/compiler/rustc_parse/src/parser/expr.rs
+++ b/compiler/rustc_parse/src/parser/expr.rs
@@ -1475,9 +1475,8 @@ impl<'a> Parser<'a> {
             } else if self.eat(&token::Comma) {
                 // Vector with two or more elements.
                 let sep = SeqSep::trailing_allowed(token::Comma);
-                let (remaining_exprs, _) = self.parse_seq_to_end(close, sep, |p| p.parse_expr())?;
-                let mut exprs = vec![first_expr];
-                exprs.extend(remaining_exprs);
+                let (mut exprs, _) = self.parse_seq_to_end(close, sep, |p| p.parse_expr())?;
+                exprs.insert(0, first_expr);
                 ExprKind::Array(exprs)
             } else {
                 // Vector with one element