about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-06-27 23:01:01 +0200
committerGitHub <noreply@github.com>2019-06-27 23:01:01 +0200
commitdf97fc6038c648ce7396d3f4dde6f6d783aec1ba (patch)
tree7a86dc790708086050272878dcfed6efa7741f4e /src/libcore
parent2f6cf36b326d5045872785782cdd0c121a3198ec (diff)
parent88194200e57c90ba0fa7b725d63ff4de28e71bbb (diff)
downloadrust-df97fc6038c648ce7396d3f4dde6f6d783aec1ba.tar.gz
rust-df97fc6038c648ce7396d3f4dde6f6d783aec1ba.zip
Rollup merge of #62067 - doctorn:await_diagnostic, r=matthewjasper
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 #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.
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/future/future.rs1
1 files changed, 1 insertions, 0 deletions
diff --git a/src/libcore/future/future.rs b/src/libcore/future/future.rs
index 0492fd709b8..acca8d7ba15 100644
--- a/src/libcore/future/future.rs
+++ b/src/libcore/future/future.rs
@@ -25,6 +25,7 @@ use crate::task::{Context, Poll};
 #[doc(spotlight)]
 #[must_use = "futures do nothing unless you `.await` or poll them"]
 #[stable(feature = "futures_api", since = "1.36.0")]
+#[cfg_attr(not(bootstrap), lang = "future_trait")]
 pub trait Future {
     /// The type of value produced on completion.
     #[stable(feature = "futures_api", since = "1.36.0")]