@@ -604,11 +604,11 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
604604 }
605605 }
606606 }
607- hir:: ItemKind :: Enum ( ref enum_definition , _ ) => {
607+ hir:: ItemKind :: Enum ( .. ) => {
608608 tcx. ensure ( ) . generics_of ( def_id) ;
609609 tcx. ensure ( ) . type_of ( def_id) ;
610610 tcx. ensure ( ) . predicates_of ( def_id) ;
611- convert_enum_variant_types ( tcx, def_id. to_def_id ( ) , enum_definition . variants ) ;
611+ convert_enum_variant_types ( tcx, def_id. to_def_id ( ) ) ;
612612 }
613613 hir:: ItemKind :: Impl { .. } => {
614614 tcx. ensure ( ) . generics_of ( def_id) ;
@@ -640,7 +640,8 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
640640 }
641641
642642 if let Some ( ctor_hir_id) = struct_def. ctor_hir_id ( ) {
643- convert_variant_ctor ( tcx, ctor_hir_id) ;
643+ let ctor_def_id = tcx. hir ( ) . local_def_id ( ctor_hir_id) ;
644+ convert_variant_ctor ( tcx, ctor_def_id) ;
644645 }
645646 }
646647
@@ -750,55 +751,51 @@ fn convert_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) {
750751 }
751752}
752753
753- fn convert_variant_ctor ( tcx : TyCtxt < ' _ > , ctor_id : hir:: HirId ) {
754- let def_id = tcx. hir ( ) . local_def_id ( ctor_id) ;
754+ fn convert_variant_ctor ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) {
755755 tcx. ensure ( ) . generics_of ( def_id) ;
756756 tcx. ensure ( ) . type_of ( def_id) ;
757757 tcx. ensure ( ) . predicates_of ( def_id) ;
758758}
759759
760- fn convert_enum_variant_types ( tcx : TyCtxt < ' _ > , def_id : DefId , variants : & [ hir :: Variant < ' _ > ] ) {
760+ fn convert_enum_variant_types ( tcx : TyCtxt < ' _ > , def_id : DefId ) {
761761 let def = tcx. adt_def ( def_id) ;
762762 let repr_type = def. repr ( ) . discr_type ( ) ;
763763 let initial = repr_type. initial_discriminant ( tcx) ;
764764 let mut prev_discr = None :: < Discr < ' _ > > ;
765765
766766 // fill the discriminant values and field types
767- for variant in variants {
767+ for variant in def . variants ( ) {
768768 let wrapped_discr = prev_discr. map_or ( initial, |d| d. wrap_incr ( tcx) ) ;
769769 prev_discr = Some (
770- if let Some ( ref e) = variant. disr_expr {
771- let expr_did = tcx. hir ( ) . local_def_id ( e. hir_id ) ;
772- def. eval_explicit_discr ( tcx, expr_did. to_def_id ( ) )
770+ if let ty:: VariantDiscr :: Explicit ( const_def_id) = variant. discr {
771+ def. eval_explicit_discr ( tcx, const_def_id)
773772 } else if let Some ( discr) = repr_type. disr_incr ( tcx, prev_discr) {
774773 Some ( discr)
775774 } else {
776- struct_span_err ! ( tcx. sess, variant. span, E0370 , "enum discriminant overflowed" )
777- . span_label (
778- variant. span ,
779- format ! ( "overflowed on value after {}" , prev_discr. unwrap( ) ) ,
780- )
775+ let span = tcx. def_span ( variant. def_id ) ;
776+ struct_span_err ! ( tcx. sess, span, E0370 , "enum discriminant overflowed" )
777+ . span_label ( span, format ! ( "overflowed on value after {}" , prev_discr. unwrap( ) ) )
781778 . note ( & format ! (
782779 "explicitly set `{} = {}` if that is desired outcome" ,
783- variant. ident, wrapped_discr
780+ tcx. item_name( variant. def_id) ,
781+ wrapped_discr
784782 ) )
785783 . emit ( ) ;
786784 None
787785 }
788786 . unwrap_or ( wrapped_discr) ,
789787 ) ;
790788
791- for f in variant. data . fields ( ) {
792- let def_id = tcx. hir ( ) . local_def_id ( f. hir_id ) ;
793- tcx. ensure ( ) . generics_of ( def_id) ;
794- tcx. ensure ( ) . type_of ( def_id) ;
795- tcx. ensure ( ) . predicates_of ( def_id) ;
789+ for f in & variant. fields {
790+ tcx. ensure ( ) . generics_of ( f. did ) ;
791+ tcx. ensure ( ) . type_of ( f. did ) ;
792+ tcx. ensure ( ) . predicates_of ( f. did ) ;
796793 }
797794
798795 // Convert the ctor, if any. This also registers the variant as
799796 // an item.
800- if let Some ( ctor_hir_id ) = variant. data . ctor_hir_id ( ) {
801- convert_variant_ctor ( tcx, ctor_hir_id ) ;
797+ if let Some ( ctor_def_id ) = variant. ctor_def_id {
798+ convert_variant_ctor ( tcx, ctor_def_id . expect_local ( ) ) ;
802799 }
803800 }
804801}
0 commit comments