From 695114ea2c1ae147dcf1c3ac690a75ecf928b8b2 Mon Sep 17 00:00:00 2001 From: Laurent Bonnans Date: Sun, 16 Mar 2014 16:07:39 +0100 Subject: rustc: disallow trailing parentheses for nullary enum variants Fixes #12560 --- src/libsyntax/parse/parser.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src/libsyntax/parse') 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( + &mut self, + bra: &token::Token, + ket: &token::Token, + sep: SeqSep, + f: |&mut Parser| -> T) + -> Vec { + 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( @@ -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), -- cgit 1.4.1-3-g733a5