about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-08-27 07:26:32 +0000
committerbors <bors@rust-lang.org>2020-08-27 07:26:32 +0000
commitf7cbb7a594658099ebb9d0008779511fe2fbe9ab (patch)
treecec33661a7609e6d6e2d44428918a36dfa4f7b91 /src/test
parent4e701afd84e4500bb7a4800f187284c1e1bf01ee (diff)
parent7cfcefd1fbbbfefbdc88feb7359e6364d7c0bf8a (diff)
Auto merge of #72784 - csmoe:issue-61076, r=estebank
Await on mismatched future types

Closes #61076
This PR suggests to `await` on:
1. `async_fn().bar() => async_fn().await.bar()`
2. `async_fn().field => async_fn().await.field`
3. ` if let x = async() {} => if let x = async().await {}`

r? @tmandry @estebank
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/async-await/issue-61076.rs41
-rw-r--r--src/test/ui/async-await/issue-61076.stderr58
2 files changed, 95 insertions, 4 deletions
diff --git a/src/test/ui/async-await/issue-61076.rs b/src/test/ui/async-await/issue-61076.rs
index 13b45df64ea..e383a9126f7 100644
--- a/src/test/ui/async-await/issue-61076.rs
+++ b/src/test/ui/async-await/issue-61076.rs
@@ -6,6 +6,26 @@ use core::task::{Context, Poll};
 
 struct T;
 
+struct Tuple(i32);
+
+struct Struct {
+    a: i32
+}
+
+impl Struct {
+    fn method(&self) {}
+}
+
+impl Future for Struct {
+    type Output = Struct;
+    fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Self::Output> { Poll::Pending }
+}
+
+impl Future for Tuple {
+    type Output = Tuple;
+    fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Self::Output> { Poll::Pending }
+}
+
 impl Future for T {
     type Output = Result<(), ()>;
 
@@ -23,10 +43,31 @@ async fn bar() -> Result<(), ()> {
     Ok(())
 }
 
+async fn struct_() -> Struct {
+    Struct { a: 1 }
+}
+
+async fn tuple() -> Tuple {
+    Tuple(1i32)
+}
+
 async fn baz() -> Result<(), ()> {
     let t = T;
     t?; //~ ERROR the `?` operator can only be applied to values that implement `std::ops::Try`
+
+    let _: i32 = tuple().0; //~ ERROR no field `0`
+
+    let _: i32 = struct_().a; //~ ERROR no field `a`
+
+    struct_().method(); //~ ERROR no method named
+
     Ok(())
 }
 
+async fn match_() {
+    match tuple() {
+        Tuple(_) => {} //~ ERROR mismatched types
+    }
+}
+
 fn main() {}
diff --git a/src/test/ui/async-await/issue-61076.stderr b/src/test/ui/async-await/issue-61076.stderr
index e71f4e7136d..69b6e8c3cf5 100644
--- a/src/test/ui/async-await/issue-61076.stderr
+++ b/src/test/ui/async-await/issue-61076.stderr
@@ -1,5 +1,5 @@
 error[E0277]: the `?` operator can only be applied to values that implement `std::ops::Try`
-  --> $DIR/issue-61076.rs:22:5
+  --> $DIR/issue-61076.rs:42:5
    |
 LL |     foo()?;
    |     ^^^^^^
@@ -11,7 +11,7 @@ LL |     foo()?;
    = note: required by `std::ops::Try::into_result`
 
 error[E0277]: the `?` operator can only be applied to values that implement `std::ops::Try`
-  --> $DIR/issue-61076.rs:28:5
+  --> $DIR/issue-61076.rs:56:5
    |
 LL |     t?;
    |     ^^
@@ -22,6 +22,56 @@ LL |     t?;
    = help: the trait `std::ops::Try` is not implemented for `T`
    = note: required by `std::ops::Try::into_result`
 
-error: aborting due to 2 previous errors
+error[E0609]: no field `0` on type `impl std::future::Future`
+  --> $DIR/issue-61076.rs:58:26
+   |
+LL |     let _: i32 = tuple().0;
+   |                          ^
+   |
+help: consider awaiting before field access
+   |
+LL |     let _: i32 = tuple().await.0;
+   |                         ^^^^^^
+
+error[E0609]: no field `a` on type `impl std::future::Future`
+  --> $DIR/issue-61076.rs:60:28
+   |
+LL |     let _: i32 = struct_().a;
+   |                            ^
+   |
+help: consider awaiting before field access
+   |
+LL |     let _: i32 = struct_().await.a;
+   |                           ^^^^^^
+
+error[E0599]: no method named `method` found for opaque type `impl std::future::Future` in the current scope
+  --> $DIR/issue-61076.rs:62:15
+   |
+LL |     struct_().method();
+   |               ^^^^^^ method not found in `impl std::future::Future`
+   |
+help: consider awaiting before this method call
+   |
+LL |     struct_().await.method();
+   |               ^^^^^^
+
+error[E0308]: mismatched types
+  --> $DIR/issue-61076.rs:69:9
+   |
+LL | async fn tuple() -> Tuple {
+   |                     ----- the `Output` of this `async fn`'s expected opaque type
+...
+LL |         Tuple(_) => {}
+   |         ^^^^^^^^ expected opaque type, found struct `Tuple`
+   |
+   = note: expected opaque type `impl std::future::Future`
+                   found struct `Tuple`
+help: consider awaiting on the future
+   |
+LL |     match tuple().await {
+   |                  ^^^^^^
+
+error: aborting due to 6 previous errors
 
-For more information about this error, try `rustc --explain E0277`.
+Some errors have detailed explanations: E0277, E0308, E0599, E0609.
+For more information about an error, try `rustc --explain E0277`.