Skip to content

Add suggestion for missing .await keyword - #62067

Merged
bors merged 1 commit into
rust-lang:masterfrom
cofibrant:await_diagnostic
Jun 28, 2019
Merged

Add suggestion for missing .await keyword#62067
bors merged 1 commit into
rust-lang:masterfrom
cofibrant:await_diagnostic

Conversation

@cofibrant

@cofibrantcofibrant commented Jun 22, 2019

Copy link
Copy Markdown
Contributor

This commit adds a suggestion diagnostic for missing .await. In order to do this, the trait Future is promoted to a lang item.

Compiling code of the form:

#![feature(async_await)]fntake_u32(x:u32){}asyncfnmake_u32() -> u32{22}asyncfnfoo(){let x = make_u32();take_u32(x)}fnmain(){}

Will now result in the suggestion:

error[E0308]: mismatched types
--> src/main.rs:11:18
|
11 | take_u32(x)
| ^
| |
| expected u32, found opaque type
| help: consider using `.await` here: `x.await`
|
= note: expected type `u32`
found type `impl std::future::Future`

This commit does not cover chained expressions and therefore only covers the case originally pointed out in #61076. Cases I can think of that still need to be covered:

  • Return places for functions
  • Field access
  • Method invocation

I'm planning to submit PRs for each of these separately as and when I have figured them out.

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @matthewjasper

