add ui tests for E0373 suggestion
This commit is contained in:
parent
5d7eda224e
commit
371de042d9
19
tests/ui/coroutine/static-move-suggestion.fixed
Normal file
19
tests/ui/coroutine/static-move-suggestion.fixed
Normal file
@ -0,0 +1,19 @@
|
||||
//@ run-rustfix
|
||||
|
||||
// check to make sure that we suggest adding `move` after `static`
|
||||
|
||||
#![feature(coroutines)]
|
||||
|
||||
fn check() -> impl Sized {
|
||||
let x = 0;
|
||||
#[coroutine]
|
||||
static move || {
|
||||
//~^ ERROR E0373
|
||||
yield;
|
||||
x
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
check();
|
||||
}
|
19
tests/ui/coroutine/static-move-suggestion.rs
Normal file
19
tests/ui/coroutine/static-move-suggestion.rs
Normal file
@ -0,0 +1,19 @@
|
||||
//@ run-rustfix
|
||||
|
||||
// check to make sure that we suggest adding `move` after `static`
|
||||
|
||||
#![feature(coroutines)]
|
||||
|
||||
fn check() -> impl Sized {
|
||||
let x = 0;
|
||||
#[coroutine]
|
||||
static || {
|
||||
//~^ ERROR E0373
|
||||
yield;
|
||||
x
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
check();
|
||||
}
|
26
tests/ui/coroutine/static-move-suggestion.stderr
Normal file
26
tests/ui/coroutine/static-move-suggestion.stderr
Normal file
@ -0,0 +1,26 @@
|
||||
error[E0373]: coroutine may outlive the current function, but it borrows `x`, which is owned by the current function
|
||||
--> $DIR/static-move-suggestion.rs:10:5
|
||||
|
|
||||
LL | static || {
|
||||
| ^^^^^^^^^ may outlive borrowed value `x`
|
||||
...
|
||||
LL | x
|
||||
| - `x` is borrowed here
|
||||
|
|
||||
note: coroutine is returned here
|
||||
--> $DIR/static-move-suggestion.rs:10:5
|
||||
|
|
||||
LL | / static || {
|
||||
LL | |
|
||||
LL | | yield;
|
||||
LL | | x
|
||||
LL | | }
|
||||
| |_____^
|
||||
help: to force the coroutine to take ownership of `x` (and any other referenced variables), use the `move` keyword
|
||||
|
|
||||
LL | static move || {
|
||||
| ++++
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0373`.
|
Loading…
Reference in New Issue
Block a user