Allow trailing commas in array patterns and attributes

This commit is contained in:
P1start 2014-11-30 17:39:50 +13:00
parent 8d8f41b75f
commit f5715f7867
5 changed files with 26 additions and 7 deletions

View File

@ -212,7 +212,7 @@ impl<'a> ParserAttr for Parser<'a> {
fn parse_meta_seq(&mut self) -> Vec<P<ast::MetaItem>> { fn parse_meta_seq(&mut self) -> Vec<P<ast::MetaItem>> {
self.parse_seq(&token::OpenDelim(token::Paren), self.parse_seq(&token::OpenDelim(token::Paren),
&token::CloseDelim(token::Paren), &token::CloseDelim(token::Paren),
seq_sep_trailing_disallowed(token::Comma), seq_sep_trailing_allowed(token::Comma),
|p| p.parse_meta_item()).node |p| p.parse_meta_item()).node
} }

View File

@ -19,18 +19,13 @@ pub struct SeqSep {
pub trailing_sep_allowed: bool pub trailing_sep_allowed: bool
} }
pub fn seq_sep_trailing_disallowed(t: token::Token) -> SeqSep {
SeqSep {
sep: Some(t),
trailing_sep_allowed: false,
}
}
pub fn seq_sep_trailing_allowed(t: token::Token) -> SeqSep { pub fn seq_sep_trailing_allowed(t: token::Token) -> SeqSep {
SeqSep { SeqSep {
sep: Some(t), sep: Some(t),
trailing_sep_allowed: true, trailing_sep_allowed: true,
} }
} }
pub fn seq_sep_none() -> SeqSep { pub fn seq_sep_none() -> SeqSep {
SeqSep { SeqSep {
sep: None, sep: None,

View File

@ -3129,6 +3129,11 @@ impl<'a> Parser<'a> {
first = false; first = false;
} else { } else {
self.expect(&token::Comma); self.expect(&token::Comma);
if self.token == token::CloseDelim(token::Bracket)
&& (before_slice || after.len() != 0) {
break
}
} }
if before_slice { if before_slice {

View File

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

View File

@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(advanced_slice_patterns,)]
fn f<T,>(_: T,) {} fn f<T,>(_: T,) {}
struct Foo<T,>; struct Foo<T,>;
@ -24,9 +26,13 @@ enum Baz {
Qux(int,), Qux(int,),
} }
#[allow(unused,)]
pub fn main() { pub fn main() {
f::<int,>(0i,); f::<int,>(0i,);
let (_, _,) = (1i, 1i,); let (_, _,) = (1i, 1i,);
let [_, _,] = [1i, 1,];
let [_, _, .., _,] = [1i, 1, 1, 1,];
let [_, _, _.., _,] = [1i, 1, 1, 1,];
let x: Foo<int,> = Foo::<int,>; let x: Foo<int,> = Foo::<int,>;