@@ -1970,8 +1970,42 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
1970
1970
1971
1971
// A generic function to factor out common logic from call and bind
1972
1972
// expressions.
1973
- fn check_call_or_bind ( fcx : @fn_ctxt , sp : span , fty : ty:: t ,
1974
- args : [ option < @ast:: expr > ] ) -> bool {
1973
+ fn check_call_or_bind ( fcx : @fn_ctxt , sp : span , id : ast:: node_id ,
1974
+ fty : ty:: t , args : [ option < @ast:: expr > ] ) -> bool {
1975
+ // Replaces "caller" regions in the arguments with the local region.
1976
+ fn instantiate_caller_regions ( fcx : @fn_ctxt , id : ast:: node_id ,
1977
+ args : [ ty:: arg ] ) -> [ ty:: arg ] {
1978
+ let site_to_block = fcx. ccx . tcx . region_map . call_site_to_block ;
1979
+ let block_id = alt site_to_block. find ( id) {
1980
+ none {
1981
+ // This can happen for those expressions that are
1982
+ // synthesized during typechecking; e.g. during
1983
+ // check_constraints().
1984
+ ret args;
1985
+ }
1986
+ some( block_id) { block_id }
1987
+ } ;
1988
+
1989
+ let region = ty:: re_block ( block_id) ;
1990
+ ret vec:: map ( args) { |arg|
1991
+ if ty:: type_has_rptrs ( arg. ty ) {
1992
+ let ty = ty:: fold_ty ( fcx. ccx . tcx , ty:: fm_rptr ( { |r|
1993
+ alt r {
1994
+ ty : : re_caller ( _) {
1995
+ // FIXME: We should not recurse into nested
1996
+ // function types here.
1997
+ region
1998
+ }
1999
+ _ { r }
2000
+ }
2001
+ } ) , arg. ty ) ;
2002
+ { ty: ty with arg}
2003
+ } else {
2004
+ arg
2005
+ }
2006
+ } ;
2007
+ }
2008
+
1975
2009
let sty = structure_of ( fcx, sp, fty) ;
1976
2010
// Grab the argument types
1977
2011
let arg_tys = alt sty {
@@ -2009,6 +2043,8 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
2009
2043
arg_tys = vec:: from_elem ( supplied_arg_count, dummy) ;
2010
2044
}
2011
2045
2046
+ arg_tys = instantiate_caller_regions ( fcx, id, arg_tys) ;
2047
+
2012
2048
// Check the arguments.
2013
2049
// We do this in a pretty awful way: first we typecheck any arguments
2014
2050
// that are not anonymous functions, then we typecheck the anonymous
@@ -2049,7 +2085,8 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
2049
2085
}
2050
2086
2051
2087
// A generic function for checking call expressions
2052
- fn check_call ( fcx : @fn_ctxt , sp : span , f : @ast:: expr , args : [ @ast:: expr ] )
2088
+ fn check_call ( fcx : @fn_ctxt , sp : span , id : ast:: node_id , f : @ast:: expr ,
2089
+ args : [ @ast:: expr ] )
2053
2090
-> bool {
2054
2091
let args_opt_0: [ option < @ast:: expr > ] = [ ] ;
2055
2092
for arg: @ast:: expr in args {
@@ -2058,13 +2095,14 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
2058
2095
2059
2096
let bot = check_expr ( fcx, f) ;
2060
2097
// Call the generic checker.
2061
- bot | check_call_or_bind ( fcx, sp, expr_ty ( fcx. ccx . tcx , f) , args_opt_0)
2098
+ bot | check_call_or_bind ( fcx, sp, id, expr_ty ( fcx. ccx . tcx , f) ,
2099
+ args_opt_0)
2062
2100
}
2063
2101
2064
2102
// A generic function for doing all of the checking for call expressions
2065
- fn check_call_full ( fcx : @fn_ctxt , sp : span , f : @ ast:: expr ,
2066
- args : [ @ast:: expr ] , id : ast:: node_id ) -> bool {
2067
- let bot = check_call ( fcx, sp, f, args) ;
2103
+ fn check_call_full ( fcx : @fn_ctxt , sp : span , id : ast:: node_id ,
2104
+ f : @ast:: expr , args : [ @ ast:: expr ] ) -> bool {
2105
+ let bot = check_call ( fcx, sp, id , f, args) ;
2068
2106
/* here we're kind of hosed, as f can be any expr
2069
2107
need to restrict it to being an explicit expr_path if we're
2070
2108
inside a pure function, and need an environment mapping from
@@ -2145,7 +2183,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
2145
2183
alt lookup_method ( fcx, op_ex, callee_id, opname, self_t, [ ] ) {
2146
2184
some ( origin) {
2147
2185
let method_ty = ty:: node_id_to_type ( fcx. ccx . tcx , callee_id) ;
2148
- check_call_or_bind ( fcx, op_ex. span , method_ty, args) ;
2186
+ check_call_or_bind ( fcx, op_ex. span , op_ex . id , method_ty, args) ;
2149
2187
fcx. ccx . method_map . insert ( op_ex. id , origin) ;
2150
2188
some ( ty:: ty_fn_ret ( method_ty) )
2151
2189
}
@@ -2472,7 +2510,8 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
2472
2510
ast:: expr_bind ( f, args) {
2473
2511
// Call the generic checker.
2474
2512
bot = check_expr ( fcx, f) ;
2475
- bot |= check_call_or_bind ( fcx, expr. span , expr_ty ( tcx, f) , args) ;
2513
+ bot |= check_call_or_bind ( fcx, expr. span , expr. id , expr_ty ( tcx, f) ,
2514
+ args) ;
2476
2515
2477
2516
// Pull the argument and return types out.
2478
2517
let proto, arg_tys, rt, cf, constrs;
@@ -2518,7 +2557,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
2518
2557
write_ty ( tcx, id, ft) ;
2519
2558
}
2520
2559
ast:: expr_call ( f, args, _) {
2521
- bot = check_call_full ( fcx, expr. span , f , args , expr . id ) ;
2560
+ bot = check_call_full ( fcx, expr. span , expr . id , f , args ) ;
2522
2561
}
2523
2562
ast:: expr_cast ( e, t) {
2524
2563
bot = check_expr ( fcx, e) ;
0 commit comments