Skip to content

Commit f5715f7

Browse files
committed
Allow trailing commas in array patterns and attributes
1 parent 8d8f41b commit f5715f7

File tree

5 files changed

+26
-7
lines changed

5 files changed

+26
-7
lines changed

src/libsyntax/parse/attr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ impl<'a> ParserAttr for Parser<'a> {
212212
fn parse_meta_seq(&mut self) -> Vec<P<ast::MetaItem>> {
213213
self.parse_seq(&token::OpenDelim(token::Paren),
214214
&token::CloseDelim(token::Paren),
215-
seq_sep_trailing_disallowed(token::Comma),
215+
seq_sep_trailing_allowed(token::Comma),
216216
|p| p.parse_meta_item()).node
217217
}
218218

src/libsyntax/parse/common.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,13 @@ pub struct SeqSep {
1919
pub trailing_sep_allowed: bool
2020
}
2121

22-
pub fn seq_sep_trailing_disallowed(t: token::Token) -> SeqSep {
23-
SeqSep {
24-
sep: Some(t),
25-
trailing_sep_allowed: false,
26-
}
27-
}
2822
pub fn seq_sep_trailing_allowed(t: token::Token) -> SeqSep {
2923
SeqSep {
3024
sep: Some(t),
3125
trailing_sep_allowed: true,
3226
}
3327
}
28+
3429
pub fn seq_sep_none() -> SeqSep {
3530
SeqSep {
3631
sep: None,

src/libsyntax/parse/parser.rs

+5
Original file line numberDiff line numberDiff line change
@@ -3129,6 +3129,11 @@ impl<'a> Parser<'a> {
31293129
first = false;
31303130
} else {
31313131
self.expect(&token::Comma);
3132+
3133+
if self.token == token::CloseDelim(token::Bracket)
3134+
&& (before_slice || after.len() != 0) {
3135+
break
3136+
}
31323137
}
31333138

31343139
if before_slice {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
let [_, ..,] = [(), ()]; //~ ERROR unexpected token: `]`
13+
}

src/test/run-pass/trailing-comma.rs

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(advanced_slice_patterns,)]
12+
1113
fn f<T,>(_: T,) {}
1214

1315
struct Foo<T,>;
@@ -24,9 +26,13 @@ enum Baz {
2426
Qux(int,),
2527
}
2628

29+
#[allow(unused,)]
2730
pub fn main() {
2831
f::<int,>(0i,);
2932
let (_, _,) = (1i, 1i,);
33+
let [_, _,] = [1i, 1,];
34+
let [_, _, .., _,] = [1i, 1, 1, 1,];
35+
let [_, _, _.., _,] = [1i, 1, 1, 1,];
3036

3137
let x: Foo<int,> = Foo::<int,>;
3238

0 commit comments

Comments
 (0)