Fix #2979: inference for lifetimes of & expressions
What we now do is to create a region variable for each & expression (and also each borrow). The lifetime of this variable will be checked by borrowck to ensure it is not greater than the lifetime of the underlying data. This both leads to shorter lifetimes in some cases but also longer in others, such as taking the address to the interior of unique boxes tht are rooted in region pointers (e.g., returning a pointer to the interior of a sendable map). This may lead to issue #2977 if the rvalue is not POD, because we may drop the data in trans sooner than borrowck expects us to. Need to work out precisely where that fix ought to occur.
This commit is contained in:
parent
6ef13e76e9
commit
5d32d03b89
34 changed files with 717 additions and 320 deletions
|
@ -4,11 +4,10 @@ fn main() {
|
|||
// Here, the variable `p` gets inferred to a type with a lifetime
|
||||
// of the loop body. The regionck then determines that this type
|
||||
// is invalid.
|
||||
let mut p = //~ ERROR reference is not valid
|
||||
&x;
|
||||
let mut p = &x;
|
||||
|
||||
loop {
|
||||
let x = 1 + *p;
|
||||
p = &x;
|
||||
p = &x; //~ ERROR illegal borrow
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue