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