diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index e3a79fe265330..3041fb7ae2e5a 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -1481,35 +1481,27 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { target: &str, types: &FxHashMap>, ) { - for (key, values) in types.iter() { - let count = values.len(); - let kind = key.descr(); + for (ty_category, spans) in types.iter() { + let count = spans.len(); + let kind = ty_category.descr(); let mut returned_async_output_error = false; - for sp in values { - err.span_label( - *sp, - format!( - "{}{}{} {}{}", - if sp.is_desugaring(DesugaringKind::Async) - && !returned_async_output_error - { - "checked the `Output` of this `async fn`, " - } else if count == 1 { - "the " - } else { - "" - }, - if count > 1 { "one of the " } else { "" }, - target, - kind, - pluralize!(count), - ), - ); - if sp.is_desugaring(DesugaringKind::Async) - && returned_async_output_error == false - { + for sp in spans { + if sp.is_desugaring(DesugaringKind::Async) && !returned_async_output_error { + err.span_label(*sp, format!("{}", "async functions return futures")); err.note("while checking the return type of the `async fn`"); returned_async_output_error = true; + } else { + err.span_label( + *sp, + format!( + "{}{}{} {}{}", + if count == 1 { "the " } else { "" }, + if count > 1 { "one of the " } else { "" }, + target, + kind, + pluralize!(count), + ), + ); } } } @@ -1768,7 +1760,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { if let ObligationCauseCode::CompareImplMethodObligation { .. } = &cause.code { return; } - match ( self.get_impl_future_output_ty(exp_found.expected), self.get_impl_future_output_ty(exp_found.found), 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 654a3bcc92dd8..6506035a1ed3b 100644 --- a/src/test/ui/async-await/dont-suggest-missing-await.stderr +++ b/src/test/ui/async-await/dont-suggest-missing-await.stderr @@ -2,7 +2,7 @@ error[E0308]: mismatched types --> $DIR/dont-suggest-missing-await.rs:14:18 | LL | async fn make_u32() -> u32 { - | --- checked the `Output` of this `async fn`, found opaque type + | --- async functions return futures ... LL | take_u32(x) | ^ expected `u32`, found opaque type diff --git a/src/test/ui/async-await/generator-desc.stderr b/src/test/ui/async-await/generator-desc.stderr index 04f191cc5e8cb..68c1dcefbe4b3 100644 --- a/src/test/ui/async-await/generator-desc.stderr +++ b/src/test/ui/async-await/generator-desc.stderr @@ -13,9 +13,9 @@ error[E0308]: mismatched types --> $DIR/generator-desc.rs:12:16 | LL | async fn one() {} - | - checked the `Output` of this `async fn`, expected opaque type + | - async functions return futures LL | async fn two() {} - | - checked the `Output` of this `async fn`, found opaque type + | - async functions return futures ... LL | fun(one(), two()); | ^^^^^ expected opaque type, found a different opaque type diff --git a/src/test/ui/async-await/issue-61076.rs b/src/test/ui/async-await/issue-61076.rs index 9fe3313ee6cc6..a17b77bd9637e 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 checked the `Output` of this `async fn`, expected opaque type + //~^ NOTE async functions return futures Tuple(1i32) } diff --git a/src/test/ui/async-await/issue-61076.stderr b/src/test/ui/async-await/issue-61076.stderr index ad661fb2833fa..6006f97de3791 100644 --- a/src/test/ui/async-await/issue-61076.stderr +++ b/src/test/ui/async-await/issue-61076.stderr @@ -61,7 +61,7 @@ error[E0308]: mismatched types --> $DIR/issue-61076.rs:92:9 | LL | async fn tuple() -> Tuple { - | ----- checked the `Output` of this `async fn`, expected opaque type + | ----- async functions return futures ... LL | Tuple(_) => {} | ^^^^^^^^ expected opaque type, found struct `Tuple` 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 483e52536a1b4..223bc1e038964 100644 --- a/src/test/ui/async-await/suggest-missing-await-closure.stderr +++ b/src/test/ui/async-await/suggest-missing-await-closure.stderr @@ -2,7 +2,7 @@ error[E0308]: mismatched types --> $DIR/suggest-missing-await-closure.rs:16:18 | LL | async fn make_u32() -> u32 { - | --- checked the `Output` of this `async fn`, found opaque type + | --- async functions return futures ... LL | take_u32(x) | ^ expected `u32`, found opaque type diff --git a/src/test/ui/async-await/suggest-missing-await.stderr b/src/test/ui/async-await/suggest-missing-await.stderr index 14b5ee95ee8ba..2c99902d6f214 100644 --- a/src/test/ui/async-await/suggest-missing-await.stderr +++ b/src/test/ui/async-await/suggest-missing-await.stderr @@ -2,7 +2,7 @@ error[E0308]: mismatched types --> $DIR/suggest-missing-await.rs:12:14 | LL | async fn make_u32() -> u32 { - | --- checked the `Output` of this `async fn`, found opaque type + | --- async functions return futures ... LL | take_u32(x) | ^ expected `u32`, found opaque type @@ -19,7 +19,7 @@ error[E0308]: mismatched types --> $DIR/suggest-missing-await.rs:22:5 | LL | async fn dummy() {} - | - checked the `Output` of this `async fn`, found opaque type + | - async functions return futures ... LL | dummy() | ^^^^^^^ expected `()`, found opaque type diff --git a/src/test/ui/parser/fn-header-semantic-fail.stderr b/src/test/ui/parser/fn-header-semantic-fail.stderr index b3f60b13b0f74..a7947585803aa 100644 --- a/src/test/ui/parser/fn-header-semantic-fail.stderr +++ b/src/test/ui/parser/fn-header-semantic-fail.stderr @@ -189,7 +189,7 @@ LL | async fn ft1(); LL | async fn ft1() {} | ^ | | - | checked the `Output` of this `async fn`, found opaque type + | async functions return futures | expected `()`, found opaque type | = note: while checking the return type of the `async fn` @@ -205,7 +205,7 @@ LL | const async unsafe extern "C" fn ft5(); LL | const async unsafe extern "C" fn ft5() {} | ^ | | - | checked the `Output` of this `async fn`, found opaque type + | async functions return futures | expected `()`, found opaque type | = note: while checking the return type of the `async fn` 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 4025b5030dc0f..5c26fa8417059 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,7 +53,7 @@ LL | async fn associated(); LL | async fn associated(); | ^ | | - | checked the `Output` of this `async fn`, found opaque type + | async functions return futures | expected `()`, found opaque type | = note: while checking the return type of the `async fn` diff --git a/src/test/ui/suggestions/issue-81839.stderr b/src/test/ui/suggestions/issue-81839.stderr index f907658708730..994a222d9f6d3 100644 --- a/src/test/ui/suggestions/issue-81839.stderr +++ b/src/test/ui/suggestions/issue-81839.stderr @@ -17,7 +17,7 @@ LL | | } ::: $DIR/auxiliary/issue-81839.rs:6:49 | LL | pub async fn answer_str(&self, _s: &str) -> Test { - | ---- checked the `Output` of this `async fn`, found opaque type + | ---- async functions return futures | = note: while checking the return type of the `async fn` = note: expected type `()` 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 3b2cff3140d63..a91e77e3f42d9 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 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_dummy() {} //~ NOTE async functions return futures +async fn async_dummy2() {} //~ NOTE async functions return futures +//~| NOTE async functions return futures async fn async_extra_semicolon_same() { let _ = match true { //~ NOTE `match` arms have incompatible types 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 e31ea9679b51d..037a7bc23c436 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() {} - | - checked the `Output` of this `async fn`, found opaque type + | - async functions return futures ... LL | let _ = match true { | _____________- @@ -34,7 +34,7 @@ error[E0308]: `match` arms have incompatible types --> $DIR/match-prev-arm-needing-semi.rs:40:18 | LL | async fn async_dummy2() {} - | - checked the `Output` of this `async fn`, found opaque type + | - async functions return futures ... LL | let _ = match true { | _____________- @@ -69,7 +69,7 @@ error[E0308]: `match` arms have incompatible types --> $DIR/match-prev-arm-needing-semi.rs:52:18 | LL | async fn async_dummy2() {} - | - checked the `Output` of this `async fn`, found opaque type + | - async functions return futures ... LL | let _ = match true { | _____________-