about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNell Shamrell <nellshamrell@gmail.com>2021-02-15 14:27:36 -0800
committerNell Shamrell <nellshamrell@gmail.com>2021-02-24 18:46:54 -0800
commit356beb3084e2a76283a19218d7cef5954d7f79ae (patch)
treef4d5a8314f1e8371122b3f7f606f981a008d6cdf
parent1fdadbf13aecd190b277ea2aa1b125d2ed986d55 (diff)
downloadrust-356beb3084e2a76283a19218d7cef5954d7f79ae.tar.gz
rust-356beb3084e2a76283a19218d7cef5954d7f79ae.zip
clarifies error when finding mismatched returned types for async functions
Signed-off-by: Nell Shamrell <nellshamrell@gmail.com>
-rw-r--r--compiler/rustc_infer/src/infer/error_reporting/mod.rs13
-rw-r--r--src/test/ui/async-await/dont-suggest-missing-await.stderr3
-rw-r--r--src/test/ui/async-await/generator-desc.stderr6
-rw-r--r--src/test/ui/async-await/issue-61076.rs3
-rw-r--r--src/test/ui/async-await/issue-61076.stderr3
-rw-r--r--src/test/ui/async-await/suggest-missing-await-closure.stderr3
-rw-r--r--src/test/ui/async-await/suggest-missing-await.stderr6
-rw-r--r--src/test/ui/parser/fn-header-semantic-fail.stderr6
-rw-r--r--src/test/ui/resolve/issue-70736-async-fn-no-body-def-collector.stderr3
-rw-r--r--src/test/ui/suggestions/issue-81839.stderr3
-rw-r--r--src/test/ui/suggestions/match-prev-arm-needing-semi.rs9
-rw-r--r--src/test/ui/suggestions/match-prev-arm-needing-semi.stderr13
12 files changed, 49 insertions, 22 deletions
diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs
index 9e55f7e5589..2d5f43e5890 100644
--- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs
+++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs
@@ -1484,13 +1484,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
                 for (key, values) in types.iter() {
                     let count = values.len();
                     let kind = key.descr();
+                    let mut returned_async_output_error = false;
                     for sp in values {
                         err.span_label(
                             *sp,
                             format!(
                                 "{}{}{} {}{}",
-                                if sp.is_desugaring(DesugaringKind::Async) {
-                                    "the `Output` of this `async fn`'s "
+                                if sp.is_desugaring(DesugaringKind::Async)
+                                    && !returned_async_output_error
+                                {
+                                    "checked the `Output` of this `async fn`, "
                                 } else if count == 1 {
                                     "the "
                                 } else {
@@ -1502,6 +1505,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
                                 pluralize!(count),
                             ),
                         );
+                        if sp.is_desugaring(DesugaringKind::Async)
+                            && returned_async_output_error == false
+                        {
+                            err.note("while checking the return type of the `async fn`");
+                            returned_async_output_error = true;
+                        }
                     }
                 }
             }
diff --git a/src/test/ui/async-await/dont-suggest-missing-await.stderr b/src/test/ui/async-await/dont-suggest-missing-await.stderr
index 14e72c2b1e7..654a3bcc92d 100644
--- a/src/test/ui/async-await/dont-suggest-missing-await.stderr
+++ b/src/test/ui/async-await/dont-suggest-missing-await.stderr
@@ -2,11 +2,12 @@ error[E0308]: mismatched types
   --> $DIR/dont-suggest-missing-await.rs:14:18
    |
 LL | async fn make_u32() -> u32 {
-   |                        --- the `Output` of this `async fn`'s found opaque type
+   |                        --- checked the `Output` of this `async fn`, found opaque type
 ...
 LL |         take_u32(x)
    |                  ^ expected `u32`, found opaque type
    |
+   = note: while checking the return type of the `async fn`
    = note:     expected type `u32`
            found opaque type `impl Future`
 help: consider `await`ing on the `Future`
diff --git a/src/test/ui/async-await/generator-desc.stderr b/src/test/ui/async-await/generator-desc.stderr
index b85926c7a03..04f191cc5e8 100644
--- a/src/test/ui/async-await/generator-desc.stderr
+++ b/src/test/ui/async-await/generator-desc.stderr
@@ -13,13 +13,15 @@ error[E0308]: mismatched types
   --> $DIR/generator-desc.rs:12:16
    |
 LL | async fn one() {}
-   |                - the `Output` of this `async fn`'s expected opaque type
+   |                - checked the `Output` of this `async fn`, expected opaque type
 LL | async fn two() {}
-   |                - the `Output` of this `async fn`'s found opaque type
+   |                - checked the `Output` of this `async fn`, found opaque type
 ...
 LL |     fun(one(), two());
    |                ^^^^^ expected opaque type, found a different opaque type
    |
+   = note: while checking the return type of the `async fn`
+   = note: while checking the return type of the `async fn`
    = note: expected opaque type `impl Future` (opaque type at <$DIR/generator-desc.rs:5:16>)
               found opaque type `impl Future` (opaque type at <$DIR/generator-desc.rs:6:16>)
    = help: consider `await`ing on both `Future`s
diff --git a/src/test/ui/async-await/issue-61076.rs b/src/test/ui/async-await/issue-61076.rs
index 8a7b166cb15..4a8e841b33d 100644
--- a/src/test/ui/async-await/issue-61076.rs
+++ b/src/test/ui/async-await/issue-61076.rs
@@ -56,7 +56,7 @@ async fn struct_() -> Struct {
 }
 
 async fn tuple() -> Tuple {
-    //~^ NOTE the `Output` of this `async fn`'s expected opaque type
+    //~^ NOTE checked the `Output` of this `async fn`, expected opaque type
     Tuple(1i32)
 }
 
@@ -92,6 +92,7 @@ async fn match_() {
         Tuple(_) => {} //~ ERROR mismatched types
         //~^ NOTE expected opaque type, found struct `Tuple`
         //~| NOTE expected opaque type `impl Future`
+        //~| NOTE while checking the return type of the `async fn`
     }
 }
 
diff --git a/src/test/ui/async-await/issue-61076.stderr b/src/test/ui/async-await/issue-61076.stderr
index db6dc3ea00a..fd00522fac7 100644
--- a/src/test/ui/async-await/issue-61076.stderr
+++ b/src/test/ui/async-await/issue-61076.stderr
@@ -61,11 +61,12 @@ error[E0308]: mismatched types
   --> $DIR/issue-61076.rs:92:9
    |
 LL | async fn tuple() -> Tuple {
-   |                     ----- the `Output` of this `async fn`'s expected opaque type
+   |                     ----- checked the `Output` of this `async fn`, expected opaque type
 ...
 LL |         Tuple(_) => {}
    |         ^^^^^^^^ expected opaque type, found struct `Tuple`
    |
+   = note: while checking the return type of the `async fn`
    = note: expected opaque type `impl Future`
                    found struct `Tuple`
 help: consider `await`ing on the `Future`
diff --git a/src/test/ui/async-await/suggest-missing-await-closure.stderr b/src/test/ui/async-await/suggest-missing-await-closure.stderr
index 2151057aa7f..483e52536a1 100644
--- a/src/test/ui/async-await/suggest-missing-await-closure.stderr
+++ b/src/test/ui/async-await/suggest-missing-await-closure.stderr
@@ -2,11 +2,12 @@ error[E0308]: mismatched types
   --> $DIR/suggest-missing-await-closure.rs:16:18
    |
 LL | async fn make_u32() -> u32 {
-   |                        --- the `Output` of this `async fn`'s found opaque type
+   |                        --- checked the `Output` of this `async fn`, found opaque type
 ...
 LL |         take_u32(x)
    |                  ^ expected `u32`, found opaque type
    |
+   = note: while checking the return type of the `async fn`
    = note:     expected type `u32`
            found opaque type `impl Future`
 help: consider `await`ing on the `Future`
diff --git a/src/test/ui/async-await/suggest-missing-await.stderr b/src/test/ui/async-await/suggest-missing-await.stderr
index 26e81a52c21..14b5ee95ee8 100644
--- a/src/test/ui/async-await/suggest-missing-await.stderr
+++ b/src/test/ui/async-await/suggest-missing-await.stderr
@@ -2,11 +2,12 @@ error[E0308]: mismatched types
   --> $DIR/suggest-missing-await.rs:12:14
    |
 LL | async fn make_u32() -> u32 {
-   |                        --- the `Output` of this `async fn`'s found opaque type
+   |                        --- checked the `Output` of this `async fn`, found opaque type
 ...
 LL |     take_u32(x)
    |              ^ expected `u32`, found opaque type
    |
+   = note: while checking the return type of the `async fn`
    = note:     expected type `u32`
            found opaque type `impl Future`
 help: consider `await`ing on the `Future`
@@ -18,11 +19,12 @@ error[E0308]: mismatched types
   --> $DIR/suggest-missing-await.rs:22:5
    |
 LL | async fn dummy() {}
-   |                  - the `Output` of this `async fn`'s found opaque type
+   |                  - checked the `Output` of this `async fn`, found opaque type
 ...
 LL |     dummy()
    |     ^^^^^^^ expected `()`, found opaque type
    |
+   = note: while checking the return type of the `async fn`
    = note: expected unit type `()`
             found opaque type `impl Future`
 help: consider `await`ing on the `Future`
diff --git a/src/test/ui/parser/fn-header-semantic-fail.stderr b/src/test/ui/parser/fn-header-semantic-fail.stderr
index 4fde243b2f8..2e513415e6c 100644
--- a/src/test/ui/parser/fn-header-semantic-fail.stderr
+++ b/src/test/ui/parser/fn-header-semantic-fail.stderr
@@ -189,9 +189,10 @@ LL |         async fn ft1();
 LL |         async fn ft1() {}
    |                        ^
    |                        |
-   |                        the `Output` of this `async fn`'s found opaque type
+   |                        checked the `Output` of this `async fn`, found opaque type
    |                        expected `()`, found opaque type
    |
+   = note: while checking the return type of the `async fn`
    = note: expected fn pointer `fn()`
               found fn pointer `fn() -> impl Future`
 
@@ -204,9 +205,10 @@ LL |         const async unsafe extern "C" fn ft5();
 LL |         const async unsafe extern "C" fn ft5() {}
    |                                                ^
    |                                                |
-   |                                                the `Output` of this `async fn`'s found opaque type
+   |                                                checked the `Output` of this `async fn`, found opaque type
    |                                                expected `()`, found opaque type
    |
+   = note: while checking the return type of the `async fn`
    = note: expected fn pointer `unsafe extern "C" fn()`
               found fn pointer `unsafe extern "C" fn() -> impl Future`
 
diff --git a/src/test/ui/resolve/issue-70736-async-fn-no-body-def-collector.stderr b/src/test/ui/resolve/issue-70736-async-fn-no-body-def-collector.stderr
index 9b59e415011..4025b5030dc 100644
--- a/src/test/ui/resolve/issue-70736-async-fn-no-body-def-collector.stderr
+++ b/src/test/ui/resolve/issue-70736-async-fn-no-body-def-collector.stderr
@@ -53,9 +53,10 @@ LL |     async fn associated();
 LL |     async fn associated();
    |                          ^
    |                          |
-   |                          the `Output` of this `async fn`'s found opaque type
+   |                          checked the `Output` of this `async fn`, found opaque type
    |                          expected `()`, found opaque type
    |
+   = note: while checking the return type of the `async fn`
    = note: expected fn pointer `fn()`
               found fn pointer `fn() -> impl Future`
 
diff --git a/src/test/ui/suggestions/issue-81839.stderr b/src/test/ui/suggestions/issue-81839.stderr
index 1a289d39e44..f9076587087 100644
--- a/src/test/ui/suggestions/issue-81839.stderr
+++ b/src/test/ui/suggestions/issue-81839.stderr
@@ -17,8 +17,9 @@ LL | |     }
   ::: $DIR/auxiliary/issue-81839.rs:6:49
    |
 LL |       pub async fn answer_str(&self, _s: &str) -> Test {
-   |                                                   ---- the `Output` of this `async fn`'s found opaque type
+   |                                                   ---- checked the `Output` of this `async fn`, found opaque type
    |
+   = note: while checking the return type of the `async fn`
    = note:     expected type `()`
            found opaque type `impl Future`
 
diff --git a/src/test/ui/suggestions/match-prev-arm-needing-semi.rs b/src/test/ui/suggestions/match-prev-arm-needing-semi.rs
index b8ac030b0bb..3b2cff3140d 100644
--- a/src/test/ui/suggestions/match-prev-arm-needing-semi.rs
+++ b/src/test/ui/suggestions/match-prev-arm-needing-semi.rs
@@ -13,9 +13,9 @@ fn extra_semicolon() {
     };
 }
 
-async fn async_dummy() {} //~ NOTE the `Output` of this `async fn`'s found opaque type
-async fn async_dummy2() {} //~ NOTE the `Output` of this `async fn`'s found opaque type
-//~^ NOTE the `Output` of this `async fn`'s found opaque type
+async fn async_dummy() {} //~ NOTE checked the `Output` of this `async fn`, found opaque type
+async fn async_dummy2() {} //~ NOTE checked the `Output` of this `async fn`, found opaque type
+//~| NOTE checked the `Output` of this `async fn`, found opaque type
 
 async fn async_extra_semicolon_same() {
     let _ = match true { //~ NOTE `match` arms have incompatible types
@@ -26,6 +26,7 @@ async fn async_extra_semicolon_same() {
         false => async_dummy(), //~ ERROR `match` arms have incompatible types
         //~^ NOTE expected `()`, found opaque type
         //~| NOTE expected type `()`
+        //~| NOTE while checking the return type of the `async fn`
         //~| HELP consider `await`ing on the `Future`
     };
 }
@@ -39,6 +40,7 @@ async fn async_extra_semicolon_different() {
         false => async_dummy2(), //~ ERROR `match` arms have incompatible types
         //~^ NOTE expected `()`, found opaque type
         //~| NOTE expected type `()`
+        //~| NOTE while checking the return type of the `async fn`
         //~| HELP consider `await`ing on the `Future`
     };
 }
@@ -51,6 +53,7 @@ async fn async_different_futures() {
         //~^ NOTE expected opaque type, found a different opaque type
         //~| NOTE expected type `impl Future`
         //~| NOTE distinct uses of `impl Trait` result in different opaque types
+        //~| NOTE while checking the return type of the `async fn`
     };
 }
 
diff --git a/src/test/ui/suggestions/match-prev-arm-needing-semi.stderr b/src/test/ui/suggestions/match-prev-arm-needing-semi.stderr
index fae0c498b44..e31ea9679b5 100644
--- a/src/test/ui/suggestions/match-prev-arm-needing-semi.stderr
+++ b/src/test/ui/suggestions/match-prev-arm-needing-semi.stderr
@@ -2,7 +2,7 @@ error[E0308]: `match` arms have incompatible types
   --> $DIR/match-prev-arm-needing-semi.rs:26:18
    |
 LL |   async fn async_dummy() {}
-   |                          - the `Output` of this `async fn`'s found opaque type
+   |                          - checked the `Output` of this `async fn`, found opaque type
 ...
 LL |       let _ = match true {
    |  _____________-
@@ -18,6 +18,7 @@ LL | |
 LL | |     };
    | |_____- `match` arms have incompatible types
    |
+   = note: while checking the return type of the `async fn`
    = note:     expected type `()`
            found opaque type `impl Future`
 help: consider `await`ing on the `Future`
@@ -30,10 +31,10 @@ LL |             async_dummy()
    |                         --
 
 error[E0308]: `match` arms have incompatible types
-  --> $DIR/match-prev-arm-needing-semi.rs:39:18
+  --> $DIR/match-prev-arm-needing-semi.rs:40:18
    |
 LL |   async fn async_dummy2() {}
-   |                           - the `Output` of this `async fn`'s found opaque type
+   |                           - checked the `Output` of this `async fn`, found opaque type
 ...
 LL |       let _ = match true {
    |  _____________-
@@ -49,6 +50,7 @@ LL | |
 LL | |     };
    | |_____- `match` arms have incompatible types
    |
+   = note: while checking the return type of the `async fn`
    = note:     expected type `()`
            found opaque type `impl Future`
 help: consider `await`ing on the `Future`
@@ -64,10 +66,10 @@ LL |         false => Box::new(async_dummy2()),
    |
 
 error[E0308]: `match` arms have incompatible types
-  --> $DIR/match-prev-arm-needing-semi.rs:50:18
+  --> $DIR/match-prev-arm-needing-semi.rs:52:18
    |
 LL |   async fn async_dummy2() {}
-   |                           - the `Output` of this `async fn`'s found opaque type
+   |                           - checked the `Output` of this `async fn`, found opaque type
 ...
 LL |       let _ = match true {
    |  _____________-
@@ -81,6 +83,7 @@ LL | |
 LL | |     };
    | |_____- `match` arms have incompatible types
    |
+   = note: while checking the return type of the `async fn`
    = note:     expected type `impl Future` (opaque type at <$DIR/match-prev-arm-needing-semi.rs:16:24>)
            found opaque type `impl Future` (opaque type at <$DIR/match-prev-arm-needing-semi.rs:17:25>)
    = note: distinct uses of `impl Trait` result in different opaque types