diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-08-08 07:35:35 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-08-08 07:35:35 +0200 |
| commit | 4f415fca379f4de29835002bf5cfb033eebf3a31 (patch) | |
| tree | 0e4c9a46e8c63b4410036b2912181f77123d8eea /src | |
| parent | ab9a95b91b1ef893d97d87caac89b2c80a62c4dc (diff) | |
| parent | 811c3040299beb2cc90dc143b90af32dc78b0a3a (diff) | |
| download | rust-4f415fca379f4de29835002bf5cfb033eebf3a31.tar.gz rust-4f415fca379f4de29835002bf5cfb033eebf3a31.zip | |
Rollup merge of #63331 - gorup:conditionalinit, r=cramertj
Test conditional initialization validation in async fns r? @cramertj Per [paper doc](https://paper.dropbox.com/doc/async.await-Call-for-Tests--AiWF2Nt8tgDiA70qFI~oiLOOAg-nMyZGrra7dz9KcFRMLKJy) calling for async/.await tests, tests are desired for conditionally initialized local variables. This PR hopes to provide tests for that. #63294 seems to be tracking the items from the paper doc that this PR is related to #62121 is an open issue asking for more async/.await tests that this relates to --- :+1: executed 2 new tests :+1: tidy
Diffstat (limited to 'src')
3 files changed, 43 insertions, 0 deletions
diff --git a/src/test/ui/async-await/conditional-and-guaranteed-initialization.rs b/src/test/ui/async-await/conditional-and-guaranteed-initialization.rs new file mode 100644 index 00000000000..a5947e7f718 --- /dev/null +++ b/src/test/ui/async-await/conditional-and-guaranteed-initialization.rs @@ -0,0 +1,18 @@ +// check-pass +// edition:2018 +// compile-flags: --crate-type lib + +#![feature(async_await)] + +async fn conditional_and_guaranteed_initialization(x: usize) -> usize { + let y; + if x > 5 { + y = echo(10).await; + } else { + y = get_something().await; + } + y +} + +async fn echo(x: usize) -> usize { x } +async fn get_something() -> usize { 10 } diff --git a/src/test/ui/async-await/no-non-guaranteed-initialization.rs b/src/test/ui/async-await/no-non-guaranteed-initialization.rs new file mode 100644 index 00000000000..a916afb6b09 --- /dev/null +++ b/src/test/ui/async-await/no-non-guaranteed-initialization.rs @@ -0,0 +1,16 @@ +// compile-fail +// edition:2018 +// compile-flags: --crate-type lib + +#![feature(async_await)] + +async fn no_non_guaranteed_initialization(x: usize) -> usize { + let y; + if x > 5 { + y = echo(10).await; + } + y + //~^ use of possibly uninitialized variable: `y` +} + +async fn echo(x: usize) -> usize { x + 1 } diff --git a/src/test/ui/async-await/no-non-guaranteed-initialization.stderr b/src/test/ui/async-await/no-non-guaranteed-initialization.stderr new file mode 100644 index 00000000000..fb94522cac0 --- /dev/null +++ b/src/test/ui/async-await/no-non-guaranteed-initialization.stderr @@ -0,0 +1,9 @@ +error[E0381]: use of possibly uninitialized variable: `y` + --> $DIR/no-non-guaranteed-initialization.rs:12:5 + | +LL | y + | ^ use of possibly uninitialized `y` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0381`. |
