Skip to content

Wrong suggestion for Boxxing body of async closure when expected return type of closure to be Box #111011

Closed
@fee1-dead

Description

@fee1-dead

Code

playground

#![feature(async_closure)]

fn uwu<X>(x: impl FnOnce() -> Box<X>) {}

fn main() {
    uwu(async move || {})
}

Current output

Compiling playground v0.0.1 (/playground)
error[E0308]: mismatched types
 --> src/main.rs:6:23
  |
6 |     uwu(async move || {})
  |                       ^^ expected `Box<_>`, found `async` closure body
  |
  = note:            expected struct `Box<_>`
          found `async` closure body `[async closure body@src/main.rs:6:23: 6:25]`
  = note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
help: store this in the heap by calling `Box::new`
  |
6 |     uwu(async move || Box::new({}))
  |                       +++++++++  +

For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` (bin "playground") due to previous error

Desired output

Compiling playground v0.0.1 (/playground)
error[E0308]: mismatched types
 --> src/main.rs:6:23
  |
6 |     uwu(async move || {})
  |                       ^^ expected `Box<_>`, found `async` closure body
  |
  = note:            expected struct `Box<_>`
          found `async` closure body `[async closure body@src/main.rs:6:23: 6:25]`
  = note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html

For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` (bin "playground") due to previous error

Rationale and extra context

No response

Other cases

No response

Anything else?

No response

Metadata

Metadata

Labels

A-async-closures`async || {}`A-diagnosticsArea: Messages for errors, warnings, and lintsD-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions