]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #107201 - compiler-errors:confusing-async-fn-note, r=estebank
authorMatthias Krüger <matthias.krueger@famsik.de>
Thu, 2 Feb 2023 05:52:13 +0000 (06:52 +0100)
committerGitHub <noreply@github.com>
Thu, 2 Feb 2023 05:52:13 +0000 (06:52 +0100)
Remove confusing 'while checking' note from opaque future type mismatches

Maybe I'm just misinterpreting the wording of the note. The only value I can see in this note is that it points out where the async's opaque future is coming from, but the way it's doing it is misleading IMO.

For example:

```rust
note: while checking the return type of the `async fn`
  --> $DIR/dont-suggest-missing-await.rs:7:24
   |
LL | async fn make_u32() -> u32 {
   |                        ^^^ checked the `Output` of this `async fn`, found opaque type
```

We point at the type `u32` in the HIR, but then say "found opaque type". We also say "while checking"... but we're typechecking a totally different function when we get this type mismatch!

r? ``@estebank`` but feel free to reassign and/or take your time reviewing this. I'd be inclined to also discuss reworking the presentation of this type mismatch to restore some of these labels in a way that makes it more clear what it's trying to point out.

1  2 
compiler/rustc_infer/src/infer/error_reporting/mod.rs
tests/ui/async-await/issue-61076.rs
tests/ui/async-await/issue-61076.stderr
tests/ui/async-await/issue-98634.stderr
tests/ui/async-await/issues/issue-102206.stderr
tests/ui/async-await/suggest-missing-await.stderr
tests/ui/impl-trait/issue-102605.stderr
tests/ui/impl-trait/issue-99914.stderr
tests/ui/type-alias-impl-trait/issue-98604.stderr

Simple merge
index 5a7316edd01f55ba5bca0df7e5c1a524a68db570,28a1a14aa8b040ec7090dcff51067612fe65f139..b25b29bf50c174fd18b5db994a8b6bd8a6d808a9
@@@ -62,13 -62,8 +62,8 @@@ LL |     match tuple() 
     |           ------- this expression has type `impl Future<Output = Tuple>`
  LL |
  LL |         Tuple(_) => {}
 -   |         ^^^^^^^^ expected opaque type, found struct `Tuple`
 +   |         ^^^^^^^^ expected opaque type, found `Tuple`
     |
