@@ -16,6 +16,7 @@ import util::ppaux::ty_to_str;
16
16
import std:: smallintmap;
17
17
import std:: map:: { hashmap, int_hash} ;
18
18
import std:: serialization:: { serialize_uint, deserialize_uint} ;
19
+ import std:: ufind;
19
20
import syntax:: print:: pprust:: * ;
20
21
21
22
export check_crate;
@@ -1554,6 +1555,33 @@ fn universally_quantify_regions(tcx: ty::ctxt, ty: ty::t) -> ty::t {
1554
1555
}
1555
1556
}
1556
1557
1558
+ // Replaces region parameter types in the given type with the appropriate
1559
+ // bindings.
1560
+ fn replace_region_params ( tcx : ty:: ctxt ,
1561
+ sp : span ,
1562
+ rb : @ty:: unify:: region_bindings ,
1563
+ ty : ty:: t )
1564
+ -> ty:: t {
1565
+
1566
+ if ty:: type_has_rptrs ( ty) {
1567
+ ty:: fold_ty ( tcx, ty:: fm_rptr ( { |r|
1568
+ alt r {
1569
+ ty : : re_param ( n) {
1570
+ if n < ufind:: set_count ( rb. sets ) {
1571
+ smallintmap:: get ( rb. regions , ufind:: find ( rb. sets , n) )
1572
+ } else {
1573
+ tcx. sess . span_err ( sp, "unresolved region" ) ;
1574
+ r
1575
+ }
1576
+ }
1577
+ _ { r }
1578
+ }
1579
+ } ) , ty)
1580
+ } else {
1581
+ ty
1582
+ }
1583
+ }
1584
+
1557
1585
fn check_pat_variant ( pcx : pat_ctxt , pat : @ast:: pat , path : @ast:: path ,
1558
1586
subpats : [ @ast:: pat ] , expected : ty:: t ) {
1559
1587
// Typecheck the path.
@@ -2277,40 +2305,38 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
2277
2305
// A generic function for checking call expressions
2278
2306
fn check_call ( fcx : @fn_ctxt , sp : span , id : ast:: node_id , f : @ast:: expr ,
2279
2307
args : [ @ast:: expr ] )
2280
- -> bool {
2308
+ -> check_call_or_bind_result {
2281
2309
let args_opt_0: [ option < @ast:: expr > ] = [ ] ;
2282
2310
for arg: @ast:: expr in args {
2283
2311
args_opt_0 += [ some :: < @ast:: expr > ( arg) ] ;
2284
2312
}
2285
2313
2286
- let mut bot = check_expr ( fcx, f) ;
2314
+ let bot = check_expr ( fcx, f) ;
2287
2315
// Call the generic checker.
2288
2316
let ccobr = check_call_or_bind ( fcx, sp, id, expr_ty ( fcx. ccx . tcx , f) ,
2289
2317
args_opt_0) ;
2290
- bot |= ccobr. bot ;
2291
-
2292
- // TODO: Munge return type.
2293
-
2294
- ret bot;
2318
+ ret { bot : bot | ccobr. bot with ccobr } ;
2295
2319
}
2296
2320
2297
2321
// A generic function for doing all of the checking for call expressions
2298
2322
fn check_call_full ( fcx : @fn_ctxt , sp : span , id : ast:: node_id ,
2299
2323
f : @ast:: expr , args : [ @ast:: expr ] ) -> bool {
2300
- let bot = check_call ( fcx, sp, id, f, args) ;
2324
+ let ccobr = check_call ( fcx, sp, id, f, args) ;
2325
+ let mut bot = ccobr. bot ;
2301
2326
/* need to restrict oper to being an explicit expr_path if we're
2302
2327
inside a pure function */
2303
2328
require_pure_call ( fcx. ccx , fcx. purity , f, sp) ;
2304
2329
2305
2330
// Pull the return type out of the type of the function.
2306
2331
let fty = ty:: expr_ty ( fcx. ccx . tcx , f) ;
2307
- let rt_1 = alt structure_of ( fcx, sp, fty) {
2332
+ let mut rt_1 = alt structure_of ( fcx, sp, fty) {
2308
2333
ty:: ty_fn ( f) {
2309
2334
bot |= f. ret_style == ast:: noreturn;
2310
2335
f. output
2311
2336
}
2312
2337
_ { fcx. ccx . tcx . sess . span_fatal ( sp, "calling non-function" ) ; }
2313
2338
} ;
2339
+ rt_1 = replace_region_params ( fcx. ccx . tcx , f. span , ccobr. rb , rt_1) ;
2314
2340
write_ty ( fcx. ccx . tcx , id, rt_1) ;
2315
2341
ret bot;
2316
2342
}
0 commit comments