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

Add suggestion for missing .await keyword #62067

Merged
merged 1 commit into from
Jun 28, 2019
Merged

Add suggestion for missing .await keyword #62067

merged 1 commit into from
Jun 28, 2019

Conversation

doctorn
Copy link
Contributor

@doctorn doctorn commented Jun 22, 2019

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)]

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 #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
Collaborator

r? @matthewjasper

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 22, 2019
@doctorn
Copy link
Contributor Author

doctorn commented Jun 24, 2019

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

Copy link
Member

@davidtwco davidtwco left a comment

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!

src/test/ui/async-await/suggest-missing-await.rs Outdated Show resolved Hide resolved
src/librustc_typeck/check/mod.rs Show resolved Hide resolved
@doctorn
Copy link
Contributor Author

doctorn commented Jun 24, 2019

@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
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Jun 26, 2019

📌 Commit 86ffeef has been approved by matthewjasper

@bors
Copy link
Contributor

bors commented Jun 26, 2019

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

@bors bors 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.
@Centril
Copy link
Contributor

Centril commented Jun 27, 2019

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

@bors bors 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
@doctorn
Copy link
Contributor Author

doctorn commented Jun 27, 2019

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
Contributor

Centril commented Jun 27, 2019

@bors r=matthewjasper

@bors
Copy link
Contributor

bors commented Jun 27, 2019

📌 Commit 8819420 has been approved by matthewjasper

@bors bors 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.
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.
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:master Jun 28, 2019
@doctorn doctorn deleted the await_diagnostic branch June 28, 2019 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: 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