@@ -4686,18 +4686,21 @@ impl<'a> Parser<'a> {
4686
4686
VariantData :: Unit ( ast:: DUMMY_NODE_ID )
4687
4687
} else {
4688
4688
// If we see: `struct Foo<T> where T: Copy { ... }`
4689
- VariantData :: Struct ( try!( self . parse_record_struct_body ( ) ) , ast:: DUMMY_NODE_ID )
4689
+ VariantData :: Struct ( try!( self . parse_record_struct_body ( true ) ) , ast:: DUMMY_NODE_ID )
4690
4690
}
4691
4691
// No `where` so: `struct Foo<T>;`
4692
4692
} else if try!( self . eat ( & token:: Semi ) ) {
4693
4693
VariantData :: Unit ( ast:: DUMMY_NODE_ID )
4694
4694
// Record-style struct definition
4695
4695
} else if self . token == token:: OpenDelim ( token:: Brace ) {
4696
- VariantData :: Struct ( try!( self . parse_record_struct_body ( ) ) , ast:: DUMMY_NODE_ID )
4696
+ VariantData :: Struct ( try!( self . parse_record_struct_body ( true ) ) , ast:: DUMMY_NODE_ID )
4697
4697
// Tuple-style struct definition with optional where-clause.
4698
4698
} else if self . token == token:: OpenDelim ( token:: Paren ) {
4699
- VariantData :: Tuple ( try!( self . parse_tuple_struct_body ( & mut generics) ) ,
4700
- ast:: DUMMY_NODE_ID )
4699
+ let body = VariantData :: Tuple ( try!( self . parse_tuple_struct_body ( true ) ) ,
4700
+ ast:: DUMMY_NODE_ID ) ;
4701
+ generics. where_clause = try!( self . parse_where_clause ( ) ) ;
4702
+ try!( self . expect ( & token:: Semi ) ) ;
4703
+ body
4701
4704
} else {
4702
4705
let token_str = self . this_token_to_string ( ) ;
4703
4706
return Err ( self . fatal ( & format ! ( "expected `where`, `{{`, `(`, or `;` after struct \
@@ -4707,11 +4710,11 @@ impl<'a> Parser<'a> {
4707
4710
Ok ( ( class_name, ItemStruct ( vdata, generics) , None ) )
4708
4711
}
4709
4712
4710
- pub fn parse_record_struct_body ( & mut self ) -> PResult < Vec < StructField > > {
4713
+ pub fn parse_record_struct_body ( & mut self , allow_pub : bool ) -> PResult < Vec < StructField > > {
4711
4714
let mut fields = Vec :: new ( ) ;
4712
4715
if try!( self . eat ( & token:: OpenDelim ( token:: Brace ) ) ) {
4713
4716
while self . token != token:: CloseDelim ( token:: Brace ) {
4714
- fields. push ( try!( self . parse_struct_decl_field ( true ) ) ) ;
4717
+ fields. push ( try!( self . parse_struct_decl_field ( allow_pub ) ) ) ;
4715
4718
}
4716
4719
4717
4720
try!( self . bump ( ) ) ;
@@ -4725,9 +4728,7 @@ impl<'a> Parser<'a> {
4725
4728
Ok ( fields)
4726
4729
}
4727
4730
4728
- pub fn parse_tuple_struct_body ( & mut self ,
4729
- generics : & mut ast:: Generics )
4730
- -> PResult < Vec < StructField > > {
4731
+ pub fn parse_tuple_struct_body ( & mut self , allow_pub : bool ) -> PResult < Vec < StructField > > {
4731
4732
// This is the case where we find `struct Foo<T>(T) where T: Copy;`
4732
4733
// Unit like structs are handled in parse_item_struct function
4733
4734
let fields = try!( self . parse_unspanned_seq (
@@ -4738,16 +4739,16 @@ impl<'a> Parser<'a> {
4738
4739
let attrs = try!( p. parse_outer_attributes ( ) ) ;
4739
4740
let lo = p. span . lo ;
4740
4741
let struct_field_ = ast:: StructField_ {
4741
- kind : UnnamedField ( try!( p. parse_visibility ( ) ) ) ,
4742
+ kind : UnnamedField (
4743
+ if allow_pub { try!( p. parse_visibility ( ) ) } else { Inherited }
4744
+ ) ,
4742
4745
id : ast:: DUMMY_NODE_ID ,
4743
4746
ty : try!( p. parse_ty_sum ( ) ) ,
4744
4747
attrs : attrs,
4745
4748
} ;
4746
4749
Ok ( spanned ( lo, p. span . hi , struct_field_) )
4747
4750
} ) ) ;
4748
4751
4749
- generics. where_clause = try!( self . parse_where_clause ( ) ) ;
4750
- try!( self . expect ( & token:: Semi ) ) ;
4751
4752
Ok ( fields)
4752
4753
}
4753
4754
@@ -5133,18 +5134,6 @@ impl<'a> Parser<'a> {
5133
5134
Ok ( ( ident, ItemTy ( ty, tps) , None ) )
5134
5135
}
5135
5136
5136
- /// Parse a structure-like enum variant definition
5137
- /// this should probably be renamed or refactored...
5138
- fn parse_struct_def ( & mut self ) -> PResult < VariantData > {
5139
- let mut fields: Vec < StructField > = Vec :: new ( ) ;
5140
- while self . token != token:: CloseDelim ( token:: Brace ) {
5141
- fields. push ( try!( self . parse_struct_decl_field ( false ) ) ) ;
5142
- }
5143
- try!( self . bump ( ) ) ;
5144
-
5145
- Ok ( VariantData :: Struct ( fields, ast:: DUMMY_NODE_ID ) )
5146
- }
5147
-
5148
5137
/// Parse the part of an "enum" decl following the '{'
5149
5138
fn parse_enum_def ( & mut self , _generics : & ast:: Generics ) -> PResult < EnumDef > {
5150
5139
let mut variants = Vec :: new ( ) ;
@@ -5157,34 +5146,21 @@ impl<'a> Parser<'a> {
5157
5146
let struct_def;
5158
5147
let mut disr_expr = None ;
5159
5148
let ident = try!( self . parse_ident ( ) ) ;
5160
- if try! ( self . eat ( & token:: OpenDelim ( token:: Brace ) ) ) {
5149
+ if self . check ( & token:: OpenDelim ( token:: Brace ) ) {
5161
5150
// Parse a struct variant.
5162
5151
all_nullary = false ;
5163
- struct_def = try!( self . parse_struct_def ( ) ) ;
5152
+ struct_def = VariantData :: Struct ( try!( self . parse_record_struct_body ( false ) ) ,
5153
+ ast:: DUMMY_NODE_ID ) ;
5164
5154
} else if self . check ( & token:: OpenDelim ( token:: Paren ) ) {
5165
5155
all_nullary = false ;
5166
- let arg_tys = try!( self . parse_enum_variant_seq (
5167
- & token:: OpenDelim ( token:: Paren ) ,
5168
- & token:: CloseDelim ( token:: Paren ) ,
5169
- seq_sep_trailing_allowed ( token:: Comma ) ,
5170
- |p| p. parse_ty_sum ( )
5171
- ) ) ;
5172
- let mut fields = Vec :: new ( ) ;
5173
- for ty in arg_tys {
5174
- fields. push ( Spanned { span : ty. span , node : ast:: StructField_ {
5175
- ty : ty,
5176
- kind : ast:: UnnamedField ( ast:: Inherited ) ,
5177
- attrs : Vec :: new ( ) ,
5178
- id : ast:: DUMMY_NODE_ID ,
5179
- } } ) ;
5180
- }
5181
- struct_def = ast:: VariantData :: Tuple ( fields, ast:: DUMMY_NODE_ID ) ;
5156
+ struct_def = VariantData :: Tuple ( try!( self . parse_tuple_struct_body ( false ) ) ,
5157
+ ast:: DUMMY_NODE_ID ) ;
5182
5158
} else if try!( self . eat ( & token:: Eq ) ) {
5183
5159
disr_expr = Some ( try!( self . parse_expr_nopanic ( ) ) ) ;
5184
5160
any_disr = disr_expr. as_ref ( ) . map ( |expr| expr. span ) ;
5185
- struct_def = ast :: VariantData :: Unit ( ast:: DUMMY_NODE_ID ) ;
5161
+ struct_def = VariantData :: Unit ( ast:: DUMMY_NODE_ID ) ;
5186
5162
} else {
5187
- struct_def = ast :: VariantData :: Unit ( ast:: DUMMY_NODE_ID ) ;
5163
+ struct_def = VariantData :: Unit ( ast:: DUMMY_NODE_ID ) ;
5188
5164
}
5189
5165
5190
5166
let vr = ast:: Variant_ {
0 commit comments