Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reword labels on E0308 involving async fn return type #82165

Merged
merged 1 commit into from
Feb 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`, "
estebank marked this conversation as resolved.
Show resolved Hide resolved
} else if count == 1 {
"the "
} else {
Expand All @@ -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;
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/test/ui/async-await/dont-suggest-missing-await.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
6 changes: 4 additions & 2 deletions src/test/ui/async-await/generator-desc.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/test/ui/async-await/issue-61076.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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`
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/test/ui/async-await/issue-61076.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
3 changes: 2 additions & 1 deletion src/test/ui/async-await/suggest-missing-await-closure.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
6 changes: 4 additions & 2 deletions src/test/ui/async-await/suggest-missing-await.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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`
Expand Down
6 changes: 4 additions & 2 deletions src/test/ui/parser/fn-header-semantic-fail.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand All @@ -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`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
3 changes: 2 additions & 1 deletion src/test/ui/suggestions/issue-81839.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
9 changes: 6 additions & 3 deletions src/test/ui/suggestions/match-prev-arm-needing-semi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`
};
}
Expand All @@ -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`
};
}
Expand All @@ -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`
};
}

Expand Down
13 changes: 8 additions & 5 deletions src/test/ui/suggestions/match-prev-arm-needing-semi.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
| _____________-
Expand All @@ -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`
Expand All @@ -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 {
| _____________-
Expand All @@ -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`
Expand All @@ -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 {
| _____________-
Expand All @@ -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
Expand Down