about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorcsmoe <csmoe@msn.com>2020-08-16 20:25:22 +0800
committercsmoe <csmoe@msn.com>2020-08-25 14:00:49 +0800
commit1de0dd9531bfae1db458c0d88830a5c09203a100 (patch)
tree08e7825ab56c86dec2c81e755f0dbc9d2ac80c95 /src/test
parent1d30de6202ea38a204849191cf9723600e522416 (diff)
downloadrust-1de0dd9531bfae1db458c0d88830a5c09203a100.tar.gz
rust-1de0dd9531bfae1db458c0d88830a5c09203a100.zip
suggest await on field access
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/async-await/issue-61076.rs30
-rw-r--r--src/test/ui/async-await/issue-61076.stderr43
2 files changed, 33 insertions, 40 deletions
diff --git a/src/test/ui/async-await/issue-61076.rs b/src/test/ui/async-await/issue-61076.rs
index e1753b28093..aead0ab438f 100644
--- a/src/test/ui/async-await/issue-61076.rs
+++ b/src/test/ui/async-await/issue-61076.rs
@@ -6,14 +6,20 @@ use core::task::{Context, Poll};
 
 struct T;
 
-struct UnionStruct(i32);
+struct Tuple(i32);
 
 struct Struct {
     a: i32
 }
 
-enum Enum {
-    A
+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 {
@@ -33,19 +39,21 @@ 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 = async {
-        UnionStruct(1i32)
-    }.0; //~ ERROR no field `0`
-
-    let _: i32 = async {
-        Struct { a: 1i32 }
-    }.a; //~ ERROR no field `a`
+    let _: i32 = tuple().0; //~ ERROR no field `0`
 
-    if let Enum::A = async { Enum::A } {} //~ ERROR mismatched type
+    let _: i32 = struct_().a; //~ ERROR no field `a`
 
     Ok(())
 }
diff --git a/src/test/ui/async-await/issue-61076.stderr b/src/test/ui/async-await/issue-61076.stderr
index af176a734e8..df4e2b8e810 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:32:5
+  --> $DIR/issue-61076.rs:38: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:38:5
+  --> $DIR/issue-61076.rs:52:5
    |
 LL |     t?;
    |     ^^
@@ -23,37 +23,22 @@ LL |     t?;
    = note: required by `std::ops::Try::into_result`
 
 error[E0609]: no field `0` on type `impl std::future::Future`
-  --> $DIR/issue-61076.rs:42:7
+  --> $DIR/issue-61076.rs:54:26
    |
-LL |     }.0;
-   |       ^
+LL |     let _: i32 = tuple().0;
+   |                  --------^
+   |                  |
+   |                  help: consider await before field access: `tuple().await.0`
 
 error[E0609]: no field `a` on type `impl std::future::Future`
-  --> $DIR/issue-61076.rs:46:7
-   |
-LL |     }.a;
-   |       ^
-
-error[E0308]: mismatched types
-  --> $DIR/issue-61076.rs:48:12
-   |
-LL |     A
-   |     - unit variant defined here
-...
-LL |     if let Enum::A = async { Enum::A } {}
-   |            ^^^^^^^         ----------- the expected generator
-   |            |
-   |            expected opaque type, found enum `Enum`
-   | 
-  ::: $SRC_DIR/libcore/future/mod.rs:LL:COL
-   |
-LL | pub const fn from_generator<T>(gen: T) -> impl Future<Output = T::Return>
-   |                                           ------------------------------- the expected opaque type
+  --> $DIR/issue-61076.rs:56:28
    |
-   = note: expected opaque type `impl std::future::Future`
-                     found enum `Enum`
+LL |     let _: i32 = struct_().a;
+   |                  ----------^
+   |                  |
+   |                  help: consider await before field access: `struct_().await.a`
 
-error: aborting due to 5 previous errors
+error: aborting due to 4 previous errors
 
-Some errors have detailed explanations: E0277, E0308, E0609.
+Some errors have detailed explanations: E0277, E0609.
 For more information about an error, try `rustc --explain E0277`.