Skip to content

Commit ef0f490

Browse files
committed
Tests around moving parts of structs and tuples across await points
1 parent 4be0675 commit ef0f490

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 }
+19
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`.
+15
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() {}
+14
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)