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

Nellshamrell/improve async error #86705

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
38 changes: 18 additions & 20 deletions compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1486,25 +1486,24 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
let kind = key.descr();
let mut returned_async_output_error = false;
for sp in values {
nellshamrell marked this conversation as resolved.
Show resolved Hide resolved
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 {
err.span_label(
*sp,
format!("{}", "calling an async function returns a future"),
nellshamrell marked this conversation as resolved.
Show resolved Hide resolved
);
} else {
err.span_label(
*sp,
format!(
"{}{}{} {}{}",
if count == 1 { "the " } else { "" },
if count > 1 { "one of the " } else { "" },
target,
kind,
pluralize!(count),
),
);
}
if sp.is_desugaring(DesugaringKind::Async)
nellshamrell marked this conversation as resolved.
Show resolved Hide resolved
&& returned_async_output_error == false
{
Expand Down Expand Up @@ -1768,7 +1767,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),
Expand Down
2 changes: 1 addition & 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,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
| --- calling an async function returns a future
...
LL | take_u32(x)
| ^ expected `u32`, found opaque type
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/async-await/generator-desc.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
| - calling an async function returns a future
LL | async fn two() {}
| - checked the `Output` of this `async fn`, found opaque type
| - calling an async function returns a future
...
LL | fun(one(), two());
| ^^^^^ expected opaque type, found a different opaque type
Expand Down
2 changes: 1 addition & 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 checked the `Output` of this `async fn`, expected opaque type
//~^ NOTE calling an async function returns a future
Tuple(1i32)
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/async-await/issue-61076.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
| ----- calling an async function returns a future
...
LL | Tuple(_) => {}
| ^^^^^^^^ expected opaque type, found struct `Tuple`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
| --- calling an async function returns a future
...
LL | take_u32(x)
| ^ expected `u32`, found opaque type
Expand Down
4 changes: 2 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,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
| --- calling an async function returns a future
...
LL | take_u32(x)
| ^ expected `u32`, found opaque type
Expand All @@ -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
| - calling an async function returns a future
...
LL | dummy()
| ^^^^^^^ expected `()`, found opaque type
Expand Down
4 changes: 2 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,7 +189,7 @@ LL | async fn ft1();
LL | async fn ft1() {}
| ^
| |
| checked the `Output` of this `async fn`, found opaque type
| calling an async function returns a future
| expected `()`, found opaque type
|
= note: while checking the return type of the `async fn`
Expand All @@ -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
| calling an async function returns a future
| expected `()`, found opaque type
|
= note: while checking the return type of the `async fn`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ LL | async fn associated();
LL | async fn associated();
| ^
| |
| checked the `Output` of this `async fn`, found opaque type
| calling an async function returns a future
| expected `()`, found opaque type
|
= note: while checking the return type of the `async fn`
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/suggestions/issue-81839.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
| ---- calling an async function returns a future
Copy link
Member

@Aaron1011 Aaron1011 Jun 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like the diagnostic is saying that Test is a future. Could we instead say something like 'an async function returns a future that outputs the written return type'?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could highlight the entire function signature and say something like:

this async function will return an `impl Future<Output = Test>`

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To better support macros, I think we should keep pointing to the return type, but mention the function name in the error message. This will produce a nicer message when the return type tokens are constructed separately (e.g. a type passed into a macro_rules! macro).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the suggestion - any pointers on how to surface the function name in the error message?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't look conveniently accessible at the moment. Maybe @estebank has a suggestion on the cleanest way to get the name of the desugared async function?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In https://github.com/rust-lang/rust/pull/86705/files#diff-845d26194de711d60e1317dbe90812d5d7635f4f758222fd7e14bf550ffe895dL1522 we have the DefId of the opaque type. With it I think you can get the def id of the parent fn, and call def_path on that, but I don't have the codebase at hand now to be more specific. I can help you nell either tomorrow or on thursday.

|
= note: while checking the return type of the `async fn`
= note: expected type `()`
Expand Down
6 changes: 3 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 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 calling an async function returns a future
async fn async_dummy2() {} //~ NOTE calling an async function returns a future
//~| NOTE calling an async function returns a future

async fn async_extra_semicolon_same() {
let _ = match true { //~ NOTE `match` arms have incompatible types
Expand Down
6 changes: 3 additions & 3 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() {}
| - checked the `Output` of this `async fn`, found opaque type
| - calling an async function returns a future
...
LL | let _ = match true {
| _____________-
Expand Down Expand Up @@ -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
| - calling an async function returns a future
...
LL | let _ = match true {
| _____________-
Expand Down Expand Up @@ -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
| - calling an async function returns a future
...
LL | let _ = match true {
| _____________-
Expand Down