(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 Jun 22, 2019
Comment threadsrc/librustc_typeck/check/mod.rs Outdated
Comment threadsrc/test/ui/async-await/suggest-missing-await.rs Outdated
@cofibrant

Copy link
Copy Markdown
ContributorAuthor

@matthewjasper Thank you very much for the comments! I hope this covers everything you suggested.

@davidtwcodavidtwco left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I've left a couple nit-picky reviews that you can feel free to resolve if you have the time, this looks great though!

Comment threadsrc/test/ui/async-await/suggest-missing-await.rs Outdated
Comment threadsrc/test/ui/async-await/suggest-missing-await.rs Outdated
Comment threadsrc/librustc_typeck/check/mod.rs Outdated
@cofibrant

Copy link
Copy Markdown
ContributorAuthor

@davidtwco Thank you for the review! I've tried my best to follow your guidance. I've rebased, but haven't made any semantic changes.

@matthewjasper

Copy link
Copy Markdown
Contributor

@bors r+

@bors

bors commented Jun 26, 2019

Copy link
Copy Markdown
Collaborator

📌 Commit 86ffeef has been approved by matthewjasper

@bors

bors commented Jun 26, 2019

Copy link
Copy Markdown
Collaborator

🌲 The tree is currently closed for pull requests below priority 999, this pull request will be tested once the tree is reopened

@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 Jun 26, 2019
Centril added a commit to Centril/rust that referenced this pull request Jun 27, 2019
…jasper
Add suggestion for missing `.await` keyword
This commit adds a suggestion diagnostic for missing `.await`. In order to do this, the trait `Future` is promoted to a lang item.
Compiling code of the form:
```rust
#![feature(async_await)]
fn take_u32(x: u32) {}
async fn make_u32() -> u32 {
22
}
async fn foo() {
let x = make_u32();
take_u32(x)
}
fn main() {}
```
Will now result in the suggestion:
```
error[E0308]: mismatched types
--> src/main.rs:11:18
|
11 | take_u32(x)
| ^
| |
| expected u32, found opaque type
| help: consider using `.await` here: `x.await`
|
= note: expected type `u32`
found type `impl std::future::Future`
```
This commit does not cover chained expressions and therefore only covers the case originally pointed out in rust-lang#61076. Cases I can think of that still need to be covered:
- [ ] Return places for functions
- [ ] Field access
- [ ] Method invocation
I'm planning to submit PRs for each of these separately as and when I have figured them out.
@CentrilCentril mentioned this pull request Jun 27, 2019
@Centril

Copy link
Copy Markdown
Contributor

Failed in #62178 (comment), @bors r-

@borsbors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jun 27, 2019
@cofibrant

cofibrant commented Jun 27, 2019

Copy link
Copy Markdown
ContributorAuthor

I hadn't realised that the API for HIR had changed, this should hopefully be alright to merge now (the only change in that rebase is to change get_parent_node_by_id to get_parent_node)

@Centril

Copy link
Copy Markdown
Contributor

@bors r=matthewjasper

@bors

bors commented Jun 27, 2019

Copy link
Copy Markdown
Collaborator

📌 Commit 8819420 has been approved by matthewjasper

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 27, 2019
Centril added a commit to Centril/rust that referenced this pull request Jun 27, 2019
…jasper
Add suggestion for missing `.await` keyword
This commit adds a suggestion diagnostic for missing `.await`. In order to do this, the trait `Future` is promoted to a lang item.
Compiling code of the form:
```rust
#![feature(async_await)]
fn take_u32(x: u32) {}
async fn make_u32() -> u32 {
22
}
async fn foo() {
let x = make_u32();
take_u32(x)
}
fn main() {}
```
Will now result in the suggestion:
```
error[E0308]: mismatched types
--> src/main.rs:11:18
|
11 | take_u32(x)
| ^
| |
| expected u32, found opaque type
| help: consider using `.await` here: `x.await`
|
= note: expected type `u32`
found type `impl std::future::Future`
```
This commit does not cover chained expressions and therefore only covers the case originally pointed out in rust-lang#61076. Cases I can think of that still need to be covered:
- [ ] Return places for functions
- [ ] Field access
- [ ] Method invocation
I'm planning to submit PRs for each of these separately as and when I have figured them out.
@CentrilCentril mentioned this pull request Jun 27, 2019
Centril added a commit to Centril/rust that referenced this pull request Jun 27, 2019
…jasper
Add suggestion for missing `.await` keyword
This commit adds a suggestion diagnostic for missing `.await`. In order to do this, the trait `Future` is promoted to a lang item.
Compiling code of the form:
```rust
#![feature(async_await)]
fn take_u32(x: u32) {}
async fn make_u32() -> u32 {
22
}
async fn foo() {
let x = make_u32();
take_u32(x)
}
fn main() {}
```
Will now result in the suggestion:
```
error[E0308]: mismatched types
--> src/main.rs:11:18
|
11 | take_u32(x)
| ^
| |
| expected u32, found opaque type
| help: consider using `.await` here: `x.await`
|
= note: expected type `u32`
found type `impl std::future::Future`
```
This commit does not cover chained expressions and therefore only covers the case originally pointed out in rust-lang#61076. Cases I can think of that still need to be covered:
- [ ] Return places for functions
- [ ] Field access
- [ ] Method invocation
I'm planning to submit PRs for each of these separately as and when I have figured them out.
@CentrilCentril mentioned this pull request Jun 27, 2019
bors added a commit that referenced this pull request Jun 28, 2019
Rollup of 16 pull requests
Successful merges:
- #61878 (improve pinning projection docs)
- #62043 (Remove `FnBox`)
- #62067 (Add suggestion for missing `.await` keyword)
- #62076 (Updated RELEASES.md for 1.36.0)
- #62102 (call out explicitly that general read needs to be called with an initialized buffer)
- #62106 (Add more tests for async/await)
- #62124 (refactor lexer to use idiomatic borrowing)
- #62131 (libsyntax: Fix some Clippy warnings)
- #62152 (Don't ICE on item in `.await` expression)
- #62154 (Remove old fixme)
- #62155 (Add regression test for MIR drop generation in async loops)
- #62156 (Update books)
- #62160 (Remove outdated question_mark_macro_sep lint)
- #62164 (save-analysis: use buffered writes)
- #62171 (rustc: Retry SIGILL linker invocations)
- #62176 (Update RLS)
Failed merges:
r? @ghost
@bors
bors merged commit 8819420 into rust-lang:masterJun 28, 2019
@cofibrant
cofibrant deleted the await_diagnostic branch June 28, 2019 17:41
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.

6 participants

@cofibrant@rust-highfive@matthewjasper@bors@Centril@davidtwco