Skip to content

Commit 9b0b433

Browse files
Add test for upvar breakage
1 parent c5abcdb commit 9b0b433

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0597]: `y` does not live long enough
2+
--> $DIR/drop-live-upvar-2.rs:31:26
3+
|
4+
LL | let y = ();
5+
| - binding `y` declared here
6+
LL | drop_me = Droppy(&y);
7+
| ^^ borrowed value does not live long enough
8+
...
9+
LL | }
10+
| - `y` dropped here while still borrowed
11+
LL | }
12+
| - borrow might be used here, when `fut` is dropped and runs the destructor for coroutine
13+
|
14+
= note: values in a scope are dropped in the opposite order they are defined
15+
16+
error: aborting due to 1 previous error
17+
18+
For more information about this error, try `rustc --explain E0597`.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//@ revisions: may_dangle may_not_dangle
2+
//@[may_dangle] check-pass
3+
//@ edition: 2018
4+
5+
// Ensure that if a coroutine's interior has no drop types then we don't require the upvars to
6+
// be *use-live*, but instead require them to be *drop-live*. In this case, `Droppy<&'?0 ()>`
7+
// does not require that `'?0` is live for drops since the parameter is `#[may_dangle]` in
8+
// the may_dangle revision, but not in the may_not_dangle revision.
9+
10+
#![feature(dropck_eyepatch)]
11+
12+
struct Droppy<T>(T);
13+
14+
#[cfg(may_dangle)]
15+
unsafe impl<#[may_dangle] T> Drop for Droppy<T> {
16+
fn drop(&mut self) {
17+
// This does not use `T` of course.
18+
}
19+
}
20+
21+
#[cfg(may_not_dangle)]
22+
impl<T> Drop for Droppy<T> {
23+
fn drop(&mut self) {}
24+
}
25+
26+
fn main() {
27+
let drop_me;
28+
let fut;
29+
{
30+
let y = ();
31+
drop_me = Droppy(&y);
32+
//[may_not_dangle]~^ ERROR `y` does not live long enough
33+
fut = async {
34+
std::mem::drop(drop_me);
35+
};
36+
}
37+
}

0 commit comments

Comments
 (0)