@@ -394,7 +394,8 @@ enum infer_ctxt = @{
394
394
ty_var_integral_bindings: vals_and_bindings<ty:: tvi_vid, int_ty_set>,
395
395
396
396
// For region variables.
397
- region_var_bindings: vals_and_bindings<ty:: region_vid, bounds<ty:: region>>,
397
+ region_var_bindings: vals_and_bindings<ty:: region_vid,
398
+ bounds<ty:: region>>,
398
399
399
400
// For keeping track of existing type and region variables.
400
401
ty_var_counter: @mut uint,
@@ -1053,7 +1054,7 @@ impl infer_ctxt {
1053
1054
nde_a. rank )
1054
1055
}
1055
1056
1056
- fn var_sub_t_integral < V : copy vid> (
1057
+ fn var_integral_sub_t < V : copy vid> (
1057
1058
vb : & vals_and_bindings < V , int_ty_set > ,
1058
1059
a_id : V , b : ty:: t ) -> ures {
1059
1060
@@ -1146,9 +1147,19 @@ impl infer_ctxt {
1146
1147
debug ! { "eq_regions(%s, %s)" ,
1147
1148
a. to_str( self ) , b. to_str( self ) } ;
1148
1149
do indent {
1149
- do self. sub_regions ( a, b) . then {
1150
- self . sub_regions ( b, a)
1151
- }
1150
+ self. try ( || {
1151
+ do self . sub_regions ( a, b) . then {
1152
+ self . sub_regions ( b, a)
1153
+ }
1154
+ } ) . chain_err ( |e| {
1155
+ // substitute a better error, but use the regions
1156
+ // found in the original error
1157
+ match e {
1158
+ ty:: terr_regions_does_not_outlive( a1, b1) =>
1159
+ err ( ty:: terr_regions_not_same ( a1, b1) ) ,
1160
+ _ => err ( e)
1161
+ }
1162
+ } )
1152
1163
}
1153
1164
}
1154
1165
}
@@ -1847,15 +1858,15 @@ fn super_tys<C:combine>(
1847
1858
}
1848
1859
( ty:: ty_var_integral( a_id) , ty:: ty_int( _) ) |
1849
1860
( ty:: ty_var_integral( a_id) , ty:: ty_uint( _) ) => {
1850
- self . infcx ( ) . vart_integral ( & self . infcx ( ) . ty_var_integral_bindings ,
1851
- a_id , b )
1852
- . then ( || ok ( a) )
1861
+ self . infcx ( ) . var_integral_sub_t (
1862
+ & self . infcx ( ) . ty_var_integral_bindings ,
1863
+ a_id , b ) . then ( || ok ( a) )
1853
1864
}
1854
1865
( ty:: ty_int( _) , ty:: ty_var_integral( b_id) ) |
1855
1866
( ty:: ty_uint( _) , ty:: ty_var_integral( b_id) ) => {
1856
- self . infcx ( ) . t_sub_var_integral ( & self . infcx ( ) . ty_var_integral_bindings ,
1857
- a , b_id )
1858
- . then ( || ok ( a) )
1867
+ self . infcx ( ) . t_sub_var_integral (
1868
+ & self . infcx ( ) . ty_var_integral_bindings ,
1869
+ a , b_id ) . then ( || ok ( a) )
1859
1870
}
1860
1871
1861
1872
( ty:: ty_int( _) , _) |
@@ -2015,8 +2026,8 @@ impl sub: combine {
2015
2026
}
2016
2027
_ => {
2017
2028
do ( & self . lub ( ) ) . regions ( a, b) . compare ( b) {
2018
- ty:: terr_regions_differ ( b, a)
2019
- }
2029
+ ty:: terr_regions_does_not_outlive ( b, a)
2030
+ }
2020
2031
}
2021
2032
}
2022
2033
}
@@ -2460,20 +2471,26 @@ impl glb: combine {
2460
2471
let rm = self . infcx ( ) . tcx . region_map ;
2461
2472
match region:: nearest_common_ancestor ( rm, f_id, s_id) {
2462
2473
some( r_id) if r_id == f_id => ok ( s) ,
2463
- _ => err ( ty:: terr_regions_differ ( b, a) )
2474
+ _ => err ( ty:: terr_regions_no_overlap ( b, a) )
2464
2475
}
2465
2476
}
2466
2477
2467
2478
( ty:: re_scope ( a_id) , ty:: re_scope ( b_id) ) |
2468
2479
( ty:: re_free ( a_id, _) , ty:: re_free ( b_id, _) ) => {
2469
- // We want to generate a region that is contained by both of
2470
- // these: so, if one of these scopes is a subscope of the
2471
- // other, return it. Otherwise fail.
2472
- let rm = self . infcx ( ) . tcx . region_map ;
2473
- match region:: nearest_common_ancestor ( rm, a_id, b_id) {
2474
- some( r_id) if a_id == r_id => ok ( b) ,
2475
- some( r_id) if b_id == r_id => ok ( a) ,
2476
- _ => err ( ty:: terr_regions_differ ( b, a) )
2480
+ if a == b {
2481
+ // Same scope or same free identifier, easy case.
2482
+ ok ( a)
2483
+ } else {
2484
+ // We want to generate the intersection of two
2485
+ // scopes or two free regions. So, if one of
2486
+ // these scopes is a subscope of the other, return
2487
+ // it. Otherwise fail.
2488
+ let rm = self . infcx ( ) . tcx . region_map ;
2489
+ match region:: nearest_common_ancestor ( rm, a_id, b_id) {
2490
+ some( r_id) if a_id == r_id => ok ( ty:: re_scope ( b_id) ) ,
2491
+ some( r_id) if b_id == r_id => ok ( ty:: re_scope ( a_id) ) ,
2492
+ _ => err ( ty:: terr_regions_no_overlap ( b, a) )
2493
+ }
2477
2494
}
2478
2495
}
2479
2496
@@ -2487,7 +2504,7 @@ impl glb: combine {
2487
2504
if a == b {
2488
2505
ok ( a)
2489
2506
} else {
2490
- err ( ty:: terr_regions_differ ( b, a) )
2507
+ err ( ty:: terr_regions_no_overlap ( b, a) )
2491
2508
}
2492
2509
}
2493
2510
}
@@ -2589,13 +2606,13 @@ fn lattice_tys<L:lattice_ops combine>(
2589
2606
}
2590
2607
2591
2608
( ty:: ty_var ( a_id) , _) => {
2592
- lattice_var_t ( self , & self . infcx ( ) . ty_var_bindings , a_id, b,
2593
- |x, y| self . tys ( x, y) )
2609
+ lattice_var_and_t ( self , & self . infcx ( ) . ty_var_bindings , a_id, b,
2610
+ |x, y| self . tys ( x, y) )
2594
2611
}
2595
2612
2596
2613
( _, ty:: ty_var ( b_id) ) => {
2597
- lattice_var_t ( self , & self . infcx ( ) . ty_var_bindings , b_id, a,
2598
- |x, y| self . tys ( x, y) )
2614
+ lattice_var_and_t ( self , & self . infcx ( ) . ty_var_bindings , b_id, a,
2615
+ |x, y| self . tys ( x, y) )
2599
2616
}
2600
2617
_ => {
2601
2618
super_tys( self , a, b)
@@ -2616,9 +2633,9 @@ fn lattice_rvars<L:lattice_ops combine>(
2616
2633
}
2617
2634
2618
2635
( ty:: re_var( v_id) , r) | ( r, ty:: re_var( v_id) ) => {
2619
- lattice_var_t ( self , & self . infcx ( ) . region_var_bindings ,
2620
- v_id, r,
2621
- |x, y| self . regions ( x, y) )
2636
+ lattice_var_and_t ( self , & self . infcx ( ) . region_var_bindings ,
2637
+ v_id, r,
2638
+ |x, y| self . regions ( x, y) )
2622
2639
}
2623
2640
2624
2641
_ => {
0 commit comments