about summary refs log tree commit diff
path: root/src/libsyntax/parse/parser.rs
diff options
context:
space:
mode:
authorJared Roesch <roeschinc@gmail.com>2015-01-02 04:02:50 -0800
committerJared Roesch <roeschinc@gmail.com>2015-01-04 17:33:31 -0800
commitc54932cb12b8384060bfe132907ec42cc5c1bbd2 (patch)
tree36aa67b40ae1533aeee70a76f5a3b0b0491c8bb0 /src/libsyntax/parse/parser.rs
parent5773bdefff2e47cc007f5cc2af3f80b30303d45a (diff)
downloadrust-c54932cb12b8384060bfe132907ec42cc5c1bbd2.tar.gz
rust-c54932cb12b8384060bfe132907ec42cc5c1bbd2.zip
Fix the parsing of where-clauses for structs
Diffstat (limited to 'src/libsyntax/parse/parser.rs')
-rw-r--r--src/libsyntax/parse/parser.rs24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 37ac86a3324..570ef67bbcc 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -4875,11 +4875,26 @@ impl<'a> Parser<'a> {
             self.span_err(ty.span, "`virtual` structs have been removed from the language");
         }
 
-        self.parse_where_clause(&mut generics);
-
         let mut fields: Vec<StructField>;
         let is_tuple_like;
 
+        // There is a special case worth noting here, as reported in issue #17904.
+        // If we are parsing a tuple struct it is the case that the where clause
+        // should follow the field list. Like so:
+        //
+        // struct Foo<T>(T) where T: Copy;
+        //
+        // If we are parsing a normal record-style struct it is the case
+        // that the where clause comes before the body, and after the generics.
+        // So if we look ahead and see a brace or a where-clause we begin
+        // parsing a record style struct.
+        //
+        // Otherwise if we look ahead and see a paren we parse a tuple-style
+        // struct.
+
+        // Will parse the where-clause if it precedes the brace.
+        self.parse_where_clause(&mut generics);
+
         if self.eat(&token::OpenDelim(token::Brace)) {
             // It's a record-like struct.
             is_tuple_like = false;
@@ -4916,8 +4931,11 @@ impl<'a> Parser<'a> {
                                     written as `struct {};`",
                                    token::get_ident(class_name))[]);
             }
+            self.parse_where_clause(&mut generics);
             self.expect(&token::Semi);
-        } else if self.eat(&token::Semi) {
+        } else if self.token.is_keyword(keywords::Where) || self.eat(&token::Semi) {
+            // We can find a where clause here.
+            self.parse_where_clause(&mut generics);
             // It's a unit-like struct.
             is_tuple_like = true;
             fields = Vec::new();