nikomatsakis / borrowck

Modeling NLL and the Rust borrowck
Apache License 2.0
75 stars 12 forks source link

model deferred borrows for nested method calls #3

Open nikomatsakis opened 7 years ago

nikomatsakis commented 7 years ago

I think my preference would be to extend the & operator with a defer "attribute:"

x = #[defer] &foo;

As a pre-pass to the processing, we would compute the "deferred region" R_D by looking for the next use of x. The 'loans in scope' would then create two loan entries, one for the main loan, and one for the same point that is deferred. We would give the deferred loan the region R_D; the main loans would be generated at the first-uses (i.e., as we exit the region R_D).

We then have to modify also the pass which checks that each action is legal: in particular, issuing a loan when there is a deferred region in scope is only legal if the lifetime of the loan is a subset of the deferred region R_D.