mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 07:14:28 +00:00
Test conditional initialization validation in async fns
This commit is contained in:
parent
4be0675589
commit
811c304029
@ -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
src/test/ui/async-await/no-non-guaranteed-initialization.rs
Normal file
16
src/test/ui/async-await/no-non-guaranteed-initialization.rs
Normal file
@ -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 }
|
@ -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`.
|
Loading…
Reference in New Issue
Block a user