about summary refs log tree commit diff
path: root/src/test/ui/async-await
diff options
context:
space:
mode:
authorTyler Mandry <tmandry@gmail.com>2019-11-01 11:20:14 -0700
committerGitHub <noreply@github.com>2019-11-01 11:20:14 -0700
commitd75338e6301ea842bc3dd92e3793626b20346aaf (patch)
tree0c9c12126d0750a551a8d6d36e30e7f331408345 /src/test/ui/async-await
parent48a9f59ae7e1444ee38fb5afa849daacfb7d02e7 (diff)
parentd7869ec02281be58ed3857b545f258b81a6adb09 (diff)
downloadrust-d75338e6301ea842bc3dd92e3793626b20346aaf.tar.gz
rust-d75338e6301ea842bc3dd92e3793626b20346aaf.zip
Rollup merge of #65902 - gilescope:issue62570, r=estebank
Make ItemContext available for better diagnositcs

Fix #62570
Diffstat (limited to 'src/test/ui/async-await')
-rw-r--r--src/test/ui/async-await/try-on-option-in-async.rs27
-rw-r--r--src/test/ui/async-await/try-on-option-in-async.stderr30
2 files changed, 57 insertions, 0 deletions
diff --git a/src/test/ui/async-await/try-on-option-in-async.rs b/src/test/ui/async-await/try-on-option-in-async.rs
new file mode 100644
index 00000000000..51ac522017c
--- /dev/null
+++ b/src/test/ui/async-await/try-on-option-in-async.rs
@@ -0,0 +1,27 @@
+#![feature(try_trait, async_closure)]
+// edition:2018
+fn main() {}
+
+async fn an_async_block() -> u32 {
+    async {
+        let x: Option<u32> = None;
+        x?; //~ ERROR the `?` operator
+        22
+    }.await
+}
+
+async fn async_closure_containing_fn() -> u32 {
+    let async_closure = async || {
+        let x: Option<u32> = None;
+        x?; //~ ERROR the `?` operator
+        22_u32
+    };
+
+    async_closure().await
+}
+
+async fn an_async_function() -> u32 {
+    let x: Option<u32> = None;
+    x?; //~ ERROR the `?` operator
+    22
+}
diff --git a/src/test/ui/async-await/try-on-option-in-async.stderr b/src/test/ui/async-await/try-on-option-in-async.stderr
new file mode 100644
index 00000000000..7d31f60efdc
--- /dev/null
+++ b/src/test/ui/async-await/try-on-option-in-async.stderr
@@ -0,0 +1,30 @@
+error[E0277]: the `?` operator can only be used in an async block that returns `Result` or `Option` (or another type that implements `std::ops::Try`)
+  --> $DIR/try-on-option-in-async.rs:8:9
+   |
+LL |         x?;
+   |         ^^ cannot use the `?` operator in an async block that returns `{integer}`
+   |
+   = help: the trait `std::ops::Try` is not implemented for `{integer}`
+   = note: required by `std::ops::Try::from_error`
+
+error[E0277]: the `?` operator can only be used in an async closure that returns `Result` or `Option` (or another type that implements `std::ops::Try`)
+  --> $DIR/try-on-option-in-async.rs:16:9
+   |
+LL |         x?;
+   |         ^^ cannot use the `?` operator in an async closure that returns `u32`
+   |
+   = help: the trait `std::ops::Try` is not implemented for `u32`
+   = note: required by `std::ops::Try::from_error`
+
+error[E0277]: the `?` operator can only be used in an async function that returns `Result` or `Option` (or another type that implements `std::ops::Try`)
+  --> $DIR/try-on-option-in-async.rs:25:5
+   |
+LL |     x?;
+   |     ^^ cannot use the `?` operator in an async function that returns `u32`
+   |
+   = help: the trait `std::ops::Try` is not implemented for `u32`
+   = note: required by `std::ops::Try::from_error`
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0277`.