Skip to content

Commit 811c304

Browse files
committed
Test conditional initialization validation in async fns
1 parent 4be0675 commit 811c304

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// check-pass
2+
// edition:2018
3+
// compile-flags: --crate-type lib
4+
5+
#![feature(async_await)]
6+
7+
async fn conditional_and_guaranteed_initialization(x: usize) -> usize {
8+
let y;
9+
if x > 5 {
10+
y = echo(10).await;
11+
} else {
12+
y = get_something().await;
13+
}
14+
y
15+
}
16+
17+
async fn echo(x: usize) -> usize { x }
18+
async fn get_something() -> usize { 10 }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// compile-fail
2+
// edition:2018
3+
// compile-flags: --crate-type lib
4+
5+
#![feature(async_await)]
6+
7+
async fn no_non_guaranteed_initialization(x: usize) -> usize {
8+
let y;
9+
if x > 5 {
10+
y = echo(10).await;
11+
}
12+
y
13+
//~^ use of possibly uninitialized variable: `y`
14+
}
15+
16+
async fn echo(x: usize) -> usize { x + 1 }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0381]: use of possibly uninitialized variable: `y`
2+
--> $DIR/no-non-guaranteed-initialization.rs:12:5
3+
|
4+
LL | y
5+
| ^ use of possibly uninitialized `y`
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0381`.

0 commit comments

Comments
 (0)