- note: while checking the return type of the `async fn`
-   --> $DIR/issue-61076.rs:56:21
-    |
- LL | async fn tuple() -> Tuple {
-    |                     ^^^^^ checked the `Output` of this `async fn`, expected opaque type
     = note: expected opaque type `impl Future<Output = Tuple>`
                     found struct `Tuple`
  help: consider `await`ing on the `Future`
index 08ea5bdc574fa8551ef2837986f14d9545b98f0d,63156140b409ca2b8cbcacae7436626242c64e86..4c5dfeed9ba5c6e87992d40a0b9bb8350e9f56b3
@@@ -2,13 -2,8 +2,8 @@@ error[E0271]: expected `callback` to b
    --> $DIR/issue-98634.rs:45:23
     |
  LL |         StructAsync { callback }.await;
 -   |                       ^^^^^^^^ expected struct `Pin`, found opaque type
 +   |                       ^^^^^^^^ expected `Pin<Box<dyn Future<Output = ()>>>`, found opaque type
     |
- note: while checking the return type of the `async fn`
-   --> $DIR/issue-98634.rs:24:21
-    |
- LL | async fn callback() {}
-    |                     ^ checked the `Output` of this `async fn`, found opaque type
     = note:   expected struct `Pin<Box<(dyn Future<Output = ()> + 'static)>>`
             found opaque type `impl Future<Output = ()>`
  note: required by a bound in `StructAsync`
@@@ -21,13 -16,8 +16,8 @@@ error[E0271]: expected `callback` to b
    --> $DIR/issue-98634.rs:45:9
     |
  LL |         StructAsync { callback }.await;
 -   |         ^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `Pin`, found opaque type
 +   |         ^^^^^^^^^^^^^^^^^^^^^^^^ expected `Pin<Box<dyn Future<Output = ()>>>`, found opaque type
     |
- note: while checking the return type of the `async fn`
-   --> $DIR/issue-98634.rs:24:21
-    |
- LL | async fn callback() {}
-    |                     ^ checked the `Output` of this `async fn`, found opaque type
     = note:   expected struct `Pin<Box<(dyn Future<Output = ()> + 'static)>>`
             found opaque type `impl Future<Output = ()>`
  note: required by a bound in `StructAsync`
@@@ -40,13 -30,8 +30,8 @@@ error[E0271]: expected `callback` to b
    --> $DIR/issue-98634.rs:45:33
     |
  LL |         StructAsync { callback }.await;
 -   |                                 ^^^^^^ expected struct `Pin`, found opaque type
 +   |                                 ^^^^^^ expected `Pin<Box<dyn Future<Output = ()>>>`, found opaque type
     |
- note: while checking the return type of the `async fn`
-   --> $DIR/issue-98634.rs:24:21
-    |
- LL | async fn callback() {}
-    |                     ^ checked the `Output` of this `async fn`, found opaque type
     = note:   expected struct `Pin<Box<(dyn Future<Output = ()> + 'static)>>`
             found opaque type `impl Future<Output = ()>`
  note: required by a bound in `StructAsync`
index 2db0666f1ae6847ed4c8c292b160b7ae9198a103,dfafc810997ecbfc1e50cb60cb73ec18de3614f2..4ed0272ac1a127b7ebd9b0c08948541ddfa21afa
@@@ -127,13 -102,8 +102,8 @@@ LL |     match dummy_result() 
     |           -------------- this expression has type `impl Future<Output = Result<(), ()>>`
  ...
  LL |         Ok(_) => {}
 -   |         ^^^^^ expected opaque type, found enum `Result`
 +   |         ^^^^^ expected opaque type, found `Result<_, _>`
     |
- note: while checking the return type of the `async fn`
-   --> $DIR/suggest-missing-await.rs:57:28
-    |
- LL | async fn dummy_result() -> Result<(), ()> {
-    |                            ^^^^^^^^^^^^^^ checked the `Output` of this `async fn`, expected opaque type
     = note: expected opaque type `impl Future<Output = Result<(), ()>>`
                       found enum `Result<_, _>`
  help: consider `await`ing on the `Future`
@@@ -148,13 -118,8 +118,8 @@@ LL |     match dummy_result() 
     |           -------------- this expression has type `impl Future<Output = Result<(), ()>>`
  ...
  LL |         Err(_) => {}
 -   |         ^^^^^^ expected opaque type, found enum `Result`
 +   |         ^^^^^^ expected opaque type, found `Result<_, _>`
     |
- note: while checking the return type of the `async fn`
-   --> $DIR/suggest-missing-await.rs:57:28
-    |
- LL | async fn dummy_result() -> Result<(), ()> {
-    |                            ^^^^^^^^^^^^^^ checked the `Output` of this `async fn`, expected opaque type
     = note: expected opaque type `impl Future<Output = Result<(), ()>>`
                       found enum `Result<_, _>`
  help: consider `await`ing on the `Future`
index 3b4e130fdebde3e88c8da6f700867fb30abe5e94,db2a979cc50afd78e30e84e10cd7271f2f1115a3..a4b7fc1f5bc75e6e62e932461e6e3c32c0c3a1dd
@@@ -2,13 -2,8 +2,8 @@@ error[E0308]: mismatched type
    --> $DIR/issue-99914.rs:9:27
     |
  LL |     t.and_then(|t| -> _ { bar(t) });
 -   |                           ^^^^^^ expected enum `Result`, found opaque type
 +   |                           ^^^^^^ expected `Result<_, Error>`, found opaque type
     |
- note: while checking the return type of the `async fn`
-   --> $DIR/issue-99914.rs:13:23
-    |
- LL | async fn bar(t: Okay) {}
-    |                       ^ checked the `Output` of this `async fn`, found opaque type
     = note:     expected enum `Result<_, Error>`
             found opaque type `impl Future<Output = ()>`
  help: try wrapping the expression in `Ok`
index c5a4b5217d7a0aaddfb240ceb422f3fbceb180d3,570529322e60faeccc711821e46fc2f017a118db..bb9dd2365ea0d5de834978e859d5006c4fb3cd4f
@@@ -2,13 -2,8 +2,8 @@@ error[E0271]: expected `test` to be a f
    --> $DIR/issue-98604.rs:9:5
     |
  LL |     Box::new(test) as AsyncFnPtr;
 -   |     ^^^^^^^^^^^^^^ expected struct `Pin`, found opaque type
 +   |     ^^^^^^^^^^^^^^ expected `Pin<Box<dyn Future<Output = ()>>>`, found opaque type
     |
- note: while checking the return type of the `async fn`
-   --> $DIR/issue-98604.rs:5:17
-    |
- LL | async fn test() {}
-    |                 ^ checked the `Output` of this `async fn`, found opaque type
     = note:   expected struct `Pin<Box<(dyn Future<Output = ()> + 'static)>>`
             found opaque type `impl Future<Output = ()>`
     = note: required for the cast from `fn() -> impl Future<Output = ()> {test}` to the object type `dyn Fn() -> Pin<Box<(dyn Future<Output = ()> + 'static)>>`