Skip to content

Commit 40cedf7

Browse files
Add regression ui test for #139839
1 parent a3c91ce commit 40cedf7

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// This is a regression test for <https://github.com/rust-lang/rust/issues/139839>.
2+
// It ensures that the "add `move` keyword" suggestion is valid.
3+
4+
//@ run-rustfix
5+
//@ edition:2024
6+
7+
#![feature(coroutines)]
8+
#![feature(gen_blocks)]
9+
#![feature(async_iterator)]
10+
11+
use std::async_iter::AsyncIterator;
12+
13+
#[allow(dead_code)]
14+
fn moved() -> impl AsyncIterator<Item = u32> {
15+
let mut x = "foo".to_string();
16+
17+
async gen move { //~ ERROR
18+
x.clear();
19+
for x in 3..6 { yield x }
20+
}
21+
}
22+
23+
fn main() {
24+
}

tests/ui/async-gen-move-suggestion.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// This is a regression test for <https://github.com/rust-lang/rust/issues/139839>.
2+
// It ensures that the "add `move` keyword" suggestion is valid.
3+
4+
//@ run-rustfix
5+
//@ edition:2024
6+
7+
#![feature(coroutines)]
8+
#![feature(gen_blocks)]
9+
#![feature(async_iterator)]
10+
11+
use std::async_iter::AsyncIterator;
12+
13+
#[allow(dead_code)]
14+
fn moved() -> impl AsyncIterator<Item = u32> {
15+
let mut x = "foo".to_string();
16+
17+
async gen { //~ ERROR
18+
x.clear();
19+
for x in 3..6 { yield x }
20+
}
21+
}
22+
23+
fn main() {
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
error[E0373]: async gen block may outlive the current function, but it borrows `x`, which is owned by the current function
2+
--> $DIR/async-gen-move-suggestion.rs:17:5
3+
|
4+
LL | async gen {
5+
| ^^^^^^^^^ may outlive borrowed value `x`
6+
LL | x.clear();
7+
| - `x` is borrowed here
8+
|
9+
note: async gen block is returned here
10+
--> $DIR/async-gen-move-suggestion.rs:17:5
11+
|
12+
LL | / async gen {
13+
LL | | x.clear();
14+
LL | | for x in 3..6 { yield x }
15+
LL | | }
16+
| |_____^
17+
help: to force the async gen block to take ownership of `x` (and any other referenced variables), use the `move` keyword
18+
|
19+
LL | async gen move {
20+
| ++++
21+
22+
error: aborting due to 1 previous error
23+
24+
For more information about this error, try `rustc --explain E0373`.

0 commit comments

Comments
 (0)