rust/tests/ui/consts/control-flow/loop.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

96 lines
1.3 KiB
Rust
Raw Normal View History

2020-06-25 19:43:48 -05:00
const _: () = loop { break (); };
2020-06-25 19:43:48 -05:00
static FOO: i32 = loop { break 4; };
const fn foo() {
2020-06-25 19:43:48 -05:00
loop {}
}
pub trait Foo {
2020-06-25 19:43:48 -05:00
const BAR: i32 = loop { break 4; };
}
impl Foo for () {
2020-06-25 19:43:48 -05:00
const BAR: i32 = loop { break 4; };
}
fn non_const_outside() {
const fn const_inside() {
2020-06-25 19:43:48 -05:00
loop {}
}
}
const fn const_outside() {
fn non_const_inside() {
loop {}
}
}
fn main() {
let x = [0; {
while false {}
4
}];
}
const _: i32 = {
let mut x = 0;
2020-06-25 19:43:48 -05:00
while x < 4 {
x += 1;
}
2020-06-25 19:43:48 -05:00
while x < 8 {
x += 1;
}
x
};
const _: i32 = {
let mut x = 0;
2020-06-25 19:43:48 -05:00
for i in 0..4 { //~ ERROR `for` is not allowed in a `const`
//~^ ERROR: cannot call
//~| ERROR: mutable references
//~| ERROR: cannot convert
x += i;
}
2020-06-25 19:43:48 -05:00
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;
2020-06-25 19:43:48 -05:00
loop {
x += 1;
2020-05-21 14:49:38 -05:00
if x == 4 {
break;
}
}
2020-06-25 19:43:48 -05:00
loop {
x += 1;
2020-05-21 14:49:38 -05:00
if x == 8 {
break;
}
}
x
};
const _: i32 = {
let mut x = 0;
2020-06-25 19:43:48 -05:00
while let None = Some(x) { }
while let None = Some(x) { }
x
};