Skip to content

Commit 051f94d

Browse files
authored
Rollup merge of rust-lang#63310 - gorup:partial-moves, r=cramertj
Tests around moving parts of structs and tuples across await points r? cramertj Per the [dropbox paper](https://paper.dropbox.com/doc/async.await-Call-for-Tests--AiR3vlp1s_Kw0yzWZ1sWMnaIAQ-nMyZGrra7dz9KcFRMLKJy) about more tests, it appears there are some tests wanted around local variables (under the section ["Dynamic semantics"](https://paper.dropbox.com/doc/async.await-Call-for-Tests--AiR3vlp1s_Kw0yzWZ1sWMnaIAg-nMyZGrra7dz9KcFRMLKJy#:uid=122335511260129643493892&h2=Dynamic-semantics)). Here is one commit, and I can probably get code up for other scenarios listed there, although I may not have the full background to know what is being targeted by the tests. Please assist me if I'm off course, thanks! --- - Executed all 4 new tests - Executed `tidy` command
2 parents f635ce5 + ef0f490 commit 051f94d

6 files changed

+95
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// build-pass
2+
// edition:2018
3+
// compile-flags: --crate-type lib
4+
5+
#![feature(async_await)]
6+
7+
struct Small {
8+
x: Vec<usize>,
9+
y: Vec<usize>,
10+
}
11+
12+
// You are allowed to move out part of a struct to an async fn, you still
13+
// have access to remaining parts after awaiting
14+
async fn move_part_await_return_rest_struct() -> Vec<usize> {
15+
let s = Small { x: vec![31], y: vec![19, 1441] };
16+
needs_vec(s.x).await;
17+
s.y
18+
}
19+
20+
async fn needs_vec(_vec: Vec<usize>) {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// build-pass
2+
// edition:2018
3+
// compile-flags: --crate-type lib
4+
5+
#![feature(async_await)]
6+
7+
async fn move_part_await_return_rest_tuple() -> Vec<usize> {
8+
let x = (vec![3], vec![4, 4]);
9+
drop(x.1);
10+
echo(x.0[0]).await;
11+
x.0
12+
}
13+
14+
async fn echo(x: usize) -> usize { x }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// compile-fail
2+
// edition:2018
3+
// compile-flags: --crate-type lib
4+
5+
#![feature(async_await)]
6+
7+
async fn no_move_across_await_struct() -> Vec<usize> {
8+
let s = Small { x: vec![31], y: vec![19, 1441] };
9+
needs_vec(s.x).await;
10+
s.x
11+
//~^ ERROR use of moved value: `s.x`
12+
}
13+
14+
struct Small {
15+
x: Vec<usize>,
16+
y: Vec<usize>,
17+
}
18+
19+
async fn needs_vec(_vec: Vec<usize>) {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0382]: use of moved value: `s.x`
2+
--> $DIR/no-move-across-await-struct.rs:10:5
3+
|
4+
LL | needs_vec(s.x).await;
5+
| --- value moved here
6+
LL | s.x
7+
| ^^^ value used here after move
8+
|
9+
= note: move occurs because `s.x` has type `std::vec::Vec<usize>`, which does not implement the `Copy` trait
10+
11+
error: aborting due to previous error
12+
13+
For more information about this error, try `rustc --explain E0382`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// compile-fail
2+
// edition:2018
3+
// compile-flags: --crate-type lib
4+
5+
#![feature(async_await)]
6+
7+
async fn no_move_across_await_tuple() -> Vec<usize> {
8+
let x = (vec![3], vec![4, 4]);
9+
drop(x.1);
10+
nothing().await;
11+
x.1
12+
//~^ ERROR use of moved value: `x.1`
13+
}
14+
15+
async fn nothing() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0382]: use of moved value: `x.1`
2+
--> $DIR/no-move-across-await-tuple.rs:11:5
3+
|
4+
LL | drop(x.1);
5+
| --- value moved here
6+
LL | nothing().await;
7+
LL | x.1
8+
| ^^^ value used here after move
9+
|
10+
= note: move occurs because `x.1` has type `std::vec::Vec<usize>`, which does not implement the `Copy` trait
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0382`.

0 commit comments

Comments
 (0)