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+
139const _: i32 = {
240 let mut x = 0 ;
341
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
743 x += 1 ;
844 }
945
10- while x < 8 {
46+ while x < 8 { //~ ERROR while loop is not allowed in a const
1147 x += 1 ;
1248 }
1349
@@ -17,16 +53,11 @@ const _: i32 = {
1753const _: i32 = {
1854 let mut x = 0 ;
1955
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
2657 x += i;
2758 }
2859
29- for i in 0 ..4 {
60+ for i in 0 ..4 { //~ ERROR for loop is not allowed in a const
3061 x += i;
3162 }
3263
@@ -36,23 +67,26 @@ const _: i32 = {
3667const _: i32 = {
3768 let mut x = 0 ;
3869
39- loop {
70+ loop { //~ ERROR loop is not allowed in a const
4071 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
4473 break ;
4574 }
4675 }
4776
48- loop {
77+ loop { //~ ERROR loop is not allowed in a const
4978 x += 1 ;
50- if x == 8 {
79+ if x == 8 { //~ ERROR if expression is not allowed in a const
5180 break ;
5281 }
5382 }
5483
5584 x
5685} ;
5786
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