Skip to content

Commit a56bbb1

Browse files
Rollup merge of #82165 - nellshamrell:nell/fix-80658-B, r=estebank
Reword labels on E0308 involving async fn return type Fix for #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 0db8349 + 356beb3 commit a56bbb1

12 files changed

+49
-22
lines changed

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

+11-2
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

+2-1
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

+4-2
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

+2-1
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

+2-1
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

+2-1
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

+4-2
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

+4-2
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

+2-1
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

+2-1
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

src/test/ui/suggestions/match-prev-arm-needing-semi.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ fn extra_semicolon() {
1313
};
1414
}
1515

16-
async fn async_dummy() {} //~ NOTE the `Output` of this `async fn`'s found opaque type
17-
async fn async_dummy2() {} //~ NOTE the `Output` of this `async fn`'s found opaque type
18-
//~^ NOTE the `Output` of this `async fn`'s found opaque type
16+
async fn async_dummy() {} //~ NOTE checked the `Output` of this `async fn`, found opaque type
17+
async fn async_dummy2() {} //~ NOTE checked the `Output` of this `async fn`, found opaque type
18+
//~| NOTE checked the `Output` of this `async fn`, found opaque type
1919

2020
async fn async_extra_semicolon_same() {
2121
let _ = match true { //~ NOTE `match` arms have incompatible types
@@ -26,6 +26,7 @@ async fn async_extra_semicolon_same() {
2626
false => async_dummy(), //~ ERROR `match` arms have incompatible types
2727
//~^ NOTE expected `()`, found opaque type
2828
//~| NOTE expected type `()`
29+
//~| NOTE while checking the return type of the `async fn`
2930
//~| HELP consider `await`ing on the `Future`
3031
};
3132
}
@@ -39,6 +40,7 @@ async fn async_extra_semicolon_different() {
3940
false => async_dummy2(), //~ ERROR `match` arms have incompatible types
4041
//~^ NOTE expected `()`, found opaque type
4142
//~| NOTE expected type `()`
43+
//~| NOTE while checking the return type of the `async fn`
4244
//~| HELP consider `await`ing on the `Future`
4345
};
4446
}
@@ -51,6 +53,7 @@ async fn async_different_futures() {
5153
//~^ NOTE expected opaque type, found a different opaque type
5254
//~| NOTE expected type `impl Future`
5355
//~| NOTE distinct uses of `impl Trait` result in different opaque types
56+
//~| NOTE while checking the return type of the `async fn`
5457
};
5558
}
5659

src/test/ui/suggestions/match-prev-arm-needing-semi.stderr

+8-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0308]: `match` arms have incompatible types
22
--> $DIR/match-prev-arm-needing-semi.rs:26:18
33
|
44
LL | async fn async_dummy() {}
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 | let _ = match true {
88
| _____________-
@@ -18,6 +18,7 @@ LL | |
1818
LL | | };
1919
| |_____- `match` arms have incompatible types
2020
|
21+
= note: while checking the return type of the `async fn`
2122
= note: expected type `()`
2223
found opaque type `impl Future`
2324
help: consider `await`ing on the `Future`
@@ -30,10 +31,10 @@ LL | async_dummy()
3031
| --
3132

3233
error[E0308]: `match` arms have incompatible types
33-
--> $DIR/match-prev-arm-needing-semi.rs:39:18
34+
--> $DIR/match-prev-arm-needing-semi.rs:40:18
3435
|
3536
LL | async fn async_dummy2() {}
36-
| - the `Output` of this `async fn`'s found opaque type
37+
| - checked the `Output` of this `async fn`, found opaque type
3738
...
3839
LL | let _ = match true {
3940
| _____________-
@@ -49,6 +50,7 @@ LL | |
4950
LL | | };
5051
| |_____- `match` arms have incompatible types
5152
|
53+
= note: while checking the return type of the `async fn`
5254
= note: expected type `()`
5355
found opaque type `impl Future`
5456
help: consider `await`ing on the `Future`
@@ -64,10 +66,10 @@ LL | false => Box::new(async_dummy2()),
6466
|
6567

6668
error[E0308]: `match` arms have incompatible types
67-
--> $DIR/match-prev-arm-needing-semi.rs:50:18
69+
--> $DIR/match-prev-arm-needing-semi.rs:52:18
6870
|
6971
LL | async fn async_dummy2() {}
70-
| - the `Output` of this `async fn`'s found opaque type
72+
| - checked the `Output` of this `async fn`, found opaque type
7173
...
7274
LL | let _ = match true {
7375
| _____________-
@@ -81,6 +83,7 @@ LL | |
8183
LL | | };
8284
| |_____- `match` arms have incompatible types
8385
|
86+
= note: while checking the return type of the `async fn`
8487
= note: expected type `impl Future` (opaque type at <$DIR/match-prev-arm-needing-semi.rs:16:24>)
8588
found opaque type `impl Future` (opaque type at <$DIR/match-prev-arm-needing-semi.rs:17:25>)
8689
= note: distinct uses of `impl Trait` result in different opaque types

0 commit comments

Comments
 (0)