@@ -1036,13 +1036,18 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1036
1036
) -> Result < Ty < ' tcx > , FieldAccessError > {
1037
1037
let tcx = self . tcx ( ) ;
1038
1038
1039
- let ( variant , substs ) = match * * ak {
1039
+ match * * ak {
1040
1040
AggregateKind :: Adt ( def, variant, substs, _) => {
1041
- // handle unions?
1042
- ( & def. variants [ variant] , substs)
1041
+ if let Some ( field) = def. variants [ variant] . fields . get ( field) {
1042
+ Ok ( self . normalize ( & field. ty ( tcx, substs) , location) )
1043
+ } else {
1044
+ Err ( FieldAccessError :: OutOfRange {
1045
+ field_count : variant. fields . len ( ) ,
1046
+ } )
1047
+ }
1043
1048
}
1044
1049
AggregateKind :: Closure ( def_id, substs) => {
1045
- return match substs. upvar_tys ( def_id, tcx) . nth ( field) {
1050
+ match substs. upvar_tys ( def_id, tcx) . nth ( field) {
1046
1051
Some ( ty) => Ok ( ty) ,
1047
1052
None => Err ( FieldAccessError :: OutOfRange {
1048
1053
field_count : substs. upvar_tys ( def_id, tcx) . count ( ) ,
@@ -1051,30 +1056,22 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1051
1056
}
1052
1057
AggregateKind :: Generator ( def_id, substs, _) => {
1053
1058
if let Some ( ty) = substs. upvar_tys ( def_id, tcx) . nth ( field) {
1054
- return Ok ( ty) ;
1059
+ Ok ( ty) ;
1060
+ } else {
1061
+ match substs. field_tys ( def_id, tcx) . nth ( field) {
1062
+ Some ( ty) => Ok ( ty) ,
1063
+ None => Err ( FieldAccessError :: OutOfRange {
1064
+ field_count : substs. field_tys ( def_id, tcx) . count ( ) + 1 ,
1065
+ } ) ,
1066
+ }
1055
1067
}
1056
-
1057
- return match substs. field_tys ( def_id, tcx) . nth ( field) {
1058
- Some ( ty) => Ok ( ty) ,
1059
- None => Err ( FieldAccessError :: OutOfRange {
1060
- field_count : substs. field_tys ( def_id, tcx) . count ( ) + 1 ,
1061
- } ) ,
1062
- } ;
1063
1068
}
1064
1069
AggregateKind :: Array ( ty) => {
1065
- return Ok ( ty) ;
1070
+ Ok ( ty)
1066
1071
}
1067
1072
AggregateKind :: Tuple => {
1068
1073
unreachable ! ( "This should have been covered in check_rvalues" ) ;
1069
1074
}
1070
- } ;
1071
-
1072
- if let Some ( field) = variant. fields . get ( field) {
1073
- Ok ( self . normalize ( & field. ty ( tcx, substs) , location) )
1074
- } else {
1075
- Err ( FieldAccessError :: OutOfRange {
1076
- field_count : variant. fields . len ( ) ,
1077
- } )
1078
1075
}
1079
1076
}
1080
1077
0 commit comments