@@ -604,11 +604,11 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
604
604
}
605
605
}
606
606
}
607
- hir:: ItemKind :: Enum ( ref enum_definition , _ ) => {
607
+ hir:: ItemKind :: Enum ( .. ) => {
608
608
tcx. ensure ( ) . generics_of ( def_id) ;
609
609
tcx. ensure ( ) . type_of ( def_id) ;
610
610
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 ( ) ) ;
612
612
}
613
613
hir:: ItemKind :: Impl { .. } => {
614
614
tcx. ensure ( ) . generics_of ( def_id) ;
@@ -640,7 +640,8 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
640
640
}
641
641
642
642
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) ;
644
645
}
645
646
}
646
647
@@ -750,55 +751,51 @@ fn convert_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) {
750
751
}
751
752
}
752
753
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 ) {
755
755
tcx. ensure ( ) . generics_of ( def_id) ;
756
756
tcx. ensure ( ) . type_of ( def_id) ;
757
757
tcx. ensure ( ) . predicates_of ( def_id) ;
758
758
}
759
759
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 ) {
761
761
let def = tcx. adt_def ( def_id) ;
762
762
let repr_type = def. repr ( ) . discr_type ( ) ;
763
763
let initial = repr_type. initial_discriminant ( tcx) ;
764
764
let mut prev_discr = None :: < Discr < ' _ > > ;
765
765
766
766
// fill the discriminant values and field types
767
- for variant in variants {
767
+ for variant in def . variants ( ) {
768
768
let wrapped_discr = prev_discr. map_or ( initial, |d| d. wrap_incr ( tcx) ) ;
769
769
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)
773
772
} else if let Some ( discr) = repr_type. disr_incr ( tcx, prev_discr) {
774
773
Some ( discr)
775
774
} 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( ) ) )
781
778
. note ( & format ! (
782
779
"explicitly set `{} = {}` if that is desired outcome" ,
783
- variant. ident, wrapped_discr
780
+ tcx. item_name( variant. def_id) ,
781
+ wrapped_discr
784
782
) )
785
783
. emit ( ) ;
786
784
None
787
785
}
788
786
. unwrap_or ( wrapped_discr) ,
789
787
) ;
790
788
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 ) ;
796
793
}
797
794
798
795
// Convert the ctor, if any. This also registers the variant as
799
796
// 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 ( ) ) ;
802
799
}
803
800
}
804
801
}
0 commit comments