@@ -158,11 +158,11 @@ pub fn regionck_item(fcx: &FnCtxt, item: &ast::Item) {
158
158
fcx. infcx ( ) . resolve_regions_and_report_errors ( ) ;
159
159
}
160
160
161
- pub fn regionck_fn ( fcx : & FnCtxt , id : ast:: NodeId , blk : & ast:: Block ) {
161
+ pub fn regionck_fn ( fcx : & FnCtxt , id : ast:: NodeId , decl : & ast :: FnDecl , blk : & ast:: Block ) {
162
162
let mut rcx = Rcx :: new ( fcx, blk. id ) ;
163
163
if fcx. err_count_since_creation ( ) == 0 {
164
164
// regionck assumes typeck succeeded
165
- rcx. visit_fn_body ( id, blk) ;
165
+ rcx. visit_fn_body ( id, decl , blk) ;
166
166
}
167
167
168
168
// Region checking a fn can introduce new trait obligations,
@@ -328,6 +328,7 @@ impl<'a, 'tcx> Rcx<'a, 'tcx> {
328
328
329
329
fn visit_fn_body ( & mut self ,
330
330
id : ast:: NodeId ,
331
+ fn_decl : & ast:: FnDecl ,
331
332
body : & ast:: Block )
332
333
{
333
334
// When we enter a function, we can derive
@@ -343,6 +344,7 @@ impl<'a, 'tcx> Rcx<'a, 'tcx> {
343
344
344
345
let len = self . region_param_pairs . len ( ) ;
345
346
self . relate_free_regions ( fn_sig. as_slice ( ) , body. id ) ;
347
+ link_fn_args ( self , CodeExtent :: from_node_id ( body. id ) , fn_decl. inputs . as_slice ( ) ) ;
346
348
self . visit_block ( body) ;
347
349
self . visit_region_obligations ( body. id ) ;
348
350
self . region_param_pairs . truncate ( len) ;
@@ -480,9 +482,9 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Rcx<'a, 'tcx> {
480
482
// hierarchy, and in particular the relationships between free
481
483
// regions, until regionck, as described in #3238.
482
484
483
- fn visit_fn ( & mut self , _fk : visit:: FnKind < ' v > , _fd : & ' v ast:: FnDecl ,
485
+ fn visit_fn ( & mut self , _fk : visit:: FnKind < ' v > , fd : & ' v ast:: FnDecl ,
484
486
b : & ' v ast:: Block , _s : Span , id : ast:: NodeId ) {
485
- self . visit_fn_body ( id, b)
487
+ self . visit_fn_body ( id, fd , b)
486
488
}
487
489
488
490
fn visit_item ( & mut self , i : & ast:: Item ) { visit_item ( self , i) ; }
@@ -1288,7 +1290,6 @@ fn link_local(rcx: &Rcx, local: &ast::Local) {
1288
1290
/// then ensures that the lifetime of the resulting pointer is
1289
1291
/// linked to the lifetime of its guarantor (if any).
1290
1292
fn link_match ( rcx : & Rcx , discr : & ast:: Expr , arms : & [ ast:: Arm ] ) {
1291
-
1292
1293
debug ! ( "regionck::for_match()" ) ;
1293
1294
let mc = mc:: MemCategorizationContext :: new ( rcx) ;
1294
1295
let discr_cmt = ignore_err ! ( mc. cat_expr( discr) ) ;
@@ -1300,12 +1301,32 @@ fn link_match(rcx: &Rcx, discr: &ast::Expr, arms: &[ast::Arm]) {
1300
1301
}
1301
1302
}
1302
1303
1304
+ /// Computes the guarantors for any ref bindings in a match and
1305
+ /// then ensures that the lifetime of the resulting pointer is
1306
+ /// linked to the lifetime of its guarantor (if any).
1307
+ fn link_fn_args ( rcx : & Rcx , body_scope : CodeExtent , args : & [ ast:: Arg ] ) {
1308
+ debug ! ( "regionck::link_fn_args(body_scope={})" , body_scope) ;
1309
+ let mc = mc:: MemCategorizationContext :: new ( rcx) ;
1310
+ for arg in args. iter ( ) {
1311
+ let arg_ty = rcx. fcx . node_ty ( arg. id ) ;
1312
+ let re_scope = ty:: ReScope ( body_scope) ;
1313
+ let arg_cmt = mc. cat_rvalue ( arg. id , arg. ty . span , re_scope, arg_ty) ;
1314
+ debug ! ( "arg_ty={} arg_cmt={}" ,
1315
+ arg_ty. repr( rcx. tcx( ) ) ,
1316
+ arg_cmt. repr( rcx. tcx( ) ) ) ;
1317
+ link_pattern ( rcx, mc, arg_cmt, & * arg. pat ) ;
1318
+ }
1319
+ }
1320
+
1303
1321
/// Link lifetimes of any ref bindings in `root_pat` to the pointers found in the discriminant, if
1304
1322
/// needed.
1305
1323
fn link_pattern < ' a , ' tcx > ( rcx : & Rcx < ' a , ' tcx > ,
1306
1324
mc : mc:: MemCategorizationContext < Rcx < ' a , ' tcx > > ,
1307
1325
discr_cmt : mc:: cmt < ' tcx > ,
1308
1326
root_pat : & ast:: Pat ) {
1327
+ debug ! ( "link_pattern(discr_cmt={}, root_pat={})" ,
1328
+ discr_cmt. repr( rcx. tcx( ) ) ,
1329
+ root_pat. repr( rcx. tcx( ) ) ) ;
1309
1330
let _ = mc. cat_pattern ( discr_cmt, root_pat, |mc, sub_cmt, sub_pat| {
1310
1331
match sub_pat. node {
1311
1332
// `ref x` pattern
0 commit comments