@@ -300,7 +300,7 @@ pub enum StaticFields {
300300
301301/// A summary of the possible sets of fields.
302302pub enum SubstructureFields < ' a > {
303- Struct ( Vec < FieldInfo < ' a > > ) ,
303+ Struct ( & ' a ast :: VariantData , Vec < FieldInfo < ' a > > ) ,
304304 /// Matching variants of the enum: variant index, ast::Variant,
305305 /// fields: the field name is only non-`None` in the case of a struct
306306 /// variant.
@@ -981,7 +981,7 @@ impl<'a> MethodDef<'a> {
981981 type_ident,
982982 self_args,
983983 nonself_args,
984- & Struct ( fields) ) ;
984+ & Struct ( struct_def , fields) ) ;
985985
986986 // make a series of nested matches, to destructure the
987987 // structs. This is actually right-to-left, but it shouldn't
@@ -1460,8 +1460,9 @@ impl<'a> TraitDef<'a> {
14601460 fields in generic `derive`") ,
14611461 // named fields
14621462 ( _, false ) => Named ( named_idents) ,
1463- // tuple structs (includes empty structs)
1464- ( _, _) => Unnamed ( just_spans)
1463+ // empty structs
1464+ _ if struct_def. is_struct ( ) => Named ( named_idents) ,
1465+ _ => Unnamed ( just_spans) ,
14651466 }
14661467 }
14671468
@@ -1486,7 +1487,11 @@ impl<'a> TraitDef<'a> {
14861487 P < Expr > ,
14871488 & ' a [ ast:: Attribute ] ) > ) {
14881489 if struct_def. fields ( ) . is_empty ( ) {
1489- return ( cx. pat_enum ( self . span , struct_path, vec ! [ ] ) , vec ! [ ] ) ;
1490+ if struct_def. is_struct ( ) {
1491+ return ( cx. pat_struct ( self . span , struct_path, vec ! [ ] ) , vec ! [ ] ) ;
1492+ } else {
1493+ return ( cx. pat_enum ( self . span , struct_path, vec ! [ ] ) , vec ! [ ] ) ;
1494+ }
14901495 }
14911496
14921497 let mut paths = Vec :: new ( ) ;
@@ -1521,7 +1526,7 @@ impl<'a> TraitDef<'a> {
15211526
15221527 // struct_type is definitely not Unknown, since struct_def.fields
15231528 // must be nonempty to reach here
1524- let pattern = if struct_type == Record {
1529+ let pattern = if struct_def . is_struct ( ) {
15251530 let field_pats = subpats. into_iter ( ) . zip ( & ident_expr)
15261531 . map ( |( pat, & ( _, id, _, _) ) | {
15271532 // id is guaranteed to be Some
@@ -1566,7 +1571,7 @@ pub fn cs_fold<F>(use_foldl: bool,
15661571 F : FnMut ( & mut ExtCtxt , Span , P < Expr > , P < Expr > , & [ P < Expr > ] ) -> P < Expr > ,
15671572{
15681573 match * substructure. fields {
1569- EnumMatching ( _, _, ref all_fields) | Struct ( ref all_fields) => {
1574+ EnumMatching ( _, _, ref all_fields) | Struct ( _ , ref all_fields) => {
15701575 if use_foldl {
15711576 all_fields. iter ( ) . fold ( base, |old, field| {
15721577 f ( cx,
@@ -1612,7 +1617,7 @@ pub fn cs_same_method<F>(f: F,
16121617 F : FnOnce ( & mut ExtCtxt , Span , Vec < P < Expr > > ) -> P < Expr > ,
16131618{
16141619 match * substructure. fields {
1615- EnumMatching ( _, _, ref all_fields) | Struct ( ref all_fields) => {
1620+ EnumMatching ( _, _, ref all_fields) | Struct ( _ , ref all_fields) => {
16161621 // call self_n.method(other_1_n, other_2_n, ...)
16171622 let called = all_fields. iter ( ) . map ( |field| {
16181623 cx. expr_method_call ( field. span ,
0 commit comments