@@ -36,7 +36,7 @@ use syntax::ast;
3636use syntax:: codemap;
3737use syntax:: codemap:: Span ;
3838use util:: common:: indent;
39- use util:: ppaux:: { bound_region_to_string , ty_to_string} ;
39+ use util:: ppaux:: { ty_to_string} ;
4040use util:: ppaux:: { trait_ref_to_string, Repr } ;
4141
4242use self :: coercion:: Coerce ;
@@ -222,6 +222,16 @@ pub enum SubregionOrigin {
222222 AutoBorrow ( Span ) ,
223223}
224224
225+ /// Times when we replace late-bound regions with variables:
226+ #[ deriving( Clone , Show ) ]
227+ pub enum LateBoundRegionConversionTime {
228+ /// when a fn is called
229+ FnCall ,
230+
231+ /// when two fn types are compared
232+ FnType ,
233+ }
234+
225235/// Reasons to create a region inference variable
226236///
227237/// See `error_reporting.rs` for more details
@@ -251,11 +261,7 @@ pub enum RegionVariableOrigin {
251261
252262 // Region variables created for bound regions
253263 // in a function or method that is called
254- LateBoundRegion ( Span , ty:: BoundRegion ) ,
255-
256- // Region variables created for bound regions
257- // when doing subtyping/lub/glb computations
258- BoundRegionInFnType ( Span , ty:: BoundRegion ) ,
264+ LateBoundRegion ( Span , ty:: BoundRegion , LateBoundRegionConversionTime ) ,
259265
260266 UpvarRegion ( ty:: UpvarId , Span ) ,
261267
@@ -959,36 +965,20 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
959965 }
960966
961967 pub fn replace_late_bound_regions_with_fresh_var < T > ( & self ,
962- binder_id: ast:: NodeId ,
963- span: Span ,
964- value: & T )
965- -> T
966- where T : TypeFoldable + Repr
968+ binder_id: ast:: NodeId ,
969+ span: Span ,
970+ lbrct: LateBoundRegionConversionTime ,
971+ value: & T )
972+ -> ( T , HashMap < ty:: BoundRegion , ty:: Region > )
973+ where T : TypeFoldable + Repr
967974 {
968- let ( _, value) = replace_late_bound_regions(
969- self . tcx,
970- binder_id,
971- value,
972- |br| self . next_region_var( LateBoundRegion ( span, br) ) ) ;
973- value
974- }
975-
976- pub fn replace_late_bound_regions_with_fresh_regions( & self ,
977- trace: TypeTrace ,
978- fsig: & ty:: FnSig )
979- -> ( ty:: FnSig ,
980- HashMap < ty:: BoundRegion ,
981- ty:: Region > ) {
982- let ( map, fn_sig) =
983- replace_late_bound_regions( self . tcx, fsig. binder_id, fsig, |br| {
984- let rvar = self . next_region_var(
985- BoundRegionInFnType ( trace. origin. span( ) , br) ) ;
986- debug ! ( "Bound region {} maps to {}" ,
987- bound_region_to_string( self . tcx, "" , false , br) ,
988- rvar) ;
989- rvar
990- } ) ;
991- ( fn_sig, map)
975+ let ( map, value) =
976+ replace_late_bound_regions(
977+ self . tcx,
978+ binder_id,
979+ value,
980+ |br| self . next_region_var( LateBoundRegion ( span, br, lbrct) ) ) ;
981+ ( value, map)
992982 }
993983}
994984
@@ -1170,8 +1160,7 @@ impl RegionVariableOrigin {
11701160 Autoref ( a) => a,
11711161 Coercion ( ref a) => a. span ( ) ,
11721162 EarlyBoundRegion ( a, _) => a,
1173- LateBoundRegion ( a, _) => a,
1174- BoundRegionInFnType ( a, _) => a,
1163+ LateBoundRegion ( a, _, _) => a,
11751164 BoundRegionInCoherence ( _) => codemap:: DUMMY_SP ,
11761165 UpvarRegion ( _, a) => a
11771166 }
@@ -1196,12 +1185,8 @@ impl Repr for RegionVariableOrigin {
11961185 EarlyBoundRegion ( a, b) => {
11971186 format ! ( "EarlyBoundRegion({},{})" , a. repr( tcx) , b. repr( tcx) )
11981187 }
1199- LateBoundRegion ( a, b) => {
1200- format ! ( "LateBoundRegion({},{})" , a. repr( tcx) , b. repr( tcx) )
1201- }
1202- BoundRegionInFnType ( a, b) => {
1203- format ! ( "bound_regionInFnType({},{})" , a. repr( tcx) ,
1204- b. repr( tcx) )
1188+ LateBoundRegion ( a, b, c) => {
1189+ format ! ( "LateBoundRegion({},{},{})" , a. repr( tcx) , b. repr( tcx) , c)
12051190 }
12061191 BoundRegionInCoherence ( a) => {
12071192 format ! ( "bound_regionInCoherence({})" , a. repr( tcx) )
0 commit comments