@@ -1031,14 +1031,16 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1031
1031
fn aggregate_field_ty (
1032
1032
& mut self ,
1033
1033
ak : & Box < AggregateKind < ' tcx > > ,
1034
- field : usize ,
1034
+ field_index : usize ,
1035
1035
location : Location ,
1036
1036
) -> Result < Ty < ' tcx > , FieldAccessError > {
1037
1037
let tcx = self . tcx ( ) ;
1038
1038
1039
1039
match * * ak {
1040
- AggregateKind :: Adt ( def, variant, substs, _) => {
1041
- if let Some ( field) = def. variants [ variant] . fields . get ( field) {
1040
+ AggregateKind :: Adt ( def, variant_index, substs, active_field_index) => {
1041
+ let variant = & def. variants [ variant_index] ;
1042
+ let adj_field_index = active_field_index. unwrap_or ( field_index) ;
1043
+ if let Some ( field) = variant. fields . get ( adj_field_index) {
1042
1044
Ok ( self . normalize ( & field. ty ( tcx, substs) , location) )
1043
1045
} else {
1044
1046
Err ( FieldAccessError :: OutOfRange {
@@ -1047,18 +1049,18 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1047
1049
}
1048
1050
}
1049
1051
AggregateKind :: Closure ( def_id, substs) => {
1050
- match substs. upvar_tys ( def_id, tcx) . nth ( field ) {
1052
+ match substs. upvar_tys ( def_id, tcx) . nth ( field_index ) {
1051
1053
Some ( ty) => Ok ( ty) ,
1052
1054
None => Err ( FieldAccessError :: OutOfRange {
1053
1055
field_count : substs. upvar_tys ( def_id, tcx) . count ( ) ,
1054
1056
} ) ,
1055
1057
}
1056
1058
}
1057
1059
AggregateKind :: Generator ( def_id, substs, _) => {
1058
- if let Some ( ty) = substs. upvar_tys ( def_id, tcx) . nth ( field ) {
1059
- Ok ( ty) ;
1060
+ if let Some ( ty) = substs. upvar_tys ( def_id, tcx) . nth ( field_index ) {
1061
+ Ok ( ty)
1060
1062
} else {
1061
- match substs. field_tys ( def_id, tcx) . nth ( field ) {
1063
+ match substs. field_tys ( def_id, tcx) . nth ( field_index ) {
1062
1064
Some ( ty) => Ok ( ty) ,
1063
1065
None => Err ( FieldAccessError :: OutOfRange {
1064
1066
field_count : substs. field_tys ( def_id, tcx) . count ( ) + 1 ,
0 commit comments