about summary refs log tree commit diff
path: root/src/libsyntax/parse/parser.rs
diff options
context:
space:
mode:
authorLaurent Bonnans <bonnans.l@gmail.com>2014-03-16 16:07:39 +0100
committerLaurent Bonnans <bonnans.l@gmail.com>2014-03-17 12:11:22 +0100
commit695114ea2c1ae147dcf1c3ac690a75ecf928b8b2 (patch)
tree611c536d3cb01ae1bf7f123f4d05469d17428597 /src/libsyntax/parse/parser.rs
parente4c91e6c7cfc03246a422576ab41ac74125fd3b8 (diff)
downloadrust-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.rs21
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),