Allow trailing comma in vectors. Closes #2482.
This commit is contained in:
parent
bffb7db8ae
commit
8a730a255d
@ -805,7 +805,7 @@ class parser {
|
||||
self.bump();
|
||||
let mutbl = self.parse_mutability();
|
||||
let es = self.parse_seq_to_end(
|
||||
token::RBRACKET, seq_sep_trailing_disallowed(token::COMMA),
|
||||
token::RBRACKET, seq_sep_trailing_allowed(token::COMMA),
|
||||
{|p| p.parse_expr()});
|
||||
hi = self.span.hi;
|
||||
ex = expr_vec(es, mutbl);
|
||||
|
3
src/test/compile-fail/empty-vec-trailing-comma.rs
Normal file
3
src/test/compile-fail/empty-vec-trailing-comma.rs
Normal file
@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
let v = [,]; //! ERROR unexpected token: ','
|
||||
}
|
10
src/test/run-pass/vec-trailing-comma.rs
Normal file
10
src/test/run-pass/vec-trailing-comma.rs
Normal file
@ -0,0 +1,10 @@
|
||||
// Issue #2482.
|
||||
|
||||
fn main() {
|
||||
let v1: [int] = [10, 20, 30,];
|
||||
let v2: [int] = [10, 20, 30];
|
||||
assert (v1[2] == v2[2]);
|
||||
let v3: [int] = [10,];
|
||||
let v4: [int] = [10];
|
||||
assert (v3[0] == v4[0]);
|
||||
}
|
Loading…
Reference in New Issue
Block a user