-
Notifications
You must be signed in to change notification settings - Fork 32
/
loop.rs
110 lines (89 loc) · 1.63 KB
/
loop.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
const _: () = loop { break (); };
static FOO: i32 = loop { break 4; };
const fn foo() {
loop {}
}
pub trait Foo {
const BAR: i32 = loop { break 4; };
}
impl Foo for () {
const BAR: i32 = loop { break 4; };
}
fn non_const_outside() {
const fn const_inside() {
loop {}
}
}
const fn const_outside() {
fn non_const_inside() {
loop {}
}
}
fn main() {
let x = [0; {
while false {}
4
}];
}
const _: i32 = {
let mut x = 0;
while x < 4 {
x += 1;
}
while x < 8 {
x += 1;
}
x
};
const _: i32 = {
let mut x = 0;
for i in 0..4 { //~ ERROR `for` is not allowed in a `const`
//~^ ERROR: cannot call
//~| ERROR: mutable references
//~| ERROR: cannot convert
x += i;
}
for i in 0..4 { //~ ERROR `for` is not allowed in a `const`
//~^ ERROR: cannot call
//~| ERROR: mutable references
//~| ERROR: cannot convert
x += i;
}
x
};
const _: i32 = {
let mut x = 0;
loop {
x += 1;
if x == 4 {
break;
}
}
loop {
x += 1;
if x == 8 {
break;
}
}
x
};
const _: i32 = {
let mut x = 0;
while let None = Some(x) { }
while let None = Some(x) { }
x
};
// ferrocene-annotations: fls_onfyolkcbeh3
// For Loops
//
// ferrocene-annotations: fls_sf4qnd43z2wc
// Infinite Loops
//
// ferrocene-annotations: fls_rr908hgunja7
// Loop Expressions
//
// ferrocene-annotations: fls_5jjm1kt43axd
// While Loops
//
// ferrocene-annotations: fls_zjoamsr3dbqk
// Diverging Expressions