diff options
| author | Joshua Wong <joshuawong@anticentri.st> | 2024-05-19 19:23:38 -0500 |
|---|---|---|
| committer | Joshua Wong <joshuawong@anticentri.st> | 2024-05-19 19:23:38 -0500 |
| commit | 371de042d90f40fe5ec9a172971660da363ff08c (patch) | |
| tree | 28c8ef7b8df7786253d5fea6c27879c8d5d84b5a | |
| parent | 5d7eda224e2c87b95a327f9279dbb25b89d24724 (diff) | |
| download | rust-371de042d90f40fe5ec9a172971660da363ff08c.tar.gz rust-371de042d90f40fe5ec9a172971660da363ff08c.zip | |
add ui tests for E0373 suggestion
| -rw-r--r-- | tests/ui/coroutine/static-move-suggestion.fixed | 19 | ||||
| -rw-r--r-- | tests/ui/coroutine/static-move-suggestion.rs | 19 | ||||
| -rw-r--r-- | tests/ui/coroutine/static-move-suggestion.stderr | 26 |
3 files changed, 64 insertions, 0 deletions
diff --git a/tests/ui/coroutine/static-move-suggestion.fixed b/tests/ui/coroutine/static-move-suggestion.fixed new file mode 100644 index 00000000000..56445be4715 --- /dev/null +++ b/tests/ui/coroutine/static-move-suggestion.fixed @@ -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(); +} diff --git a/tests/ui/coroutine/static-move-suggestion.rs b/tests/ui/coroutine/static-move-suggestion.rs new file mode 100644 index 00000000000..1d6e4a62883 --- /dev/null +++ b/tests/ui/coroutine/static-move-suggestion.rs @@ -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(); +} diff --git a/tests/ui/coroutine/static-move-suggestion.stderr b/tests/ui/coroutine/static-move-suggestion.stderr new file mode 100644 index 00000000000..6d890468b32 --- /dev/null +++ b/tests/ui/coroutine/static-move-suggestion.stderr @@ -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`. |
