diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-05-20 08:31:42 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-20 08:31:42 +0200 |
| commit | 199d3bf3e406934a40d43c32333108a064be627e (patch) | |
| tree | bbc14d9fc062154819a2388500180b22da06f880 /compiler/rustc_parse/src/parser/mod.rs | |
| parent | 88552615e87028fe591486ba0bc166623711047e (diff) | |
| parent | 371de042d90f40fe5ec9a172971660da363ff08c (diff) | |
| download | rust-199d3bf3e406934a40d43c32333108a064be627e.tar.gz rust-199d3bf3e406934a40d43c32333108a064be627e.zip | |
Rollup merge of #125301 - jwong101:fix-static-coro-suggest, r=compiler-errors
fix suggestion in E0373 for !Unpin coroutines
Coroutines can be prefixed with the `static` keyword to make them
`!Unpin`.
However, given the following function:
```rust
fn check() -> impl Sized {
let x = 0;
#[coroutine]
static || {
yield;
x
}
}
```
We currently suggest prefixing `move` before `static`, which is
syntactically incorrect:
```
error[E0373]: coroutine may outlive the current function, but it borrows
...
--> src/main.rs:6:5
|
6 | static || {
| ^^^^^^^^^ may outlive borrowed value `x`
7 | yield;
8 | x
| - `x` is borrowed here
|
note: coroutine is returned here
--> src/main.rs:6:5
|
6 | / static || {
7 | | yield;
8 | | x
9 | | }
| |_____^
help: to force the coroutine to take ownership of `x` (and any other
referenced variables), use the `move` keyword
| // this is syntactically incorrect, it should be `static move ||`
6 | move static || {
| ++++
```
This PR suggests adding `move` after `static` for these coroutines.
I also added a UI test for this case.
Diffstat (limited to 'compiler/rustc_parse/src/parser/mod.rs')
0 files changed, 0 insertions, 0 deletions
