Skip to content

E0373 help suggests move async but the correct syntax is async move #61920

Closed
@sinkuu

Description

@sinkuu

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-async-awaitArea: Async & AwaitA-async-closures`async || {}`A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`AsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.C-bugCategory: This is a bug.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions