72
72
use hir:: def_id:: DefId ;
73
73
use infer:: { self , GenericKind , InferCtxt , RegionObligation , SubregionOrigin , VerifyBound } ;
74
74
use syntax:: ast;
75
- use traits;
75
+ use traits:: { self , ObligationCause } ;
76
76
use ty:: outlives:: Component ;
77
77
use ty:: subst:: { Subst , Substs } ;
78
- use ty:: { self , Ty , TyCtxt , TypeFoldable } ;
78
+ use ty:: { self , Region , Ty , TyCtxt , TypeFoldable } ;
79
79
80
80
impl < ' cx , ' gcx , ' tcx > InferCtxt < ' cx , ' gcx , ' tcx > {
81
81
/// Registers that the given region obligation must be resolved
@@ -98,6 +98,26 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
98
98
. push ( ( body_id, obligation) ) ;
99
99
}
100
100
101
+ pub fn register_region_obligation_with_cause (
102
+ & self ,
103
+ sup_type : Ty < ' tcx > ,
104
+ sub_region : Region < ' tcx > ,
105
+ cause : & ObligationCause < ' tcx > ,
106
+ ) {
107
+ let origin = SubregionOrigin :: from_obligation_cause ( cause, || {
108
+ infer:: RelateParamBound ( cause. span , sup_type)
109
+ } ) ;
110
+
111
+ self . register_region_obligation (
112
+ cause. body_id ,
113
+ RegionObligation {
114
+ sup_type,
115
+ sub_region,
116
+ origin,
117
+ } ,
118
+ ) ;
119
+ }
120
+
101
121
/// Trait queries just want to pass back type obligations "as is"
102
122
pub fn take_registered_region_obligations ( & self ) -> Vec < ( ast:: NodeId , RegionObligation < ' tcx > ) > {
103
123
:: std:: mem:: replace ( & mut * self . region_obligations . borrow_mut ( ) , vec ! [ ] )
@@ -154,10 +174,9 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
154
174
let mut my_region_obligations = Vec :: with_capacity ( self . region_obligations . borrow ( ) . len ( ) ) ;
155
175
{
156
176
let mut r_o = self . region_obligations . borrow_mut ( ) ;
157
- my_region_obligations. extend (
158
- r_o. drain_filter ( |( ro_body_id, _) | * ro_body_id == body_id)
159
- . map ( |( _, obligation) | obligation)
160
- ) ;
177
+ my_region_obligations. extend ( r_o. drain_filter ( |( ro_body_id, _) | {
178
+ * ro_body_id == body_id
179
+ } ) . map ( |( _, obligation) | obligation) ) ;
161
180
}
162
181
163
182
let outlives = & mut TypeOutlives :: new (
@@ -171,18 +190,14 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
171
190
for RegionObligation {
172
191
sup_type,
173
192
sub_region,
174
- cause ,
193
+ origin ,
175
194
} in my_region_obligations
176
195
{
177
196
debug ! (
178
- "process_registered_region_obligations: sup_type={:?} sub_region={:?} cause ={:?}" ,
179
- sup_type, sub_region, cause
197
+ "process_registered_region_obligations: sup_type={:?} sub_region={:?} origin ={:?}" ,
198
+ sup_type, sub_region, origin
180
199
) ;
181
200
182
- let origin = SubregionOrigin :: from_obligation_cause ( & cause, || {
183
- infer:: RelateParamBound ( cause. span , sup_type)
184
- } ) ;
185
-
186
201
let sup_type = self . resolve_type_vars_if_possible ( & sup_type) ;
187
202
outlives. type_must_outlive ( origin, sup_type, sub_region) ;
188
203
}
@@ -302,7 +317,8 @@ where
302
317
let origin = origin. clone ( ) ;
303
318
match component {
304
319
Component :: Region ( region1) => {
305
- self . delegate . push_sub_region_constraint ( origin, region, region1) ;
320
+ self . delegate
321
+ . push_sub_region_constraint ( origin, region, region1) ;
306
322
}
307
323
Component :: Param ( param_ty) => {
308
324
self . param_ty_must_outlive ( origin, region, param_ty) ;
@@ -405,7 +421,8 @@ where
405
421
}
406
422
407
423
for r in projection_ty. substs . regions ( ) {
408
- self . delegate . push_sub_region_constraint ( origin. clone ( ) , region, r) ;
424
+ self . delegate
425
+ . push_sub_region_constraint ( origin. clone ( ) , region, r) ;
409
426
}
410
427
411
428
return ;
@@ -497,16 +514,17 @@ where
497
514
) ;
498
515
499
516
// see the extensive comment in projection_must_outlive
500
- let ty = self
501
- . tcx
517
+ let ty = self . tcx
502
518
. mk_projection ( projection_ty. item_def_id , projection_ty. substs ) ;
503
519
let recursive_bound = self . recursive_type_bound ( ty) ;
504
520
505
521
VerifyBound :: AnyRegion ( declared_bounds) . or ( recursive_bound)
506
522
}
507
523
508
524
fn recursive_type_bound ( & self , ty : Ty < ' tcx > ) -> VerifyBound < ' tcx > {
509
- let mut bounds = ty. walk_shallow ( ) . map ( |subty| self . type_bound ( subty) ) . collect :: < Vec < _ > > ( ) ;
525
+ let mut bounds = ty. walk_shallow ( )
526
+ . map ( |subty| self . type_bound ( subty) )
527
+ . collect :: < Vec < _ > > ( ) ;
510
528
511
529
let mut regions = ty. regions ( ) ;
512
530
regions. retain ( |r| !r. is_late_bound ( ) ) ; // ignore late-bound regions
@@ -674,4 +692,3 @@ impl<'cx, 'gcx, 'tcx> TypeOutlivesDelegate<'tcx> for &'cx InferCtxt<'cx, 'gcx, '
674
692
self . verify_generic_bound ( origin, kind, a, bound)
675
693
}
676
694
}
677
-
0 commit comments