@@ -1031,13 +1031,13 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1031
1031
1032
1032
fn aggregate_field_ty (
1033
1033
& mut self ,
1034
- ak : & Box < AggregateKind < ' tcx > > ,
1034
+ ak : & AggregateKind < ' tcx > ,
1035
1035
field_index : usize ,
1036
1036
location : Location ,
1037
1037
) -> Result < Ty < ' tcx > , FieldAccessError > {
1038
1038
let tcx = self . tcx ( ) ;
1039
1039
1040
- match * * ak {
1040
+ match * ak {
1041
1041
AggregateKind :: Adt ( def, variant_index, substs, active_field_index) => {
1042
1042
let variant = & def. variants [ variant_index] ;
1043
1043
let adj_field_index = active_field_index. unwrap_or ( field_index) ;
@@ -1069,56 +1069,17 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1069
1069
}
1070
1070
}
1071
1071
}
1072
- AggregateKind :: Array ( ty) => {
1073
- Ok ( ty)
1074
- }
1072
+ AggregateKind :: Array ( ty) => Ok ( ty) ,
1075
1073
AggregateKind :: Tuple => {
1076
1074
unreachable ! ( "This should have been covered in check_rvalues" ) ;
1077
1075
}
1078
1076
}
1079
1077
}
1080
1078
1081
- fn check_rvalue ( & mut self , mir : & Mir < ' tcx > , rv : & Rvalue < ' tcx > , location : Location ) {
1082
- let tcx = self . tcx ( ) ;
1083
- match rv {
1079
+ fn check_rvalue ( & mut self , mir : & Mir < ' tcx > , rvalue : & Rvalue < ' tcx > , location : Location ) {
1080
+ match rvalue {
1084
1081
Rvalue :: Aggregate ( ak, ops) => {
1085
- match * * ak {
1086
- // tuple rvalue field type is always the type of the op. Nothing to check here.
1087
- AggregateKind :: Tuple => { }
1088
- _ => {
1089
- for ( i, op) in ops. iter ( ) . enumerate ( ) {
1090
- let field_ty = match self . aggregate_field_ty ( ak, i, location) {
1091
- Ok ( field_ty) => field_ty,
1092
- Err ( FieldAccessError :: OutOfRange { field_count } ) => {
1093
- span_mirbug ! (
1094
- self ,
1095
- rv,
1096
- "accessed field #{} but variant only has {}" ,
1097
- i,
1098
- field_count
1099
- ) ;
1100
- continue ;
1101
- }
1102
- } ;
1103
- let op_ty = op. ty ( mir, tcx) ;
1104
- if let Err ( terr) = self . sub_types (
1105
- op_ty,
1106
- field_ty,
1107
- location. at_successor_within_block ( ) ,
1108
- )
1109
- {
1110
- span_mirbug ! (
1111
- self ,
1112
- rv,
1113
- "{:?} is not a subtype of {:?}: {:?}" ,
1114
- op_ty,
1115
- field_ty,
1116
- terr
1117
- ) ;
1118
- }
1119
- }
1120
- }
1121
- }
1082
+ self . check_aggregate_rvalue ( mir, rvalue, ak, ops, location)
1122
1083
}
1123
1084
// FIXME: These other cases have to be implemented in future PRs
1124
1085
Rvalue :: Use ( ..) |
@@ -1134,6 +1095,52 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1134
1095
}
1135
1096
}
1136
1097
1098
+ fn check_aggregate_rvalue (
1099
+ & mut self ,
1100
+ mir : & Mir < ' tcx > ,
1101
+ rvalue : & Rvalue < ' tcx > ,
1102
+ aggregate_kind : & AggregateKind < ' tcx > ,
1103
+ operands : & [ Operand < ' tcx > ] ,
1104
+ location : Location ,
1105
+ ) {
1106
+ match aggregate_kind {
1107
+ // tuple rvalue field type is always the type of the op. Nothing to check here.
1108
+ AggregateKind :: Tuple => return ,
1109
+ _ => { }
1110
+ }
1111
+
1112
+ let tcx = self . tcx ( ) ;
1113
+
1114
+ for ( i, operand) in operands. iter ( ) . enumerate ( ) {
1115
+ let field_ty = match self . aggregate_field_ty ( aggregate_kind, i, location) {
1116
+ Ok ( field_ty) => field_ty,
1117
+ Err ( FieldAccessError :: OutOfRange { field_count } ) => {
1118
+ span_mirbug ! (
1119
+ self ,
1120
+ rvalue,
1121
+ "accessed field #{} but variant only has {}" ,
1122
+ i,
1123
+ field_count
1124
+ ) ;
1125
+ continue ;
1126
+ }
1127
+ } ;
1128
+ let operand_ty = operand. ty ( mir, tcx) ;
1129
+ if let Err ( terr) =
1130
+ self . sub_types ( operand_ty, field_ty, location. at_successor_within_block ( ) )
1131
+ {
1132
+ span_mirbug ! (
1133
+ self ,
1134
+ rvalue,
1135
+ "{:?} is not a subtype of {:?}: {:?}" ,
1136
+ operand_ty,
1137
+ field_ty,
1138
+ terr
1139
+ ) ;
1140
+ }
1141
+ }
1142
+ }
1143
+
1137
1144
fn typeck_mir ( & mut self , mir : & Mir < ' tcx > ) {
1138
1145
self . last_span = mir. span ;
1139
1146
debug ! ( "run_on_mir: {:?}" , mir. span) ;
0 commit comments