@@ -36,7 +36,7 @@ use syntax::ast;
36
36
use syntax:: codemap;
37
37
use syntax:: codemap:: Span ;
38
38
use util:: common:: indent;
39
- use util:: ppaux:: { bound_region_to_string , ty_to_string} ;
39
+ use util:: ppaux:: { ty_to_string} ;
40
40
use util:: ppaux:: { trait_ref_to_string, Repr } ;
41
41
42
42
use self :: coercion:: Coerce ;
@@ -222,6 +222,16 @@ pub enum SubregionOrigin {
222
222
AutoBorrow ( Span ) ,
223
223
}
224
224
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
+
225
235
/// Reasons to create a region inference variable
226
236
///
227
237
/// See `error_reporting.rs` for more details
@@ -251,11 +261,7 @@ pub enum RegionVariableOrigin {
251
261
252
262
// Region variables created for bound regions
253
263
// 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 ) ,
259
265
260
266
UpvarRegion ( ty:: UpvarId , Span ) ,
261
267
@@ -959,36 +965,20 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
959
965
}
960
966
961
967
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
967
974
{
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)
992
982
}
993
983
}
994
984
@@ -1170,8 +1160,7 @@ impl RegionVariableOrigin {
1170
1160
Autoref ( a) => a,
1171
1161
Coercion ( ref a) => a. span ( ) ,
1172
1162
EarlyBoundRegion ( a, _) => a,
1173
- LateBoundRegion ( a, _) => a,
1174
- BoundRegionInFnType ( a, _) => a,
1163
+ LateBoundRegion ( a, _, _) => a,
1175
1164
BoundRegionInCoherence ( _) => codemap:: DUMMY_SP ,
1176
1165
UpvarRegion ( _, a) => a
1177
1166
}
@@ -1196,12 +1185,8 @@ impl Repr for RegionVariableOrigin {
1196
1185
EarlyBoundRegion ( a, b) => {
1197
1186
format ! ( "EarlyBoundRegion({},{})" , a. repr( tcx) , b. repr( tcx) )
1198
1187
}
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)
1205
1190
}
1206
1191
BoundRegionInCoherence ( a) => {
1207
1192
format ! ( "bound_regionInCoherence({})" , a. repr( tcx) )
0 commit comments