@@ -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 } ;
20
+ use rustc:: ty:: { self , Ty , TyCtxt , TypeVariants , ToPolyTraitRef } ;
21
21
use rustc:: middle:: const_val:: ConstVal ;
22
22
use rustc:: mir:: * ;
23
23
use rustc:: mir:: tcx:: PlaceTy ;
@@ -545,6 +545,13 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
545
545
span_mirbug ! ( self , "" , "errors selecting obligation: {:?}" , e) ;
546
546
}
547
547
548
+ self . infcx . process_registered_region_obligations (
549
+ & [ ] ,
550
+ None ,
551
+ self . param_env ,
552
+ self . body_id ,
553
+ ) ;
554
+
548
555
let data = self . infcx . take_and_reset_region_constraints ( ) ;
549
556
if !data. is_empty ( ) {
550
557
self . constraints
@@ -1110,13 +1117,28 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1110
1117
}
1111
1118
1112
1119
fn check_rvalue ( & mut self , mir : & Mir < ' tcx > , rvalue : & Rvalue < ' tcx > , location : Location ) {
1120
+ let tcx = self . tcx ( ) ;
1121
+
1113
1122
match rvalue {
1114
1123
Rvalue :: Aggregate ( ak, ops) => {
1115
1124
self . check_aggregate_rvalue ( mir, rvalue, ak, ops, location)
1116
1125
}
1126
+
1127
+ Rvalue :: Repeat ( operand, const_usize) => {
1128
+ if const_usize. as_u64 ( ) > 1 {
1129
+ let operand_ty = operand. ty ( mir, tcx) ;
1130
+
1131
+ let trait_ref = ty:: TraitRef {
1132
+ def_id : tcx. lang_items ( ) . copy_trait ( ) . unwrap ( ) ,
1133
+ substs : tcx. mk_substs_trait ( operand_ty, & [ ] ) ,
1134
+ } ;
1135
+
1136
+ self . prove_trait_ref ( trait_ref, location) ;
1137
+ }
1138
+ }
1139
+
1117
1140
// FIXME: These other cases have to be implemented in future PRs
1118
1141
Rvalue :: Use ( ..) |
1119
- Rvalue :: Repeat ( ..) |
1120
1142
Rvalue :: Ref ( ..) |
1121
1143
Rvalue :: Len ( ..) |
1122
1144
Rvalue :: Cast ( ..) |
@@ -1205,6 +1227,31 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1205
1227
}
1206
1228
}
1207
1229
1230
+ fn prove_trait_ref ( & mut self , trait_ref : ty:: TraitRef < ' tcx > , location : Location ) {
1231
+ self . prove_predicates (
1232
+ & [
1233
+ ty:: Predicate :: Trait ( trait_ref. to_poly_trait_ref ( ) . to_poly_trait_predicate ( ) ) ,
1234
+ ] ,
1235
+ location,
1236
+ ) ;
1237
+ }
1238
+
1239
+ fn prove_predicates ( & mut self , predicates : & [ ty:: Predicate < ' tcx > ] , location : Location ) {
1240
+ self . fully_perform_op ( location. at_self ( ) , |this| {
1241
+ let cause = this. misc ( this. last_span ) ;
1242
+ let obligations = predicates
1243
+ . iter ( )
1244
+ . map ( |& p| {
1245
+ traits:: Obligation :: new ( cause. clone ( ) , this. param_env , p)
1246
+ } )
1247
+ . collect ( ) ;
1248
+ Ok ( InferOk {
1249
+ value : ( ) ,
1250
+ obligations,
1251
+ } )
1252
+ } ) . unwrap ( )
1253
+ }
1254
+
1208
1255
fn typeck_mir ( & mut self , mir : & Mir < ' tcx > ) {
1209
1256
self . last_span = mir. span ;
1210
1257
debug ! ( "run_on_mir: {:?}" , mir. span) ;
@@ -1237,7 +1284,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1237
1284
{
1238
1285
self . fully_perform_op ( location. at_self ( ) , |this| {
1239
1286
let mut selcx = traits:: SelectionContext :: new ( this. infcx ) ;
1240
- let cause = traits :: ObligationCause :: misc ( this. last_span , ast :: CRATE_NODE_ID ) ;
1287
+ let cause = this . misc ( this. last_span ) ;
1241
1288
let traits:: Normalized { value, obligations } =
1242
1289
traits:: normalize ( & mut selcx, this. param_env , cause, value) ;
1243
1290
Ok ( InferOk { value, obligations } )
0 commit comments