-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Conversation
r? @estebank (rust-highfive has picked a reviewer for you, use r? to override) |
I think I noticed this weird wording on #81496 and I think this will fix it! Nice! |
@@ -1502,6 +1502,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { | |||
pluralize!(count), | |||
), | |||
); | |||
if sp.is_desugaring(DesugaringKind::Async) { | |||
err.note("while checking the return type of this `async fn`"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how cumbersome it might be to procure, but if we had the Span
for make_u32
we could have the following output:
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
| |
| while checking the return type of this `async fn`
...
LL | take_u32(x)
| ^ expected `u32`, found opaque type
|
= note: expected type `u32`
found opaque type `impl Future`
help: consider `await`ing on the `Future`
|
LL | take_u32(x.await)
| ^^^^^^
If getting it is too difficult, then we should reword the note
to be "while checking the return type of the async fn
", because the note has no span and the output on both the CLI and third-party tools might be ambiguous.
After doing either of the options, could you squash your commits? With those nitpicks addressed, this can be landed :) |
This comment has been minimized.
This comment has been minimized.
if sp.is_desugaring(DesugaringKind::Async) { | ||
err.note("while checking the return type of the `async fn`"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you'll have to keep a local that checks if you have noted this in this loop already
In the rebase on my pr, this message shows up twice in 1 diagnostic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will experiment with this (likely tomorrow), but is there any chance you could point me to a place in the code base where it does a similar local check in the loop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Experimented and I think I've got what you suggested working. Would you mind trying it out when you have a moment?
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
It seems like you'll have to |
…tions Signed-off-by: Nell Shamrell <[email protected]>
@estebank I think this is ready to go now! |
@bors r+ |
📌 Commit 356beb3 has been approved by |
…tebank 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` ```
…tebank 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` ```
…laumeGomez Rollup of 8 pull requests Successful merges: - rust-lang#81940 (Stabilize str_split_once) - rust-lang#82165 (Reword labels on E0308 involving async fn return type) - rust-lang#82456 (Replaced some unwrap_or and map_or with lazy variants) - rust-lang#82491 (Consider inexpensive inlining criteria first) - rust-lang#82506 (Properly account for non-shorthand pattern field in unused variable lint) - rust-lang#82535 (Set codegen thread names) - rust-lang#82545 (rustdoc: add optional woff2 versions of FiraSans.) - rust-lang#82549 (Revert "Update normalize.css to 8.0.1") Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Fix for #80658.
When someone writes code like this:
And they try to compile it, they will see an error that looks like this: