-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #49943 - pnkfelix:fix-issue-49918, r=nikomatsakis
Treat generators as if they have an arbitrary destructor Conservatively assume dropping a generator touches its upvars, via locals' destructors. Fix #49918
- Loading branch information
Showing
7 changed files
with
106 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,30 @@ | ||
error: compilation successful | ||
--> $DIR/borrowing.rs:15:1 | ||
error[E0597]: `a` does not live long enough | ||
--> $DIR/borrowing.rs:18:18 | ||
| | ||
LL | / fn main() { #![rustc_error] // rust-lang/rust#49855 | ||
LL | | let _b = { | ||
LL | | let a = 3; | ||
LL | | unsafe { (|| yield &a).resume() } | ||
... | | ||
LL | | }; | ||
LL | | } | ||
| |_^ | ||
LL | unsafe { (|| yield &a).resume() } | ||
| ^^^^^^^^^^^^^ | ||
| | | ||
| borrowed value does not live long enough | ||
| borrow may end up in a temporary, created here | ||
LL | //~^ ERROR: `a` does not live long enough | ||
LL | }; | ||
| -- temporary later dropped here, potentially using the reference | ||
| | | ||
| borrowed value only lives until here | ||
|
||
error: aborting due to previous error | ||
error[E0597]: `a` does not live long enough | ||
--> $DIR/borrowing.rs:24:9 | ||
| | ||
LL | / || { | ||
LL | | yield &a | ||
LL | | //~^ ERROR: `a` does not live long enough | ||
LL | | } | ||
| |_________^ borrowed value does not live long enough | ||
LL | }; | ||
| - borrowed value only lives until here | ||
LL | } | ||
| - borrow later used here, when `_b` is dropped | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0597`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,20 @@ | ||
error: compilation successful | ||
--> $DIR/dropck.rs:16:1 | ||
error[E0597]: `ref_` does not live long enough | ||
--> $DIR/dropck.rs:22:11 | ||
| | ||
LL | / fn main() { #![rustc_error] // rust-lang/rust#49855 | ||
LL | | let (cell, mut gen); | ||
LL | | cell = Box::new(RefCell::new(0)); | ||
LL | | let ref_ = Box::leak(Box::new(Some(cell.borrow_mut()))); | ||
... | | ||
LL | | // drops the RefCell and then the Ref, leading to use-after-free | ||
LL | | } | ||
| |_^ | ||
LL | gen = || { | ||
| ___________^ | ||
LL | | // but the generator can use it to drop a `Ref<'a, i32>`. | ||
LL | | let _d = ref_.take(); //~ ERROR `ref_` does not live long enough | ||
LL | | yield; | ||
LL | | }; | ||
| |_____^ borrowed value does not live long enough | ||
... | ||
LL | } | ||
| - | ||
| | | ||
| borrowed value only lives until here | ||
| borrow later used here, when `gen` is dropped | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0597`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 13 additions & 5 deletions
18
src/test/ui/generator/ref-escapes-but-not-over-yield.nll.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters