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