Add qualif smoke tests for const loops

This commit is contained in:
Dylan MacKenzie 2019-12-10 21:24:46 -08:00
parent 99e132db97
commit 1122404be5
3 changed files with 61 additions and 0 deletions

View File

@ -1,4 +1,5 @@
#![feature(const_if_match)]
#![feature(const_loop)]
// `x` is *not* always moved into the final value may be dropped inside the initializer.
const _: Option<Vec<i32>> = {
@ -32,4 +33,27 @@ const _: Vec<i32> = {
}
};
const _: Option<Vec<i32>> = {
let mut some = Some(Vec::new());
let mut tmp = None;
//~^ ERROR destructors cannot be evaluated at compile-time
let mut i = 0;
while i < 10 {
tmp = some;
some = None;
if i > 100 {
break;
}
some = tmp;
tmp = None;
i += 1;
}
some
};
fn main() {}

View File

@ -1,6 +1,7 @@
// run-pass
#![feature(const_if_match)]
#![feature(const_loop)]
// `x` is always moved into the final value and is not dropped inside the initializer.
const _: Option<Vec<i32>> = {
@ -21,4 +22,24 @@ const _: Option<Vec<i32>> = {
}
};
const _: Option<Vec<i32>> = {
let mut some = Some(Vec::new());
let mut tmp = None;
let mut i = 0;
while i < 10 {
tmp = some;
some = None;
// We can never exit the loop with `Some` in `tmp`.
some = tmp;
tmp = None;
i += 1;
}
some
};
fn main() {}

View File

@ -2,6 +2,7 @@
// disqualifies it from promotion.
#![feature(const_if_match)]
#![feature(const_loop)]
use std::cell::Cell;
@ -21,7 +22,22 @@ const Y: Option<Cell<i32>> = {
y
};
const Z: Option<Cell<i32>> = {
let mut z = None;
let mut i = 0;
while i < 10 {
if i == 8 {
z = Some(Cell::new(4));
}
i += 1;
}
z
};
fn main() {
let x: &'static _ = &X; //~ ERROR temporary value dropped while borrowed
let y: &'static _ = &Y; //~ ERROR temporary value dropped while borrowed
let z: &'static _ = &Z; //~ ERROR temporary value dropped while borrowed
}