1010
1111use middle:: mem_categorization:: Typer ;
1212use middle:: ty:: { mod, Ty } ;
13- use middle:: infer:: { mod, InferCtxt } ;
13+ use middle:: infer:: { mod, InferCtxt , ures } ;
1414use std:: collections:: HashSet ;
1515use std:: collections:: hash_map:: { Occupied , Vacant } ;
1616use std:: default:: Default ;
@@ -20,6 +20,8 @@ use util::ppaux::Repr;
2020use util:: nodemap:: NodeMap ;
2121
2222use super :: CodeAmbiguity ;
23+ use super :: Obligation ;
24+ use super :: ObligationCause ;
2325use super :: TraitObligation ;
2426use super :: FulfillmentError ;
2527use super :: CodeSelectionError ;
@@ -82,7 +84,7 @@ pub struct FulfillmentContext<'tcx> {
8284pub struct RegionObligation < ' tcx > {
8385 pub sub_region : ty:: Region ,
8486 pub sup_type : Ty < ' tcx > ,
85- pub origin : infer :: SubregionOrigin < ' tcx > ,
87+ pub cause : ObligationCause < ' tcx > ,
8688}
8789
8890impl < ' tcx > FulfillmentContext < ' tcx > {
@@ -95,6 +97,32 @@ impl<'tcx> FulfillmentContext<'tcx> {
9597 }
9698 }
9799
100+ pub fn register_predicate < ' a > ( & mut self ,
101+ infcx : & InferCtxt < ' a , ' tcx > ,
102+ predicate : & Obligation < ' tcx , ty:: Predicate < ' tcx > > )
103+ -> ures < ' tcx >
104+ {
105+ match predicate. trait_ref {
106+ ty:: Predicate :: Trait ( ref trait_ref) => {
107+ let trait_obligation = Obligation { cause : predicate. cause ,
108+ recursion_depth : predicate. recursion_depth ,
109+ trait_ref : ( * trait_ref) . clone ( ) } ;
110+ Ok ( self . register_obligation ( infcx. tcx , trait_obligation) )
111+ }
112+ ty:: Predicate :: Equate ( a, b) => {
113+ let origin = infer:: EquatePredicate ( predicate. cause . span ) ;
114+ infer:: mk_eqty ( infcx, false , origin, a, b) // `a == b` ==> ``
115+ }
116+ ty:: Predicate :: RegionOutlives ( r_a, r_b) => {
117+ let origin = infer:: RelateRegionParamBound ( predicate. cause . span ) ;
118+ Ok ( infer:: mk_subr ( infcx, origin, r_b, r_a) ) // `b : a` ==> `a <= b`
119+ }
120+ ty:: Predicate :: TypeOutlives ( t_a, r_b) => {
121+ Ok ( self . register_region_obligation ( t_a, r_b, predicate. cause ) )
122+ }
123+ }
124+ }
125+
98126 pub fn register_obligation ( & mut self ,
99127 tcx : & ty:: ctxt < ' tcx > ,
100128 obligation : TraitObligation < ' tcx > )
@@ -109,10 +137,14 @@ impl<'tcx> FulfillmentContext<'tcx> {
109137 }
110138
111139 pub fn register_region_obligation ( & mut self ,
112- body_id : ast:: NodeId ,
113- region_obligation : RegionObligation < ' tcx > )
140+ sup_type : Ty < ' tcx > ,
141+ sub_region : ty:: Region ,
142+ cause : ObligationCause < ' tcx > )
114143 {
115- match self . region_obligations . entry ( body_id) {
144+ let region_obligation = RegionObligation { sup_type : sup_type,
145+ sub_region : sub_region,
146+ cause : cause } ;
147+ match self . region_obligations . entry ( cause. body_id ) {
116148 Vacant ( entry) => { entry. set ( vec ! [ region_obligation] ) ; } ,
117149 Occupied ( mut entry) => { entry. get_mut ( ) . push ( region_obligation) ; } ,
118150 }
@@ -268,9 +300,8 @@ impl<'tcx> FulfillmentContext<'tcx> {
268300
269301impl < ' tcx > Repr < ' tcx > for RegionObligation < ' tcx > {
270302 fn repr ( & self , tcx : & ty:: ctxt < ' tcx > ) -> String {
271- format ! ( "RegionObligation(sub_region={}, sup_type={}, origin={} )" ,
303+ format ! ( "RegionObligation(sub_region={}, sup_type={})" ,
272304 self . sub_region. repr( tcx) ,
273- self . sup_type. repr( tcx) ,
274- self . origin. repr( tcx) )
305+ self . sup_type. repr( tcx) )
275306 }
276307}
0 commit comments