Extend const-loop and const-if to handle more cases
This makes sure that our HIR visitor is visiting as many const-items as possible.
This commit is contained in:
parent
92386e8e57
commit
67336bb399
2 changed files with 71 additions and 21 deletions
|
@ -1,5 +1,21 @@
|
|||
const _X: i32 = if true { 5 } else { 6 };
|
||||
//~^ ERROR constant contains unimplemented expression type
|
||||
//~| ERROR constant contains unimplemented expression type
|
||||
const _: i32 = if true { //~ ERROR if expression is not allowed in a const
|
||||
5
|
||||
} else {
|
||||
6
|
||||
};
|
||||
|
||||
const _: i32 = match 1 { //~ ERROR match expression is not allowed in a const
|
||||
2 => 3,
|
||||
4 => 5,
|
||||
_ => 0,
|
||||
};
|
||||
|
||||
const fn foo() -> i32 {
|
||||
if true { 5 } else { 6 } //~ ERROR if expression is not allowed in a const fn
|
||||
}
|
||||
|
||||
const fn bar() -> i32 {
|
||||
match 0 { 1 => 2, _ => 0 } //~ ERROR match expression is not allowed in a const fn
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
@ -1,13 +1,49 @@
|
|||
const _: () = loop {}; //~ ERROR loop is not allowed in a const
|
||||
|
||||
static FOO: i32 = loop { break 4; }; //~ ERROR loop is not allowed in a static
|
||||
|
||||
const fn foo() {
|
||||
loop {} //~ ERROR loop is not allowed in a const fn
|
||||
}
|
||||
|
||||
pub trait Foo {
|
||||
const BAR: i32 = loop { break 4; }; //~ ERROR loop is not allowed in a const
|
||||
}
|
||||
|
||||
impl Foo for () {
|
||||
const BAR: i32 = loop { break 4; }; //~ ERROR loop is not allowed in a const
|
||||
}
|
||||
|
||||
fn non_const_outside() {
|
||||
const fn const_inside() {
|
||||
loop {} //~ ERROR `loop` is not allowed in a `const fn`
|
||||
}
|
||||
}
|
||||
|
||||
const fn const_outside() {
|
||||
fn non_const_inside() {
|
||||
loop {}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = [0; {
|
||||
while false {}
|
||||
//~^ ERROR `while` is not allowed in a `const`
|
||||
//~| ERROR constant contains unimplemented expression type
|
||||
//~| ERROR constant contains unimplemented expression type
|
||||
4
|
||||
}];
|
||||
}
|
||||
|
||||
const _: i32 = {
|
||||
let mut x = 0;
|
||||
|
||||
while x < 4 {
|
||||
//~^ ERROR constant contains unimplemented expression type
|
||||
//~| ERROR constant contains unimplemented expression type
|
||||
while x < 4 { //~ ERROR while loop is not allowed in a const
|
||||
x += 1;
|
||||
}
|
||||
|
||||
while x < 8 {
|
||||
while x < 8 { //~ ERROR while loop is not allowed in a const
|
||||
x += 1;
|
||||
}
|
||||
|
||||
|
@ -17,16 +53,11 @@ const _: i32 = {
|
|||
const _: i32 = {
|
||||
let mut x = 0;
|
||||
|
||||
for i in 0..4 {
|
||||
//~^ ERROR constant contains unimplemented expression type
|
||||
//~| ERROR constant contains unimplemented expression type
|
||||
//~| ERROR references in constants may only refer to immutable values
|
||||
//~| ERROR calls in constants are limited to constant functions, tuple
|
||||
// structs and tuple variants
|
||||
for i in 0..4 { //~ ERROR for loop is not allowed in a const
|
||||
x += i;
|
||||
}
|
||||
|
||||
for i in 0..4 {
|
||||
for i in 0..4 { //~ ERROR for loop is not allowed in a const
|
||||
x += i;
|
||||
}
|
||||
|
||||
|
@ -36,18 +67,16 @@ const _: i32 = {
|
|||
const _: i32 = {
|
||||
let mut x = 0;
|
||||
|
||||
loop {
|
||||
loop { //~ ERROR loop is not allowed in a const
|
||||
x += 1;
|
||||
if x == 4 {
|
||||
//~^ ERROR constant contains unimplemented expression type
|
||||
//~| ERROR constant contains unimplemented expression type
|
||||
if x == 4 { //~ ERROR if expression is not allowed in a const
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
loop {
|
||||
loop { //~ ERROR loop is not allowed in a const
|
||||
x += 1;
|
||||
if x == 8 {
|
||||
if x == 8 { //~ ERROR if expression is not allowed in a const
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -55,4 +84,9 @@ const _: i32 = {
|
|||
x
|
||||
};
|
||||
|
||||
fn main() {}
|
||||
const _: i32 = {
|
||||
let mut x = 0;
|
||||
while let None = Some(x) { } //~ ERROR while loop is not allowed in a const
|
||||
while let None = Some(x) { } //~ ERROR while loop is not allowed in a const
|
||||
x
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue