Skip to content

Commit 1122404

Browse files
Add qualif smoke tests for const loops
1 parent 99e132d commit 1122404

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

src/test/ui/consts/control-flow/drop-failure.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![feature(const_if_match)]
2+
#![feature(const_loop)]
23

34
// `x` is *not* always moved into the final value may be dropped inside the initializer.
45
const _: Option<Vec<i32>> = {
@@ -32,4 +33,27 @@ const _: Vec<i32> = {
3233
}
3334
};
3435

36+
const _: Option<Vec<i32>> = {
37+
let mut some = Some(Vec::new());
38+
let mut tmp = None;
39+
//~^ ERROR destructors cannot be evaluated at compile-time
40+
41+
let mut i = 0;
42+
while i < 10 {
43+
tmp = some;
44+
some = None;
45+
46+
if i > 100 {
47+
break;
48+
}
49+
50+
some = tmp;
51+
tmp = None;
52+
53+
i += 1;
54+
}
55+
56+
some
57+
};
58+
3559
fn main() {}

src/test/ui/consts/control-flow/drop-success.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// run-pass
22

33
#![feature(const_if_match)]
4+
#![feature(const_loop)]
45

56
// `x` is always moved into the final value and is not dropped inside the initializer.
67
const _: Option<Vec<i32>> = {
@@ -21,4 +22,24 @@ const _: Option<Vec<i32>> = {
2122
}
2223
};
2324

25+
const _: Option<Vec<i32>> = {
26+
let mut some = Some(Vec::new());
27+
let mut tmp = None;
28+
29+
let mut i = 0;
30+
while i < 10 {
31+
tmp = some;
32+
some = None;
33+
34+
// We can never exit the loop with `Some` in `tmp`.
35+
36+
some = tmp;
37+
tmp = None;
38+
39+
i += 1;
40+
}
41+
42+
some
43+
};
44+
2445
fn main() {}

src/test/ui/consts/control-flow/interior-mutability.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// disqualifies it from promotion.
33

44
#![feature(const_if_match)]
5+
#![feature(const_loop)]
56

67
use std::cell::Cell;
78

@@ -21,7 +22,22 @@ const Y: Option<Cell<i32>> = {
2122
y
2223
};
2324

25+
const Z: Option<Cell<i32>> = {
26+
let mut z = None;
27+
let mut i = 0;
28+
while i < 10 {
29+
if i == 8 {
30+
z = Some(Cell::new(4));
31+
}
32+
33+
i += 1;
34+
}
35+
z
36+
};
37+
38+
2439
fn main() {
2540
let x: &'static _ = &X; //~ ERROR temporary value dropped while borrowed
2641
let y: &'static _ = &Y; //~ ERROR temporary value dropped while borrowed
42+
let z: &'static _ = &Z; //~ ERROR temporary value dropped while borrowed
2743
}

0 commit comments

Comments
 (0)