From 356beb3084e2a76283a19218d7cef5954d7f79ae Mon Sep 17 00:00:00 2001 From: Nell Shamrell Date: Mon, 15 Feb 2021 14:27:36 -0800 Subject: [PATCH] clarifies error when finding mismatched returned types for async functions Signed-off-by: Nell Shamrell --- .../rustc_infer/src/infer/error_reporting/mod.rs | 13 +++++++++++-- .../async-await/dont-suggest-missing-await.stderr | 3 ++- src/test/ui/async-await/generator-desc.stderr | 6 ++++-- src/test/ui/async-await/issue-61076.rs | 3 ++- src/test/ui/async-await/issue-61076.stderr | 3 ++- .../suggest-missing-await-closure.stderr | 3 ++- .../ui/async-await/suggest-missing-await.stderr | 6 ++++-- src/test/ui/parser/fn-header-semantic-fail.stderr | 6 ++++-- ...ssue-70736-async-fn-no-body-def-collector.stderr | 3 ++- src/test/ui/suggestions/issue-81839.stderr | 3 ++- .../ui/suggestions/match-prev-arm-needing-semi.rs | 9 ++++++--- .../suggestions/match-prev-arm-needing-semi.stderr | 13 ++++++++----- 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 9e55f7e558999..2d5f43e5890d0 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 14e72c2b1e7e2..654a3bcc92dd8 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 b85926c7a03c0..04f191cc5e8cb 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 8a7b166cb15bd..4a8e841b33d49 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 db6dc3ea00a8d..fd00522fac703 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 2151057aa7fc0..483e52536a1b4 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 26e81a52c2141..14b5ee95ee8ba 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 4fde243b2f8ec..2e513415e6c64 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 9b59e41501102..4025b5030dc0f 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 1a289d39e4467..f907658708730 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 b8ac030b0bbbe..3b2cff3140d63 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 fae0c498b440a..e31ea9679b51d 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