rust/compiler/rustc_infer
Matthias Krüger dad39e8840
Rollup merge of #126915 - SparkyPotato:fix-126903, r=compiler-errors
Don't suggest awaiting in closure patterns

Fixes #126903.

For
```rust
async fn do_async() {}

fn main() {
    Some(do_async()).map(|()| {});
}
```
the error is now
```rust
error[E0308]: mismatched types
 --> src/main.rs:4:27
  |
4 |     Some(do_async()).map(|()| {});
  |                           ^^
  |                           |
  |                           expected future, found `()`
  |                           expected due to this
  |
  = note: expected opaque type `impl Future<Output = ()>`
               found unit type `()`
```

Ideally, if `main` were to be `async`, it should be
```rs
error[E0308]: mismatched types
 --> src/main.rs:4:27
  |
4 |     Some(do_async()).map(|()| {});
  |                           ^^
  |                           |
  |                           expected future, found `()`
  |                           expected due to this
  |
  = note: expected opaque type `impl Future<Output = ()>`
               found unit type `()`
help: consider `await`ing on the `Future`
  |
4 |     Some(do_async().await).map(|()| {});
  |                    ++++++
```
However, this would mean `FnCtx::check_pat_top` would have to be called with an `origin_expr` in `rustc_hir_typeck::check::check_fn`, and that expr would have to be somehow plumbed through `FnCtxt::check_expr_closure` and closure signature deduction. I'm willing to work on the plumbing but unsure how to start.
2024-06-25 18:03:01 +02:00
..
src Rollup merge of #126915 - SparkyPotato:fix-126903, r=compiler-errors 2024-06-25 18:03:01 +02:00
Cargo.toml Remove some unnecessary crate dependencies. 2024-06-13 15:03:43 +10:00
messages.ftl Cleanup: Fix up some diagnostics 2024-05-22 22:40:34 +02:00