diff options
| author | Tyler Mandry <tmandry@gmail.com> | 2019-11-01 11:20:14 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-11-01 11:20:14 -0700 |
| commit | d75338e6301ea842bc3dd92e3793626b20346aaf (patch) | |
| tree | 0c9c12126d0750a551a8d6d36e30e7f331408345 /src/test/ui/async-await | |
| parent | 48a9f59ae7e1444ee38fb5afa849daacfb7d02e7 (diff) | |
| parent | d7869ec02281be58ed3857b545f258b81a6adb09 (diff) | |
| download | rust-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.rs | 27 | ||||
| -rw-r--r-- | src/test/ui/async-await/try-on-option-in-async.stderr | 30 |
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`. |
