2019-12-11 18:16:12 +00:00
|
|
|
// Ensure that loops are forbidden in a const context unless `#![feature(const_loop)]` is enabled.
|
2019-11-18 05:11:42 +00:00
|
|
|
|
2019-12-11 05:11:53 +00:00
|
|
|
// gate-test-const_loop
|
2020-05-21 19:49:38 +00:00
|
|
|
// revisions: stock loop_
|
2019-11-18 05:11:42 +00:00
|
|
|
|
2020-05-21 19:49:38 +00:00
|
|
|
#![cfg_attr(loop_, feature(const_loop))]
|
2019-11-18 05:11:42 +00:00
|
|
|
|
2020-05-21 19:49:38 +00:00
|
|
|
const _: () = loop {}; //[stock]~ ERROR `loop` is not allowed in a `const`
|
2019-11-18 05:11:42 +00:00
|
|
|
|
2020-05-21 19:49:38 +00:00
|
|
|
static FOO: i32 = loop { break 4; }; //[stock]~ ERROR `loop` is not allowed in a `static`
|
2019-11-18 05:11:42 +00:00
|
|
|
|
|
|
|
const fn foo() {
|
2020-05-21 19:49:38 +00:00
|
|
|
loop {} //[stock]~ ERROR `loop` is not allowed in a `const fn`
|
2019-11-18 05:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub trait Foo {
|
2020-05-21 19:49:38 +00:00
|
|
|
const BAR: i32 = loop { break 4; }; //[stock]~ ERROR `loop` is not allowed in a `const`
|
2019-11-18 05:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Foo for () {
|
2020-05-21 19:49:38 +00:00
|
|
|
const BAR: i32 = loop { break 4; }; //[stock]~ ERROR `loop` is not allowed in a `const`
|
2019-11-18 05:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn non_const_outside() {
|
|
|
|
const fn const_inside() {
|
2020-05-21 19:49:38 +00:00
|
|
|
loop {} //[stock]~ ERROR `loop` is not allowed in a `const fn`
|
2019-11-18 05:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const fn const_outside() {
|
|
|
|
fn non_const_inside() {
|
|
|
|
loop {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let x = [0; {
|
|
|
|
while false {}
|
2020-05-21 19:49:38 +00:00
|
|
|
//[stock]~^ ERROR `while` is not allowed in a `const`
|
2019-11-18 05:11:42 +00:00
|
|
|
4
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
const _: i32 = {
|
|
|
|
let mut x = 0;
|
|
|
|
|
2020-05-21 19:49:38 +00:00
|
|
|
while x < 4 { //[stock]~ ERROR `while` is not allowed in a `const`
|
2019-11-18 05:11:42 +00:00
|
|
|
x += 1;
|
|
|
|
}
|
|
|
|
|
2020-05-21 19:49:38 +00:00
|
|
|
while x < 8 { //[stock]~ ERROR `while` is not allowed in a `const`
|
2019-11-18 05:11:42 +00:00
|
|
|
x += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
x
|
|
|
|
};
|
|
|
|
|
|
|
|
const _: i32 = {
|
|
|
|
let mut x = 0;
|
|
|
|
|
2020-05-21 19:49:38 +00:00
|
|
|
for i in 0..4 { //[stock,loop_]~ ERROR `for` is not allowed in a `const`
|
2019-11-18 05:11:42 +00:00
|
|
|
x += i;
|
|
|
|
}
|
|
|
|
|
2020-05-21 19:49:38 +00:00
|
|
|
for i in 0..4 { //[stock,loop_]~ ERROR `for` is not allowed in a `const`
|
2019-11-18 05:11:42 +00:00
|
|
|
x += i;
|
|
|
|
}
|
|
|
|
|
|
|
|
x
|
|
|
|
};
|
|
|
|
|
|
|
|
const _: i32 = {
|
|
|
|
let mut x = 0;
|
|
|
|
|
2020-05-21 19:49:38 +00:00
|
|
|
loop { //[stock]~ ERROR `loop` is not allowed in a `const`
|
2019-11-18 05:11:42 +00:00
|
|
|
x += 1;
|
2020-05-21 19:49:38 +00:00
|
|
|
if x == 4 {
|
2019-11-18 05:11:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-21 19:49:38 +00:00
|
|
|
loop { //[stock]~ ERROR `loop` is not allowed in a `const`
|
2019-11-18 05:11:42 +00:00
|
|
|
x += 1;
|
2020-05-21 19:49:38 +00:00
|
|
|
if x == 8 {
|
2019-11-18 05:11:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
x
|
|
|
|
};
|
|
|
|
|
|
|
|
const _: i32 = {
|
|
|
|
let mut x = 0;
|
2020-05-21 19:49:38 +00:00
|
|
|
while let None = Some(x) { } //[stock]~ ERROR `while` is not allowed in a `const`
|
|
|
|
while let None = Some(x) { } //[stock]~ ERROR `while` is not allowed in a `const`
|
2019-11-18 05:11:42 +00:00
|
|
|
x
|
|
|
|
};
|