Skip to content

Commit aad8917

Browse files
authored
Rollup merge of rust-lang#82165 - nellshamrell:nell/fix-80658-B, r=estebank
Reword labels on E0308 involving async fn return type Fix for rust-lang#80658. When someone writes code like this: ```rust fn foo() -> u8 { async fn async_fn() -> () {} async_fn() } ``` And they try to compile it, they will see an error that looks like this: ```bash error[E0308]: mismatched types --> test.rs:4:5 | 1 | fn foo() -> u8 { | -- expected `u8` because of return type 2 | async fn async_fn() -> () {} | -- checked the `Output` of this `async fn`, found opaque type 3 | 4 | async_fn() | ^^^^^^^^^^ expected `u8`, found opaque type | = note: while checking the return type of this `async fn` = note: expected type `u8` found opaque type `impl Future` ```
2 parents 86fb983 + 356beb3 commit aad8917

12 files changed

+49
-22
lines changed

compiler/rustc_infer/src/infer/error_reporting/mod.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,13 +1484,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
14841484
for (key, values) in types.iter() {
14851485
let count = values.len();
14861486
let kind = key.descr();
1487+
let mut returned_async_output_error = false;
14871488
for sp in values {
14881489
err.span_label(
14891490
*sp,
14901491
format!(
14911492
"{}{}{} {}{}",
1492-
if sp.is_desugaring(DesugaringKind::Async) {
1493-
"the `Output` of this `async fn`'s "
1493+
if sp.is_desugaring(DesugaringKind::Async)
1494+
&& !returned_async_output_error
1495+
{
1496+
"checked the `Output` of this `async fn`, "
14941497
} else if count == 1 {
14951498
"the "
14961499
} else {
@@ -1502,6 +1505,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
15021505
pluralize!(count),
15031506
),
15041507
);
1508+
if sp.is_desugaring(DesugaringKind::Async)
1509+
&& returned_async_output_error == false
1510+
{
1511+
err.note("while checking the return type of the `async fn`");
1512+
returned_async_output_error = true;
1513+
}
15051514
}
15061515
}
15071516
}

src/test/ui/async-await/dont-suggest-missing-await.stderr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ error[E0308]: mismatched types
22
--> $DIR/dont-suggest-missing-await.rs:14:18
33
|
44
LL | async fn make_u32() -> u32 {
5-
| --- the `Output` of this `async fn`'s found opaque type
5+
| --- checked the `Output` of this `async fn`, found opaque type
66
...
77
LL | take_u32(x)
88
| ^ expected `u32`, found opaque type
99
|
10+
= note: while checking the return type of the `async fn`
1011
= note: expected type `u32`
1112
found opaque type `impl Future`
1213
help: consider `await`ing on the `Future`

src/test/ui/async-await/generator-desc.stderr

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ error[E0308]: mismatched types
1313
--> $DIR/generator-desc.rs:12:16
1414
|
1515
LL | async fn one() {}
16-
| - the `Output` of this `async fn`'s expected opaque type
16+
| - checked the `Output` of this `async fn`, expected opaque type
1717
LL | async fn two() {}
18-
| - the `Output` of this `async fn`'s found opaque type
18+
| - checked the `Output` of this `async fn`, found opaque type
1919
...
2020
LL | fun(one(), two());
2121
| ^^^^^ expected opaque type, found a different opaque type
2222
|
23+
= note: while checking the return type of the `async fn`
24+
= note: while checking the return type of the `async fn`
2325
= note: expected opaque type `impl Future` (opaque type at <$DIR/generator-desc.rs:5:16>)
2426
found opaque type `impl Future` (opaque type at <$DIR/generator-desc.rs:6:16>)
2527
= help: consider `await`ing on both `Future`s

src/test/ui/async-await/issue-61076.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ async fn struct_() -> Struct {
5656
}
5757

5858
async fn tuple() -> Tuple {
59-
//~^ NOTE the `Output` of this `async fn`'s expected opaque type
59+
//~^ NOTE checked the `Output` of this `async fn`, expected opaque type
6060
Tuple(1i32)
6161
}
6262

@@ -92,6 +92,7 @@ async fn match_() {
9292
Tuple(_) => {} //~ ERROR mismatched types
9393
//~^ NOTE expected opaque type, found struct `Tuple`
9494
//~| NOTE expected opaque type `impl Future`
95+
//~| NOTE while checking the return type of the `async fn`
9596
}
9697
}
9798

src/test/ui/async-await/issue-61076.stderr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,12 @@ error[E0308]: mismatched types
6161
--> $DIR/issue-61076.rs:92:9
6262
|
6363
LL | async fn tuple() -> Tuple {
64-
| ----- the `Output` of this `async fn`'s expected opaque type
64+
| ----- checked the `Output` of this `async fn`, expected opaque type
6565
...
6666
LL | Tuple(_) => {}
6767
| ^^^^^^^^ expected opaque type, found struct `Tuple`
6868
|
69+
= note: while checking the return type of the `async fn`
6970
= note: expected opaque type `impl Future`
7071
found struct `Tuple`
7172
help: consider `await`ing on the `Future`

src/test/ui/async-await/suggest-missing-await-closure.stderr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ error[E0308]: mismatched types
22
--> $DIR/suggest-missing-await-closure.rs:16:18
33
|
44
LL | async fn make_u32() -> u32 {
5-
| --- the `Output` of this `async fn`'s found opaque type
5+
| --- checked the `Output` of this `async fn`, found opaque type
66
...
77
LL | take_u32(x)
88
| ^ expected `u32`, found opaque type
99
|
10+
= note: while checking the return type of the `async fn`
1011
= note: expected type `u32`
1112
found opaque type `impl Future`
1213
help: consider `await`ing on the `Future`

src/test/ui/async-await/suggest-missing-await.stderr

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ error[E0308]: mismatched types
22
--> $DIR/suggest-missing-await.rs:12:14
33
|
44
LL | async fn make_u32() -> u32 {
5-
| --- the `Output` of this `async fn`'s found opaque type
5+
| --- checked the `Output` of this `async fn`, found opaque type
66
...
77
LL | take_u32(x)
88
| ^ expected `u32`, found opaque type
99
|
10+
= note: while checking the return type of the `async fn`
1011
= note: expected type `u32`
1112
found opaque type `impl Future`
1213
help: consider `await`ing on the `Future`
@@ -18,11 +19,12 @@ error[E0308]: mismatched types
1819
--> $DIR/suggest-missing-await.rs:22:5
1920
|
2021
LL | async fn dummy() {}
21-
| - the `Output` of this `async fn`'s found opaque type
22+
| - checked the `Output` of this `async fn`, found opaque type
2223
...
2324
LL | dummy()
2425
| ^^^^^^^ expected `()`, found opaque type
2526
|
27+
= note: while checking the return type of the `async fn`
2628
= note: expected unit type `()`
2729
found opaque type `impl Future`
2830
help: consider `await`ing on the `Future`

src/test/ui/parser/fn-header-semantic-fail.stderr

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,10 @@ LL | async fn ft1();
189189
LL | async fn ft1() {}
190190
| ^
191191
| |
192-
| the `Output` of this `async fn`'s found opaque type
192+
| checked the `Output` of this `async fn`, found opaque type
193193
| expected `()`, found opaque type
194194
|
195+
= note: while checking the return type of the `async fn`
195196
= note: expected fn pointer `fn()`
196197
found fn pointer `fn() -> impl Future`
197198

@@ -204,9 +205,10 @@ LL | const async unsafe extern "C" fn ft5();
204205
LL | const async unsafe extern "C" fn ft5() {}
205206
| ^
206207
| |
207-
| the `Output` of this `async fn`'s found opaque type
208+
| checked the `Output` of this `async fn`, found opaque type
208209
| expected `()`, found opaque type
209210
|
211+
= note: while checking the return type of the `async fn`
210212
= note: expected fn pointer `unsafe extern "C" fn()`
211213
found fn pointer `unsafe extern "C" fn() -> impl Future`
212214

src/test/ui/resolve/issue-70736-async-fn-no-body-def-collector.stderr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ LL | async fn associated();
5353
LL | async fn associated();
5454
| ^
5555
| |
56-
| the `Output` of this `async fn`'s found opaque type
56+
| checked the `Output` of this `async fn`, found opaque type
5757
| expected `()`, found opaque type
5858
|
59+
= note: while checking the return type of the `async fn`
5960
= note: expected fn pointer `fn()`
6061
found fn pointer `fn() -> impl Future`
6162

src/test/ui/suggestions/issue-81839.stderr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ LL | | }
1717
::: $DIR/auxiliary/issue-81839.rs:6:49
1818
|
1919
LL | pub async fn answer_str(&self, _s: &str) -> Test {
20-
| ---- the `Output` of this `async fn`'s found opaque type
20+
| ---- checked the `Output` of this `async fn`, found opaque type
2121
|
22+
= note: while checking the return type of the `async fn`
2223
= note: expected type `()`
2324
found opaque type `impl Future`
2425

0 commit comments

Comments
 (0)