@@ -20,7 +20,7 @@ use lint;
20
20
use middle:: cstore:: LOCAL_CRATE ;
21
21
use hir:: def:: Def ;
22
22
use hir:: def_id:: { CRATE_DEF_INDEX , DefId , DefIndex } ;
23
- use ty:: { self , TyCtxt } ;
23
+ use ty:: { self , TyCtxt , AdtKind } ;
24
24
use middle:: privacy:: AccessLevels ;
25
25
use syntax:: parse:: token:: InternedString ;
26
26
use syntax_pos:: { Span , DUMMY_SP } ;
@@ -561,49 +561,48 @@ pub fn check_expr<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, e: &hir::Expr,
561
561
hir:: ExprField ( ref base_e, ref field) => {
562
562
span = field. span ;
563
563
match tcx. expr_ty_adjusted ( base_e) . sty {
564
- ty:: TyStruct ( def , _ ) | ty :: TyUnion ( def, _) => {
564
+ ty:: TyAdt ( def, _) => {
565
565
def. struct_variant ( ) . field_named ( field. node ) . did
566
566
}
567
567
_ => span_bug ! ( e. span,
568
- "stability::check_expr: named field access on non-struct/union " )
568
+ "stability::check_expr: named field access on non-ADT " )
569
569
}
570
570
}
571
571
hir:: ExprTupField ( ref base_e, ref field) => {
572
572
span = field. span ;
573
573
match tcx. expr_ty_adjusted ( base_e) . sty {
574
- ty:: TyStruct ( def, _) => def. struct_variant ( ) . fields [ field. node ] . did ,
574
+ ty:: TyAdt ( def, _) => {
575
+ def. struct_variant ( ) . fields [ field. node ] . did
576
+ }
575
577
ty:: TyTuple ( ..) => return ,
576
578
_ => span_bug ! ( e. span,
577
579
"stability::check_expr: unnamed field access on \
578
580
something other than a tuple or struct")
579
581
}
580
582
}
581
583
hir:: ExprStruct ( _, ref expr_fields, _) => {
582
- let type_ = tcx. expr_ty ( e) ;
583
- match type_. sty {
584
- ty:: TyStruct ( def, _) | ty:: TyUnion ( def, _) => {
585
- // check the stability of each field that appears
586
- // in the construction expression.
587
- for field in expr_fields {
588
- let did = def. struct_variant ( )
589
- . field_named ( field. name . node )
590
- . did ;
591
- maybe_do_stability_check ( tcx, did, field. span , cb) ;
592
- }
584
+ match tcx. expr_ty ( e) . sty {
585
+ ty:: TyAdt ( adt, ..) => match adt. adt_kind ( ) {
586
+ AdtKind :: Struct | AdtKind :: Union => {
587
+ // check the stability of each field that appears
588
+ // in the construction expression.
589
+ for field in expr_fields {
590
+ let did = adt. struct_variant ( ) . field_named ( field. name . node ) . did ;
591
+ maybe_do_stability_check ( tcx, did, field. span , cb) ;
592
+ }
593
593
594
- // we're done.
595
- return
596
- }
597
- // we don't look at stability attributes on
598
- // struct-like enums (yet...), but it's definitely not
599
- // a bug to have construct one.
600
- ty:: TyEnum ( ..) => return ,
601
- _ => {
602
- span_bug ! ( e. span,
603
- "stability::check_expr: struct construction \
604
- of non-struct/union, type {:?}",
605
- type_) ;
606
- }
594
+ // we're done.
595
+ return
596
+ }
597
+ AdtKind :: Enum => {
598
+ // we don't look at stability attributes on
599
+ // struct-like enums (yet...), but it's definitely not
600
+ // a bug to have construct one.
601
+ return
602
+ }
603
+ } ,
604
+ ref ty => span_bug ! ( e. span, "stability::check_expr: struct \
605
+ construction of non-ADT type: {:?}", ty)
607
606
}
608
607
}
609
608
_ => return
@@ -648,10 +647,9 @@ pub fn check_pat<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, pat: &hir::Pat,
648
647
debug ! ( "check_pat(pat = {:?})" , pat) ;
649
648
if is_internal ( tcx, pat. span ) { return ; }
650
649
651
- let v = match tcx. pat_ty_opt ( pat) {
652
- Some ( & ty:: TyS { sty : ty:: TyStruct ( def, _) , .. } ) |
653
- Some ( & ty:: TyS { sty : ty:: TyUnion ( def, _) , .. } ) => def. struct_variant ( ) ,
654
- Some ( _) | None => return ,
650
+ let v = match tcx. pat_ty_opt ( pat) . map ( |ty| & ty. sty ) {
651
+ Some ( & ty:: TyAdt ( adt, _) ) if !adt. is_enum ( ) => adt. struct_variant ( ) ,
652
+ _ => return ,
655
653
} ;
656
654
match pat. node {
657
655
// Foo(a, b, c)
0 commit comments