提交 26f2867c 编写于 作者: C Corey Richardson

rollup merge of #19413: P1start/more-trailing-commas

The only other place I know of that doesn’t allow trailing commas is closure types (#19414), and those are a bit tricky to fix (I suspect it might be impossible without infinite lookahead) so I didn’t implement that in this patch. There are other issues surrounding closure type parsing anyway, in particular #19410.
......@@ -212,7 +212,7 @@ fn parse_meta_item(&mut self) -> P<ast::MetaItem> {
fn parse_meta_seq(&mut self) -> Vec<P<ast::MetaItem>> {
self.parse_seq(&token::OpenDelim(token::Paren),
&token::CloseDelim(token::Paren),
seq_sep_trailing_disallowed(token::Comma),
seq_sep_trailing_allowed(token::Comma),
|p| p.parse_meta_item()).node
}
......
......@@ -19,18 +19,13 @@ pub struct SeqSep {
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 {
SeqSep {
sep: Some(t),
trailing_sep_allowed: true,
}
}
pub fn seq_sep_none() -> SeqSep {
SeqSep {
sep: None,
......
......@@ -3111,6 +3111,11 @@ fn parse_pat_vec_elements(
first = false;
} else {
self.expect(&token::Comma);
if self.token == token::CloseDelim(token::Bracket)
&& (before_slice || after.len() != 0) {
break
}
}
if before_slice {
......
// 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: `]`
}
......@@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(advanced_slice_patterns,)]
fn f<T,>(_: T,) {}
struct Foo<T,>;
......@@ -24,9 +26,13 @@ enum Baz {
Qux(int,),
}
#[allow(unused,)]
pub fn main() {
f::<int,>(0i,);
let (_, _,) = (1i, 1i,);
let [_, _,] = [1i, 1,];
let [_, _, .., _,] = [1i, 1, 1, 1,];
let [_, _, _.., _,] = [1i, 1, 1, 1,];
let x: Foo<int,> = Foo::<int,>;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册