diff options
| author | Laurent Bonnans <bonnans.l@gmail.com> | 2014-03-16 16:07:39 +0100 |
|---|---|---|
| committer | Laurent Bonnans <bonnans.l@gmail.com> | 2014-03-17 12:11:22 +0100 |
| commit | 695114ea2c1ae147dcf1c3ac690a75ecf928b8b2 (patch) | |
| tree | 611c536d3cb01ae1bf7f123f4d05469d17428597 /src/libsyntax/parse/parser.rs | |
| parent | e4c91e6c7cfc03246a422576ab41ac74125fd3b8 (diff) | |
| download | rust-695114ea2c1ae147dcf1c3ac690a75ecf928b8b2.tar.gz rust-695114ea2c1ae147dcf1c3ac690a75ecf928b8b2.zip | |
rustc: disallow trailing parentheses for nullary enum variants
Fixes #12560
Diffstat (limited to 'src/libsyntax/parse/parser.rs')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 27c86956499..e1a02d5240f 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -713,6 +713,23 @@ impl<'a> Parser<'a> { result } + // parse a sequence parameter of enum variant. For consistency purposes, + // these should not be empty. + pub fn parse_enum_variant_seq<T>( + &mut self, + bra: &token::Token, + ket: &token::Token, + sep: SeqSep, + f: |&mut Parser| -> T) + -> Vec<T> { + let result = self.parse_unspanned_seq(bra, ket, sep, f); + if result.is_empty() { + self.span_err(self.last_span, + "nullary enum variants are written with no trailing `( )`"); + } + result + } + // NB: Do not use this function unless you actually plan to place the // spanned list in the AST. pub fn parse_seq<T>( @@ -3013,7 +3030,7 @@ impl<'a> Parser<'a> { self.expect(&token::RPAREN); pat = PatEnum(enum_path, None); } else { - args = self.parse_unspanned_seq( + args = self.parse_enum_variant_seq( &token::LPAREN, &token::RPAREN, seq_sep_trailing_disallowed(token::COMMA), @@ -4431,7 +4448,7 @@ impl<'a> Parser<'a> { kind = StructVariantKind(self.parse_struct_def()); } else if self.token == token::LPAREN { all_nullary = false; - let arg_tys = self.parse_unspanned_seq( + let arg_tys = self.parse_enum_variant_seq( &token::LPAREN, &token::RPAREN, seq_sep_trailing_disallowed(token::COMMA), |
