Rust: E0373 help suggests `move async` but the correct syntax is `async move`

Created on 18 Jun 2019  路  7Comments  路  Source: rust-lang/rust

E0373 help suggests appending move in front of async closures:

error[E0373]: closure may outlive the current function, but it borrows `n`, which is owned by the current function
  --> src/main.rs:10:19
   |
10 |         Box::pin((async || {
   |                   ^^^^^^^^ may outlive borrowed value `n`
11 |             Some((n, n + 1))
   |                   - `n` is borrowed here
   |
note: closure is returned here
  --> src/main.rs:10:9
   |
10 | /         Box::pin((async || {
11 | |             Some((n, n + 1))
12 | |         })())
   | |_____________^
help: to force the closure to take ownership of `n` (and any other referenced variables), use the `move` keyword
   |
10 |         Box::pin((move async || {
   |                   ^^^^^^^^^^^^^

but move async is not in the correct order:

error: expected one of `|` or `||`, found `async`
  --> src/main.rs:10:24
   |
10 |         Box::pin((move async || {
   |                        ^^^^^ expected one of `|` or `||` here

The suggestion should be async move || { ... instead.

Meta: rustc 1.37.0-nightly (4edff843d 2019-06-16)

A-async-await A-diagnostics A-suggestion-diagnostics AsyncAwait-Triaged C-bug F-async_closures requires-nightly

Most helpful comment

@estebank this issue is now fixed. Can you close it for me please?

All 7 comments

Marking as "deferred" because async closures are not a candidate for stabilization. async blocks do not give any similar suggestion, though it would be nice if they did:

error[E0597]: `a` does not live long enough
 --> src/main.rs:7:30
  |
4 |       let x = {
  |           - borrow later stored here
5 |           let a = 5;
6 |           async {
  |  _______________-
7 | |             println!("{:?}", a);
  | |                              ^ borrowed value does not live long enough
8 | |         }
  | |_________- value captured here by generator
9 |       };
  |       - `a` dropped here while still borrowed

Marking as "deferred" because async closures are not a candidate for stabilization

@cramertj if we're making the suggestion now then it is _wrong_ and we should at least _hide it_. Users will get confused if they are offered a feature that is not yet stable, and even worse offered it with the wrong syntax.

cc @rust-lang/wg-diagnostics

@estebank we're not making the suggestion for any stable code, or any code we intend to stabilize.

Oh! That's a different case entirely :)

RipGrepped for "move async " in the current codebase and not found so I think someone's already fixed this? - move to close.

This is not fixed (playground - I should have provided one). IIRC E0373's suggestion just adds "move " in front of the closure span.

@estebank this issue is now fixed. Can you close it for me please?

Was this page helpful?
0 / 5 - 0 ratings