about summary refs log tree commit diff
path: root/src/libsyntax/parse
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-09-13 13:09:22 +0000
committerbors <bors@rust-lang.org>2015-09-13 13:09:22 +0000
commit9040b06ed28d37022d7c5135a6809aba951a243e (patch)
treea149621f28ca9bc64f653523421b664585177a77 /src/libsyntax/parse
parentfd230ff12481ebeba720fb1ac1f610d93bb74920 (diff)
parentc87a58fe4b5c2f64ecd1ad3697bdb0403c76af4c (diff)
downloadrust-9040b06ed28d37022d7c5135a6809aba951a243e.tar.gz
rust-9040b06ed28d37022d7c5135a6809aba951a243e.zip
Auto merge of #28286 - matklad:remove-dead-code, r=eddyb
There is a dead code in libsyntax/parser/parse.rs, when parsing structs.

Two functions are involved:

* [parse_item_struct](https://github.com/rust-lang/rust/blob/cd9c9f048f6aa0be091cd9835771ba0712bead4e/src/libsyntax/parse/parser.rs#L4691)
* [parse_tuple_struct_body](https://github.com/rust-lang/rust/blob/cd9c9f048f6aa0be091cd9835771ba0712bead4e/src/libsyntax/parse/parser.rs#L4769)

The problem is that both functions handle the case with unit structs. But because
`parse_tuple_struct_body` is called from `parse_item_struct`, it never faces
this case.

This PR removes unit struct case from `parse_tuple_struct_body` function. I tested with `make -j8 check-statge1`.
Diffstat (limited to 'src/libsyntax/parse')
-rw-r--r--src/libsyntax/parse/parser.rs69
1 files changed, 31 insertions, 38 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 56641a9ba27..2308787bf67 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -4723,9 +4723,13 @@ impl<'a> Parser<'a> {
             let fields = try!(self.parse_record_struct_body(&class_name));
             (fields, None)
         // Tuple-style struct definition with optional where-clause.
-        } else {
+        } else if self.token == token::OpenDelim(token::Paren) {
             let fields = try!(self.parse_tuple_struct_body(&class_name, &mut generics));
             (fields, Some(ast::DUMMY_NODE_ID))
+        } else {
+            let token_str = self.this_token_to_string();
+            return Err(self.fatal(&format!("expected `where`, `{{`, `(`, or `;` after struct \
+                                            name, found `{}`", token_str)))
         };
 
         Ok((class_name,
@@ -4753,8 +4757,8 @@ impl<'a> Parser<'a> {
             try!(self.bump());
         } else {
             let token_str = self.this_token_to_string();
-            return Err(self.fatal(&format!("expected `where`, or `{}` after struct \
-                                name, found `{}`", "{",
+            return Err(self.fatal(&format!("expected `where`, or `{{` after struct \
+                                name, found `{}`",
                                 token_str)));
         }
 
@@ -4766,43 +4770,32 @@ impl<'a> Parser<'a> {
                                    generics: &mut ast::Generics)
                                    -> PResult<Vec<StructField>> {
         // This is the case where we find `struct Foo<T>(T) where T: Copy;`
-        if self.check(&token::OpenDelim(token::Paren)) {
-            let fields = try!(self.parse_unspanned_seq(
-                &token::OpenDelim(token::Paren),
-                &token::CloseDelim(token::Paren),
-                seq_sep_trailing_allowed(token::Comma),
-                |p| {
-                    let attrs = p.parse_outer_attributes();
-                    let lo = p.span.lo;
-                    let struct_field_ = ast::StructField_ {
-                        kind: UnnamedField(try!(p.parse_visibility())),
-                        id: ast::DUMMY_NODE_ID,
-                        ty: try!(p.parse_ty_sum()),
-                        attrs: attrs,
-                    };
-                    Ok(spanned(lo, p.span.hi, struct_field_))
-                }));
-
-            if fields.is_empty() {
-                return Err(self.fatal(&format!("unit-like struct definition should be \
-                    written as `struct {};`",
-                    class_name)));
-            }
+        // Unit like structs are handled in parse_item_struct function
+        let fields = try!(self.parse_unspanned_seq(
+            &token::OpenDelim(token::Paren),
+            &token::CloseDelim(token::Paren),
+            seq_sep_trailing_allowed(token::Comma),
+            |p| {
+                let attrs = p.parse_outer_attributes();
+                let lo = p.span.lo;
+                let struct_field_ = ast::StructField_ {
+                    kind: UnnamedField(try!(p.parse_visibility())),
+                    id: ast::DUMMY_NODE_ID,
+                    ty: try!(p.parse_ty_sum()),
+                    attrs: attrs,
+                };
+                Ok(spanned(lo, p.span.hi, struct_field_))
+            }));
 
-            generics.where_clause = try!(self.parse_where_clause());
-            try!(self.expect(&token::Semi));
-            Ok(fields)
-        // This is the case where we just see struct Foo<T> where T: Copy;
-        } else if self.token.is_keyword(keywords::Where) {
-            generics.where_clause = try!(self.parse_where_clause());
-            try!(self.expect(&token::Semi));
-            Ok(Vec::new())
-        // This case is where we see: `struct Foo<T>;`
-        } else {
-            let token_str = self.this_token_to_string();
-            Err(self.fatal(&format!("expected `where`, `{}`, `(`, or `;` after struct \
-                name, found `{}`", "{", token_str)))
+        if fields.is_empty() {
+            return Err(self.fatal(&format!("unit-like struct definition should be \
+                                            written as `struct {};`",
+                                           class_name)));
         }
+
+        generics.where_clause = try!(self.parse_where_clause());
+        try!(self.expect(&token::Semi));
+        Ok(fields)
     }
 
     /// Parse a structure field declaration