]> git.lizzy.rs Git - rust.git/blob - src/test/ui/async-await/partial-initialization-across-await.rs
Rollup merge of #63737 - HowJMay:fix_naming, r=jonas-schievink
[rust.git] / src / test / ui / async-await / partial-initialization-across-await.rs
1 // Test that we don't allow awaiting from an async fn while a local is partially
2 // initialized.
3
4 // edition:2018
5
6 struct S { x: i32, y: i32 }
7 struct T(i32, i32);
8
9 async fn noop() {}
10
11 async fn test_tuple() {
12     let mut t: (i32, i32);
13     t.0 = 42;
14     //~^ ERROR assign to part of possibly uninitialized variable: `t` [E0381]
15     noop().await;
16     t.1 = 88;
17     let _ = t;
18 }
19
20 async fn test_tuple_struct() {
21     let mut t: T;
22     t.0 = 42;
23     //~^ ERROR assign to part of possibly uninitialized variable: `t` [E0381]
24     noop().await;
25     t.1 = 88;
26     let _ = t;
27 }
28
29 async fn test_struct() {
30     let mut t: S;
31     t.x = 42;
32     //~^ ERROR assign to part of possibly uninitialized variable: `t` [E0381]
33     noop().await;
34     t.y = 88;
35     let _ = t;
36 }
37
38 fn main() {
39     let _ = test_tuple();
40     let _ = test_tuple_struct();
41     let _ = test_struct();
42 }