]> git.lizzy.rs Git - rust.git/blob - tests/ui/loops/loop-proper-liveness.rs
Rollup merge of #106397 - compiler-errors:new-solver-impl-wc, r=lcnr
[rust.git] / tests / ui / loops / loop-proper-liveness.rs
1 fn test1() {
2     // In this test the outer 'a loop may terminate without `x` getting initialised. Although the
3     // `x = loop { ... }` statement is reached, the value itself ends up never being computed and
4     // thus leaving `x` uninit.
5     let x: i32;
6     'a: loop {
7         x = loop { break 'a };
8     }
9     println!("{:?}", x); //~ ERROR E0381
10 }
11
12 // test2 and test3 should not fail.
13 fn test2() {
14     // In this test the `'a` loop will never terminate thus making the use of `x` unreachable.
15     let x: i32;
16     'a: loop {
17         x = loop { continue 'a };
18     }
19     println!("{:?}", x);
20 }
21
22 fn test3() {
23     let x: i32;
24     // Similarly, the use of variable `x` is unreachable.
25     'a: loop {
26         x = loop { return };
27     }
28     println!("{:?}", x);
29 }
30
31 fn main() {
32 }