forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test conditional initialization validation in async fns
- Loading branch information
Showing
3 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
src/test/ui/async-await/conditional-and-guaranteed-initialization.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 } |
16 changes: 16 additions & 0 deletions
16
src/test/ui/async-await/no-non-guaranteed-initialization.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 } |
9 changes: 9 additions & 0 deletions
9
src/test/ui/async-await/no-non-guaranteed-initialization.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |