@@ -1012,23 +1012,27 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1012
1012
}
1013
1013
}
1014
1014
1015
- fn aggregate_field_ty ( & mut self , ak : & Box < AggregateKind < ' tcx > > , field : usize , location : Location )
1016
- -> Result < Ty < ' tcx > , FieldAccessError >
1017
- {
1015
+ fn aggregate_field_ty (
1016
+ & mut self ,
1017
+ ak : & Box < AggregateKind < ' tcx > > ,
1018
+ field : usize ,
1019
+ location : Location ,
1020
+ ) -> Result < Ty < ' tcx > , FieldAccessError > {
1018
1021
let tcx = self . tcx ( ) ;
1019
1022
1020
1023
let ( variant, substs) = match * * ak {
1021
- AggregateKind :: Adt ( def, variant, substs, _) => { // handle unions?
1024
+ AggregateKind :: Adt ( def, variant, substs, _) => {
1025
+ // handle unions?
1022
1026
( & def. variants [ variant] , substs)
1023
- } ,
1027
+ }
1024
1028
AggregateKind :: Closure ( def_id, substs) => {
1025
1029
return match substs. upvar_tys ( def_id, tcx) . nth ( field) {
1026
1030
Some ( ty) => Ok ( ty) ,
1027
1031
None => Err ( FieldAccessError :: OutOfRange {
1028
- field_count : substs. upvar_tys ( def_id, tcx) . count ( )
1032
+ field_count : substs. upvar_tys ( def_id, tcx) . count ( ) ,
1029
1033
} ) ,
1030
1034
}
1031
- } ,
1035
+ }
1032
1036
AggregateKind :: Generator ( def_id, substs, _) => {
1033
1037
if let Some ( ty) = substs. upvar_tys ( def_id, tcx) . nth ( field) {
1034
1038
return Ok ( ty) ;
@@ -1037,22 +1041,24 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1037
1041
return match substs. field_tys ( def_id, tcx) . nth ( field) {
1038
1042
Some ( ty) => Ok ( ty) ,
1039
1043
None => Err ( FieldAccessError :: OutOfRange {
1040
- field_count : substs. field_tys ( def_id, tcx) . count ( ) + 1
1044
+ field_count : substs. field_tys ( def_id, tcx) . count ( ) + 1 ,
1041
1045
} ) ,
1042
- }
1043
- } ,
1046
+ } ;
1047
+ }
1044
1048
AggregateKind :: Array ( ty) => {
1045
1049
return Ok ( ty) ;
1046
- } ,
1050
+ }
1047
1051
AggregateKind :: Tuple => {
1048
1052
unreachable ! ( "This should have been covered in check_rvalues" ) ;
1049
- } ,
1053
+ }
1050
1054
} ;
1051
1055
1052
1056
if let Some ( field) = variant. fields . get ( field) {
1053
1057
Ok ( self . normalize ( & field. ty ( tcx, substs) , location) )
1054
1058
} else {
1055
- Err ( FieldAccessError :: OutOfRange { field_count : variant. fields . len ( ) } )
1059
+ Err ( FieldAccessError :: OutOfRange {
1060
+ field_count : variant. fields . len ( ) ,
1061
+ } )
1056
1062
}
1057
1063
}
1058
1064
@@ -1062,7 +1068,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1062
1068
Rvalue :: Aggregate ( ak, ops) => {
1063
1069
match * * ak {
1064
1070
// tuple rvalue field type is always the type of the op. Nothing to check here.
1065
- AggregateKind :: Tuple => { } ,
1071
+ AggregateKind :: Tuple => { }
1066
1072
_ => {
1067
1073
for ( i, op) in ops. iter ( ) . enumerate ( ) {
1068
1074
let field_ty = match self . aggregate_field_ty ( ak, i, location) {
@@ -1073,27 +1079,36 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1073
1079
rv,
1074
1080
"accessed field #{} but variant only has {}" ,
1075
1081
i,
1076
- field_count) ;
1082
+ field_count
1083
+ ) ;
1077
1084
continue ;
1078
- } ,
1085
+ }
1079
1086
} ;
1080
1087
let op_ty = match op {
1081
- Operand :: Consume ( lv) => lv. ty ( mir, tcx) . to_ty ( tcx) ,
1088
+ Operand :: Consume ( lv) => {
1089
+ self . normalize ( & lv. ty ( mir, tcx) , location) . to_ty ( tcx)
1090
+ }
1082
1091
Operand :: Constant ( c) => c. ty ,
1083
1092
} ;
1084
- if let Err ( terr) = self . sub_types ( op_ty, field_ty, location. at_successor_within_block ( ) ) {
1085
- span_mirbug ! (
1093
+ if let Err ( terr) = self . sub_types (
1094
+ op_ty,
1095
+ field_ty,
1096
+ location. at_successor_within_block ( ) ,
1097
+ )
1098
+ {
1099
+ span_mirbug ! (
1086
1100
self ,
1087
1101
rv,
1088
1102
"{:?} is not a subtype of {:?}: {:?}" ,
1089
1103
op_ty,
1090
1104
field_ty,
1091
- terr) ;
1092
- }
1105
+ terr
1106
+ ) ;
1107
+ }
1093
1108
}
1094
- } ,
1109
+ }
1095
1110
}
1096
- } ,
1111
+ }
1097
1112
// FIXME: These other cases have to be implemented in future PRs
1098
1113
Rvalue :: Use ( ..) |
1099
1114
Rvalue :: Repeat ( ..) |
@@ -1104,7 +1119,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1104
1119
Rvalue :: CheckedBinaryOp ( ..) |
1105
1120
Rvalue :: UnaryOp ( ..) |
1106
1121
Rvalue :: Discriminant ( ..) |
1107
- Rvalue :: NullaryOp ( ..) => { }
1122
+ Rvalue :: NullaryOp ( ..) => { }
1108
1123
}
1109
1124
}
1110
1125
0 commit comments