@@ -17,7 +17,7 @@ use rustc::infer::region_constraints::RegionConstraintData;
17
17
use rustc:: traits:: { self , FulfillmentContext } ;
18
18
use rustc:: ty:: error:: TypeError ;
19
19
use rustc:: ty:: fold:: TypeFoldable ;
20
- use rustc:: ty:: { self , Ty , TyCtxt , TypeVariants , ToPolyTraitRef } ;
20
+ use rustc:: ty:: { self , ToPolyTraitRef , Ty , TyCtxt , TypeVariants } ;
21
21
use rustc:: middle:: const_val:: ConstVal ;
22
22
use rustc:: mir:: * ;
23
23
use rustc:: mir:: tcx:: PlaceTy ;
@@ -193,13 +193,11 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
193
193
assert_eq ! ( def_id, ty_def_id) ;
194
194
substs
195
195
}
196
- _ => {
197
- span_bug ! (
198
- self . last_span,
199
- "unexpected type for constant function: {:?}" ,
200
- value. ty
201
- )
202
- }
196
+ _ => span_bug ! (
197
+ self . last_span,
198
+ "unexpected type for constant function: {:?}" ,
199
+ value. ty
200
+ ) ,
203
201
} ;
204
202
205
203
let instantiated_predicates =
@@ -585,12 +583,8 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
585
583
span_mirbug ! ( self , "" , "errors selecting obligation: {:?}" , e) ;
586
584
}
587
585
588
- self . infcx . process_registered_region_obligations (
589
- & [ ] ,
590
- None ,
591
- self . param_env ,
592
- self . body_id ,
593
- ) ;
586
+ self . infcx
587
+ . process_registered_region_obligations ( & [ ] , None , self . param_env , self . body_id ) ;
594
588
595
589
let data = self . infcx . take_and_reset_region_constraints ( ) ;
596
590
if !data. is_empty ( ) {
@@ -1164,18 +1158,16 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1164
1158
self . check_aggregate_rvalue ( mir, rvalue, ak, ops, location)
1165
1159
}
1166
1160
1167
- Rvalue :: Repeat ( operand, const_usize) => {
1168
- if const_usize. as_u64 ( ) > 1 {
1169
- let operand_ty = operand. ty ( mir, tcx) ;
1161
+ Rvalue :: Repeat ( operand, const_usize) => if const_usize. as_u64 ( ) > 1 {
1162
+ let operand_ty = operand. ty ( mir, tcx) ;
1170
1163
1171
- let trait_ref = ty:: TraitRef {
1172
- def_id : tcx. lang_items ( ) . copy_trait ( ) . unwrap ( ) ,
1173
- substs : tcx. mk_substs_trait ( operand_ty, & [ ] ) ,
1174
- } ;
1164
+ let trait_ref = ty:: TraitRef {
1165
+ def_id : tcx. lang_items ( ) . copy_trait ( ) . unwrap ( ) ,
1166
+ substs : tcx. mk_substs_trait ( operand_ty, & [ ] ) ,
1167
+ } ;
1175
1168
1176
- self . prove_trait_ref ( trait_ref, location) ;
1177
- }
1178
- }
1169
+ self . prove_trait_ref ( trait_ref, location) ;
1170
+ } ,
1179
1171
1180
1172
Rvalue :: NullaryOp ( _, ty) => {
1181
1173
let trait_ref = ty:: TraitRef {
@@ -1186,50 +1178,87 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1186
1178
self . prove_trait_ref ( trait_ref, location) ;
1187
1179
}
1188
1180
1189
- Rvalue :: Cast ( cast_kind, op, ty) => {
1190
- match cast_kind {
1191
- CastKind :: ReifyFnPointer => {
1192
- let ty_fn_ptr_from = tcx. mk_fn_ptr ( op. ty ( mir, tcx) . fn_sig ( tcx) ) ;
1181
+ Rvalue :: Cast ( cast_kind, op, ty) => match cast_kind {
1182
+ CastKind :: ReifyFnPointer => {
1183
+ let fn_sig = op. ty ( mir, tcx) . fn_sig ( tcx) ;
1193
1184
1194
- if let Err ( terr) = self . eq_types ( ty_fn_ptr_from, ty, location. at_self ( ) ) {
1195
- span_mirbug ! ( self , "" , "casting {:?}" , terr) ;
1196
- }
1197
- }
1185
+ // The type that we see in the fcx is like
1186
+ // `foo::<'a, 'b>`, where `foo` is the path to a
1187
+ // function definition. When we extract the
1188
+ // signature, it comes from the `fn_sig` query,
1189
+ // and hence may contain unnormalized results.
1190
+ let fn_sig = self . normalize ( & fn_sig, location) ;
1198
1191
1199
- CastKind :: ClosureFnPointer => {
1200
- let sig = match op. ty ( mir, tcx) . sty {
1201
- ty:: TyClosure ( def_id, substs) => {
1202
- substs. closure_sig_ty ( def_id, tcx) . fn_sig ( tcx)
1203
- }
1204
- _ => bug ! ( ) ,
1205
- } ;
1206
- let ty_fn_ptr_from = tcx. coerce_closure_fn_ty ( sig) ;
1192
+ let ty_fn_ptr_from = tcx. mk_fn_ptr ( fn_sig) ;
1207
1193
1208
- if let Err ( terr) = self . eq_types ( ty_fn_ptr_from, ty, location. at_self ( ) ) {
1209
- span_mirbug ! ( self , "" , "casting {:?}" , terr) ;
1210
- }
1194
+ if let Err ( terr) = self . eq_types ( ty_fn_ptr_from, ty, location. at_self ( ) ) {
1195
+ span_mirbug ! (
1196
+ self ,
1197
+ rvalue,
1198
+ "equating {:?} with {:?} yields {:?}" ,
1199
+ ty_fn_ptr_from,
1200
+ ty,
1201
+ terr
1202
+ ) ;
1211
1203
}
1204
+ }
1212
1205
1213
- CastKind :: UnsafeFnPointer => {
1214
- let ty_fn_ptr_from = tcx. safe_to_unsafe_fn_ty ( op. ty ( mir, tcx) . fn_sig ( tcx) ) ;
1215
-
1216
- if let Err ( terr) = self . eq_types ( ty_fn_ptr_from, ty, location. at_self ( ) ) {
1217
- span_mirbug ! ( self , "" , "casting {:?}" , terr) ;
1206
+ CastKind :: ClosureFnPointer => {
1207
+ let sig = match op. ty ( mir, tcx) . sty {
1208
+ ty:: TyClosure ( def_id, substs) => {
1209
+ substs. closure_sig_ty ( def_id, tcx) . fn_sig ( tcx)
1218
1210
}
1211
+ _ => bug ! ( ) ,
1212
+ } ;
1213
+ let ty_fn_ptr_from = tcx. coerce_closure_fn_ty ( sig) ;
1214
+
1215
+ if let Err ( terr) = self . eq_types ( ty_fn_ptr_from, ty, location. at_self ( ) ) {
1216
+ span_mirbug ! (
1217
+ self ,
1218
+ rvalue,
1219
+ "equating {:?} with {:?} yields {:?}" ,
1220
+ ty_fn_ptr_from,
1221
+ ty,
1222
+ terr
1223
+ ) ;
1219
1224
}
1225
+ }
1220
1226
1221
- CastKind :: Unsize => {
1222
- let trait_ref = ty:: TraitRef {
1223
- def_id : tcx. lang_items ( ) . coerce_unsized_trait ( ) . unwrap ( ) ,
1224
- substs : tcx. mk_substs_trait ( op. ty ( mir, tcx) , & [ ty] ) ,
1225
- } ;
1227
+ CastKind :: UnsafeFnPointer => {
1228
+ let fn_sig = op. ty ( mir, tcx) . fn_sig ( tcx) ;
1229
+
1230
+ // The type that we see in the fcx is like
1231
+ // `foo::<'a, 'b>`, where `foo` is the path to a
1232
+ // function definition. When we extract the
1233
+ // signature, it comes from the `fn_sig` query,
1234
+ // and hence may contain unnormalized results.
1235
+ let fn_sig = self . normalize ( & fn_sig, location) ;
1226
1236
1227
- self . prove_trait_ref ( trait_ref, location) ;
1237
+ let ty_fn_ptr_from = tcx. safe_to_unsafe_fn_ty ( fn_sig) ;
1238
+
1239
+ if let Err ( terr) = self . eq_types ( ty_fn_ptr_from, ty, location. at_self ( ) ) {
1240
+ span_mirbug ! (
1241
+ self ,
1242
+ rvalue,
1243
+ "equating {:?} with {:?} yields {:?}" ,
1244
+ ty_fn_ptr_from,
1245
+ ty,
1246
+ terr
1247
+ ) ;
1228
1248
}
1249
+ }
1229
1250
1230
- CastKind :: Misc => { }
1251
+ CastKind :: Unsize => {
1252
+ let trait_ref = ty:: TraitRef {
1253
+ def_id : tcx. lang_items ( ) . coerce_unsized_trait ( ) . unwrap ( ) ,
1254
+ substs : tcx. mk_substs_trait ( op. ty ( mir, tcx) , & [ ty] ) ,
1255
+ } ;
1256
+
1257
+ self . prove_trait_ref ( trait_ref, location) ;
1231
1258
}
1232
- }
1259
+
1260
+ CastKind :: Misc => { }
1261
+ } ,
1233
1262
1234
1263
// FIXME: These other cases have to be implemented in future PRs
1235
1264
Rvalue :: Use ( ..) |
@@ -1344,8 +1373,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1344
1373
tcx. predicates_of ( * def_id) . instantiate ( tcx, substs. substs )
1345
1374
}
1346
1375
1347
- AggregateKind :: Array ( _) |
1348
- AggregateKind :: Tuple => ty:: InstantiatedPredicates :: empty ( ) ,
1376
+ AggregateKind :: Array ( _) | AggregateKind :: Tuple => ty:: InstantiatedPredicates :: empty ( ) ,
1349
1377
} ;
1350
1378
1351
1379
let predicates = self . normalize ( & instantiated_predicates. predicates , location) ;
0 commit comments