diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-08-08 22:38:26 +0200 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-08-09 00:21:21 +0200 |
| commit | 48fbf4891a138edbaf2142ff9121c298c2750164 (patch) | |
| tree | 7cd7d794bc32c70b3137a43be05d63b30c340e3c /src/test/ui/async-await/async-block-control-flow-static-semantics.rs | |
| parent | 04523404bcae5904fe29a54122040a7101f5c652 (diff) | |
| download | rust-48fbf4891a138edbaf2142ff9121c298c2750164.tar.gz rust-48fbf4891a138edbaf2142ff9121c298c2750164.zip | |
Test interaction btw async blocks and ?, return, break.
Diffstat (limited to 'src/test/ui/async-await/async-block-control-flow-static-semantics.rs')
| -rw-r--r-- | src/test/ui/async-await/async-block-control-flow-static-semantics.rs | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/src/test/ui/async-await/async-block-control-flow-static-semantics.rs b/src/test/ui/async-await/async-block-control-flow-static-semantics.rs new file mode 100644 index 00000000000..6a766ede0ed --- /dev/null +++ b/src/test/ui/async-await/async-block-control-flow-static-semantics.rs @@ -0,0 +1,67 @@ +// Test that `async { .. }` blocks: +// 1. do not allow `break` expressions. +// 2. get targeted by `return` and not the parent function. +// 3. get targeted by `?` and not the parent function. +// +// edition:2018 +// ignore-tidy-linelength + +#![feature(async_await)] + +fn main() {} + +use core::future::Future; + +fn return_targets_async_block_not_fn() -> u8 { + //~^ ERROR mismatched types + let block = async { + return 0u8; + }; + let _: &dyn Future<Output = ()> = █ + //~^ ERROR type mismatch resolving `<impl std::future::Future as std::future::Future>::Output == ()` +} + +async fn return_targets_async_block_not_async_fn() -> u8 { + //~^ ERROR type mismatch resolving + let block = async { + return 0u8; + }; + let _: &dyn Future<Output = ()> = █ + //~^ ERROR type mismatch resolving `<impl std::future::Future as std::future::Future>::Output == ()` +} + +fn no_break_in_async_block() { + async { + break 0u8; //~ ERROR `break` inside of a closure + // FIXME: This diagnostic is pretty bad. + }; +} + +fn no_break_in_async_block_even_with_outer_loop() { + loop { + async { + break 0u8; //~ ERROR `break` inside of a closure + }; + } +} + +struct MyErr; +fn err() -> Result<u8, MyErr> { Err(MyErr) } + +fn rethrow_targets_async_block_not_fn() -> Result<u8, MyErr> { + //~^ ERROR mismatched types + let block = async { + err()?; + Ok(()) + }; + let _: &dyn Future<Output = Result<(), MyErr>> = █ +} + +fn rethrow_targets_async_block_not_async_fn() -> Result<u8, MyErr> { + //~^ ERROR mismatched types + let block = async { + err()?; + Ok(()) + }; + let _: &dyn Future<Output = Result<(), MyErr>> = █ +} |
