]> git.proxmox.com Git - rustc.git/blob - src/test/ui/consts/control-flow/loop.rs
New upstream version 1.67.1+dfsg1
[rustc.git] / src / test / ui / consts / control-flow / loop.rs
1 const _: () = loop { break (); };
2
3 static FOO: i32 = loop { break 4; };
4
5 const fn foo() {
6 loop {}
7 }
8
9 pub trait Foo {
10 const BAR: i32 = loop { break 4; };
11 }
12
13 impl Foo for () {
14 const BAR: i32 = loop { break 4; };
15 }
16
17 fn non_const_outside() {
18 const fn const_inside() {
19 loop {}
20 }
21 }
22
23 const fn const_outside() {
24 fn non_const_inside() {
25 loop {}
26 }
27 }
28
29 fn main() {
30 let x = [0; {
31 while false {}
32 4
33 }];
34 }
35
36 const _: i32 = {
37 let mut x = 0;
38
39 while x < 4 {
40 x += 1;
41 }
42
43 while x < 8 {
44 x += 1;
45 }
46
47 x
48 };
49
50 const _: i32 = {
51 let mut x = 0;
52
53 for i in 0..4 { //~ ERROR `for` is not allowed in a `const`
54 x += i;
55 }
56
57 for i in 0..4 { //~ ERROR `for` is not allowed in a `const`
58 x += i;
59 }
60
61 x
62 };
63
64 const _: i32 = {
65 let mut x = 0;
66
67 loop {
68 x += 1;
69 if x == 4 {
70 break;
71 }
72 }
73
74 loop {
75 x += 1;
76 if x == 8 {
77 break;
78 }
79 }
80
81 x
82 };
83
84 const _: i32 = {
85 let mut x = 0;
86 while let None = Some(x) { }
87 while let None = Some(x) { }
88 x
89 };