@@ -4723,9 +4723,13 @@ impl<'a> Parser<'a> {
4723
4723
let fields = try!( self . parse_record_struct_body ( & class_name) ) ;
4724
4724
( fields, None )
4725
4725
// Tuple-style struct definition with optional where-clause.
4726
- } else {
4726
+ } else if self . token == token :: OpenDelim ( token :: Paren ) {
4727
4727
let fields = try!( self . parse_tuple_struct_body ( & class_name, & mut generics) ) ;
4728
4728
( fields, Some ( ast:: DUMMY_NODE_ID ) )
4729
+ } else {
4730
+ let token_str = self . this_token_to_string ( ) ;
4731
+ return Err ( self . fatal ( & format ! ( "expected `where`, `{{`, `(`, or `;` after struct \
4732
+ name, found `{}`", token_str) ) )
4729
4733
} ;
4730
4734
4731
4735
Ok ( ( class_name,
@@ -4753,8 +4757,8 @@ impl<'a> Parser<'a> {
4753
4757
try!( self . bump ( ) ) ;
4754
4758
} else {
4755
4759
let token_str = self . this_token_to_string ( ) ;
4756
- return Err ( self . fatal ( & format ! ( "expected `where`, or `{} ` after struct \
4757
- name, found `{}`", "{" ,
4760
+ return Err ( self . fatal ( & format ! ( "expected `where`, or `{{ ` after struct \
4761
+ name, found `{}`",
4758
4762
token_str) ) ) ;
4759
4763
}
4760
4764
@@ -4766,43 +4770,32 @@ impl<'a> Parser<'a> {
4766
4770
generics : & mut ast:: Generics )
4767
4771
-> PResult < Vec < StructField > > {
4768
4772
// This is the case where we find `struct Foo<T>(T) where T: Copy;`
4769
- if self . check ( & token:: OpenDelim ( token:: Paren ) ) {
4770
- let fields = try!( self . parse_unspanned_seq (
4771
- & token:: OpenDelim ( token:: Paren ) ,
4772
- & token:: CloseDelim ( token:: Paren ) ,
4773
- seq_sep_trailing_allowed ( token:: Comma ) ,
4774
- |p| {
4775
- let attrs = p. parse_outer_attributes ( ) ;
4776
- let lo = p. span . lo ;
4777
- let struct_field_ = ast:: StructField_ {
4778
- kind : UnnamedField ( try!( p. parse_visibility ( ) ) ) ,
4779
- id : ast:: DUMMY_NODE_ID ,
4780
- ty : try!( p. parse_ty_sum ( ) ) ,
4781
- attrs : attrs,
4782
- } ;
4783
- Ok ( spanned ( lo, p. span . hi , struct_field_) )
4784
- } ) ) ;
4785
-
4786
- if fields. is_empty ( ) {
4787
- return Err ( self . fatal ( & format ! ( "unit-like struct definition should be \
4788
- written as `struct {};`",
4789
- class_name) ) ) ;
4790
- }
4773
+ // Unit like structs are handled in parse_item_struct function
4774
+ let fields = try!( self . parse_unspanned_seq (
4775
+ & token:: OpenDelim ( token:: Paren ) ,
4776
+ & token:: CloseDelim ( token:: Paren ) ,
4777
+ seq_sep_trailing_allowed ( token:: Comma ) ,
4778
+ |p| {
4779
+ let attrs = p. parse_outer_attributes ( ) ;
4780
+ let lo = p. span . lo ;
4781
+ let struct_field_ = ast:: StructField_ {
4782
+ kind : UnnamedField ( try!( p. parse_visibility ( ) ) ) ,
4783
+ id : ast:: DUMMY_NODE_ID ,
4784
+ ty : try!( p. parse_ty_sum ( ) ) ,
4785
+ attrs : attrs,
4786
+ } ;
4787
+ Ok ( spanned ( lo, p. span . hi , struct_field_) )
4788
+ } ) ) ;
4791
4789
4792
- generics. where_clause = try!( self . parse_where_clause ( ) ) ;
4793
- try!( self . expect ( & token:: Semi ) ) ;
4794
- Ok ( fields)
4795
- // This is the case where we just see struct Foo<T> where T: Copy;
4796
- } else if self . token . is_keyword ( keywords:: Where ) {
4797
- generics. where_clause = try!( self . parse_where_clause ( ) ) ;
4798
- try!( self . expect ( & token:: Semi ) ) ;
4799
- Ok ( Vec :: new ( ) )
4800
- // This case is where we see: `struct Foo<T>;`
4801
- } else {
4802
- let token_str = self . this_token_to_string ( ) ;
4803
- Err ( self . fatal ( & format ! ( "expected `where`, `{}`, `(`, or `;` after struct \
4804
- name, found `{}`", "{" , token_str) ) )
4790
+ if fields. is_empty ( ) {
4791
+ return Err ( self . fatal ( & format ! ( "unit-like struct definition should be \
4792
+ written as `struct {};`",
4793
+ class_name) ) ) ;
4805
4794
}
4795
+
4796
+ generics. where_clause = try!( self . parse_where_clause ( ) ) ;
4797
+ try!( self . expect ( & token:: Semi ) ) ;
4798
+ Ok ( fields)
4806
4799
}
4807
4800
4808
4801
/// Parse a structure field declaration
0 commit comments