@@ -300,7 +300,7 @@ pub enum StaticFields {
300
300
301
301
/// A summary of the possible sets of fields.
302
302
pub enum SubstructureFields < ' a > {
303
- Struct ( Vec < FieldInfo < ' a > > ) ,
303
+ Struct ( & ' a ast :: VariantData , Vec < FieldInfo < ' a > > ) ,
304
304
/// Matching variants of the enum: variant index, ast::Variant,
305
305
/// fields: the field name is only non-`None` in the case of a struct
306
306
/// variant.
@@ -981,7 +981,7 @@ impl<'a> MethodDef<'a> {
981
981
type_ident,
982
982
self_args,
983
983
nonself_args,
984
- & Struct ( fields) ) ;
984
+ & Struct ( struct_def , fields) ) ;
985
985
986
986
// make a series of nested matches, to destructure the
987
987
// structs. This is actually right-to-left, but it shouldn't
@@ -1460,8 +1460,9 @@ impl<'a> TraitDef<'a> {
1460
1460
fields in generic `derive`") ,
1461
1461
// named fields
1462
1462
( _, 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) ,
1465
1466
}
1466
1467
}
1467
1468
@@ -1486,7 +1487,11 @@ impl<'a> TraitDef<'a> {
1486
1487
P < Expr > ,
1487
1488
& ' a [ ast:: Attribute ] ) > ) {
1488
1489
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
+ }
1490
1495
}
1491
1496
1492
1497
let mut paths = Vec :: new ( ) ;
@@ -1521,7 +1526,7 @@ impl<'a> TraitDef<'a> {
1521
1526
1522
1527
// struct_type is definitely not Unknown, since struct_def.fields
1523
1528
// must be nonempty to reach here
1524
- let pattern = if struct_type == Record {
1529
+ let pattern = if struct_def . is_struct ( ) {
1525
1530
let field_pats = subpats. into_iter ( ) . zip ( & ident_expr)
1526
1531
. map ( |( pat, & ( _, id, _, _) ) | {
1527
1532
// id is guaranteed to be Some
@@ -1566,7 +1571,7 @@ pub fn cs_fold<F>(use_foldl: bool,
1566
1571
F : FnMut ( & mut ExtCtxt , Span , P < Expr > , P < Expr > , & [ P < Expr > ] ) -> P < Expr > ,
1567
1572
{
1568
1573
match * substructure. fields {
1569
- EnumMatching ( _, _, ref all_fields) | Struct ( ref all_fields) => {
1574
+ EnumMatching ( _, _, ref all_fields) | Struct ( _ , ref all_fields) => {
1570
1575
if use_foldl {
1571
1576
all_fields. iter ( ) . fold ( base, |old, field| {
1572
1577
f ( cx,
@@ -1612,7 +1617,7 @@ pub fn cs_same_method<F>(f: F,
1612
1617
F : FnOnce ( & mut ExtCtxt , Span , Vec < P < Expr > > ) -> P < Expr > ,
1613
1618
{
1614
1619
match * substructure. fields {
1615
- EnumMatching ( _, _, ref all_fields) | Struct ( ref all_fields) => {
1620
+ EnumMatching ( _, _, ref all_fields) | Struct ( _ , ref all_fields) => {
1616
1621
// call self_n.method(other_1_n, other_2_n, ...)
1617
1622
let called = all_fields. iter ( ) . map ( |field| {
1618
1623
cx. expr_method_call ( field. span ,
0 commit comments