Allow use of [_ ; n]
syntax for fixed length and repeating arrays.
This does NOT break any existing programs because the `[_, ..n]` syntax is also supported.
This commit is contained in:
parent
cbe9fb45bc
commit
2e86929a4a
122 changed files with 260 additions and 266 deletions
|
@ -1548,7 +1548,7 @@ impl<'a> Parser<'a> {
|
|||
self.expect(&token::OpenDelim(token::Bracket));
|
||||
let t = self.parse_ty_sum();
|
||||
|
||||
// Parse the `, ..e` in `[ int, ..e ]`
|
||||
// Parse the `; e` in `[ int; e ]`
|
||||
// where `e` is a const expression
|
||||
let t = match self.maybe_parse_fixed_vstore() {
|
||||
None => TyVec(t),
|
||||
|
@ -1716,6 +1716,9 @@ impl<'a> Parser<'a> {
|
|||
self.bump();
|
||||
self.bump();
|
||||
Some(self.parse_expr())
|
||||
} else if self.check(&token::Semi) {
|
||||
self.bump();
|
||||
Some(self.parse_expr())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
@ -2262,6 +2265,12 @@ impl<'a> Parser<'a> {
|
|||
let count = self.parse_expr();
|
||||
self.expect(&token::CloseDelim(token::Bracket));
|
||||
ex = ExprRepeat(first_expr, count);
|
||||
} else if self.check(&token::Semi) {
|
||||
// Repeating vector syntax: [ 0; 512 ]
|
||||
self.bump();
|
||||
let count = self.parse_expr();
|
||||
self.expect(&token::CloseDelim(token::Bracket));
|
||||
ex = ExprRepeat(first_expr, count);
|
||||
} else if self.check(&token::Comma) {
|
||||
// Vector with two or more elements.
|
||||
self.bump();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue