Make needs_drop less pessimistic on generators
This commit is contained in:
parent
8d67f576b5
commit
50c1c295ee
4 changed files with 29 additions and 18 deletions
|
|
@ -1,19 +1,16 @@
|
|||
error[E0597]: `a` does not live long enough
|
||||
--> $DIR/borrowing.rs:9:33
|
||||
|
|
||||
LL | let _b = {
|
||||
| -- borrow later stored here
|
||||
LL | let a = 3;
|
||||
LL | Pin::new(&mut || yield &a).resume(())
|
||||
| ----------^
|
||||
| | |
|
||||
| | borrowed value does not live long enough
|
||||
| -- ^ borrowed value does not live long enough
|
||||
| |
|
||||
| value captured here by generator
|
||||
| a temporary with access to the borrow is created here ...
|
||||
LL |
|
||||
LL | };
|
||||
| -- ... and the borrow might be used here, when that temporary is dropped and runs the destructor for generator
|
||||
| |
|
||||
| `a` dropped here while still borrowed
|
||||
|
|
||||
= note: The temporary is part of an expression at the end of a block. Consider forcing this temporary to be dropped sooner, before the block's local variables are dropped. For example, you could save the expression's value in a new local variable `x` and then make `x` be the expression at the end of the block.
|
||||
| - `a` dropped here while still borrowed
|
||||
|
||||
error[E0597]: `a` does not live long enough
|
||||
--> $DIR/borrowing.rs:16:20
|
||||
|
|
|
|||
|
|
@ -4,10 +4,9 @@ error[E0499]: cannot borrow `thing` as mutable more than once at a time
|
|||
LL | gen.as_mut().resume(&mut thing);
|
||||
| ---------- first mutable borrow occurs here
|
||||
LL | gen.as_mut().resume(&mut thing);
|
||||
| ^^^^^^^^^^ second mutable borrow occurs here
|
||||
LL |
|
||||
LL | }
|
||||
| - first borrow might be used here, when `gen` is dropped and runs the destructor for generator
|
||||
| ------ ^^^^^^^^^^ second mutable borrow occurs here
|
||||
| |
|
||||
| first borrow later used by call
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue