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