1
+ const _: () = loop {}; //~ ERROR loop is not allowed in a const
2
+
3
+ static FOO: i32 = loop { break 4; }; //~ ERROR loop is not allowed in a static
4
+
5
+ const fn foo() {
6
+ loop {} //~ ERROR loop is not allowed in a const fn
7
+ }
8
+
9
+ pub trait Foo {
10
+ const BAR: i32 = loop { break 4; }; //~ ERROR loop is not allowed in a const
11
+ }
12
+
13
+ impl Foo for () {
14
+ const BAR: i32 = loop { break 4; }; //~ ERROR loop is not allowed in a const
15
+ }
16
+
17
+ fn non_const_outside() {
18
+ const fn const_inside() {
19
+ loop {} //~ ERROR `loop` is not allowed in a `const fn`
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
+ //~^ ERROR `while` is not allowed in a `const`
33
+ //~| ERROR constant contains unimplemented expression type
34
+ //~| ERROR constant contains unimplemented expression type
35
+ 4
36
+ }];
37
+ }
38
+
1
39
const _: i32 = {
2
40
let mut x = 0;
3
41
4
- while x < 4 {
5
- //~^ ERROR constant contains unimplemented expression type
6
- //~| ERROR constant contains unimplemented expression type
42
+ while x < 4 { //~ ERROR while loop is not allowed in a const
7
43
x += 1;
8
44
}
9
45
10
- while x < 8 {
46
+ while x < 8 { //~ ERROR while loop is not allowed in a const
11
47
x += 1;
12
48
}
13
49
@@ -17,16 +53,11 @@ const _: i32 = {
17
53
const _: i32 = {
18
54
let mut x = 0;
19
55
20
- for i in 0..4 {
21
- //~^ ERROR constant contains unimplemented expression type
22
- //~| ERROR constant contains unimplemented expression type
23
- //~| ERROR references in constants may only refer to immutable values
24
- //~| ERROR calls in constants are limited to constant functions, tuple
25
- // structs and tuple variants
56
+ for i in 0..4 { //~ ERROR for loop is not allowed in a const
26
57
x += i;
27
58
}
28
59
29
- for i in 0..4 {
60
+ for i in 0..4 { //~ ERROR for loop is not allowed in a const
30
61
x += i;
31
62
}
32
63
@@ -36,23 +67,26 @@ const _: i32 = {
36
67
const _: i32 = {
37
68
let mut x = 0;
38
69
39
- loop {
70
+ loop { //~ ERROR loop is not allowed in a const
40
71
x += 1;
41
- if x == 4 {
42
- //~^ ERROR constant contains unimplemented expression type
43
- //~| ERROR constant contains unimplemented expression type
72
+ if x == 4 { //~ ERROR if expression is not allowed in a const
44
73
break;
45
74
}
46
75
}
47
76
48
- loop {
77
+ loop { //~ ERROR loop is not allowed in a const
49
78
x += 1;
50
- if x == 8 {
79
+ if x == 8 { //~ ERROR if expression is not allowed in a const
51
80
break;
52
81
}
53
82
}
54
83
55
84
x
56
85
};
57
86
58
- fn main() {}
87
+ const _: i32 = {
88
+ let mut x = 0;
89
+ while let None = Some(x) { } //~ ERROR while loop is not allowed in a const
90
+ while let None = Some(x) { } //~ ERROR while loop is not allowed in a const
91
+ x
92
+ };
0 commit comments