Skip to content

Reword labels on E0308 involving async fn return type - #82165

Merged
bors merged 1 commit into
rust-lang:masterfrom
nellshamrell:nell/fix-80658-B
Feb 26, 2021
Merged

Reword labels on E0308 involving async fn return type#82165
bors merged 1 commit into
rust-lang:masterfrom
nellshamrell:nell/fix-80658-B

Conversation

@nellshamrell

Copy link
Copy Markdown
Contributor

Fix for #80658.

When someone writes code like this:

fnfoo() -> u8{asyncfnasync_fn() -> (){}async_fn()}

And they try to compile it, they will see an error that looks like this:

error[E0308]: mismatched types
--> test.rs:4:5
|
1 | fn foo() -> u8 {
| -- expected `u8` because of returntype
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 returntype of this `async fn`
= note: expected type`u8`
found opaque type`impl Future`

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @estebank

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 16, 2021
@guswynn

Copy link
Copy Markdown
Contributor

I think I noticed this weird wording on #81496 and I think this will fix it! Nice!

@estebankestebank changed the title Nell/fix 80658 bReword labels on E0308 involving async fn return typeFeb 16, 2021

Copy link
Copy Markdown
Contributor

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.

@estebank

Copy link
Copy Markdown
Contributor

After doing either of the options, could you squash your commits? With those nitpicks addressed, this can be landed :)

@rust-log-analyzer

This comment has been minimized.

Comment on lines 1505 to 1511

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Will do!

Copy link
Copy Markdown
ContributorAuthor

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?

Copy link
Copy Markdown
ContributorAuthor

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?

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

Comment threadcompiler/rustc_infer/src/infer/error_reporting/mod.rs Outdated
Comment threadcompiler/rustc_infer/src/infer/error_reporting/mod.rs Outdated
@rust-log-analyzer

This comment has been minimized.

@estebank

Copy link
Copy Markdown
Contributor

It seems like you'll have to ./x.py fmt after fetching the changes from github, sadly. After that r=me.

…tions
Signed-off-by: Nell Shamrell <nellshamrell@gmail.com>
@nellshamrell

Copy link
Copy Markdown
ContributorAuthor

@estebank I think this is ready to go now!

@estebank

Copy link
Copy Markdown
Contributor

@bors r+

@bors

bors commented Feb 25, 2021

Copy link
Copy Markdown
Collaborator

📌 Commit 356beb3 has been approved by estebank

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 25, 2021
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Feb 26, 2021
…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`
```
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Feb 26, 2021
…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`
```
This was referenced Feb 26, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 26, 2021
…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
@bors
bors merged commit a56bbb1 into rust-lang:masterFeb 26, 2021
@rustbotrustbot added this to the 1.52.0 milestone Feb 26, 2021
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@nellshamrell@rust-highfive@guswynn@estebank@rust-log-analyzer@bors@rustbot