@@ -20,7 +20,7 @@ use lint;
2020use middle:: cstore:: LOCAL_CRATE ;
2121use hir:: def:: Def ;
2222use hir:: def_id:: { CRATE_DEF_INDEX , DefId , DefIndex } ;
23- use ty:: { self , TyCtxt } ;
23+ use ty:: { self , TyCtxt , AdtKind } ;
2424use middle:: privacy:: AccessLevels ;
2525use syntax:: parse:: token:: InternedString ;
2626use syntax_pos:: { Span , DUMMY_SP } ;
@@ -561,49 +561,48 @@ pub fn check_expr<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, e: &hir::Expr,
561561 hir:: ExprField ( ref base_e, ref field) => {
562562 span = field. span ;
563563 match tcx. expr_ty_adjusted ( base_e) . sty {
564- ty:: TyStruct ( def , _ ) | ty :: TyUnion ( def, _) => {
564+ ty:: TyAdt ( def, _) => {
565565 def. struct_variant ( ) . field_named ( field. node ) . did
566566 }
567567 _ => 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 " )
569569 }
570570 }
571571 hir:: ExprTupField ( ref base_e, ref field) => {
572572 span = field. span ;
573573 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+ }
575577 ty:: TyTuple ( ..) => return ,
576578 _ => span_bug ! ( e. span,
577579 "stability::check_expr: unnamed field access on \
578580 something other than a tuple or struct")
579581 }
580582 }
581583 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+ }
593593
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)
607606 }
608607 }
609608 _ => return
@@ -648,10 +647,9 @@ pub fn check_pat<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, pat: &hir::Pat,
648647 debug ! ( "check_pat(pat = {:?})" , pat) ;
649648 if is_internal ( tcx, pat. span ) { return ; }
650649
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 ,
655653 } ;
656654 match pat. node {
657655 // Foo(a, b, c)
0 commit comments