Skip to content

Commit 2dcf7db

Browse files
Add tests for const_precise_live_drops
1 parent 9e2ee32 commit 2dcf7db

File tree

5 files changed

+49
-9
lines changed

5 files changed

+49
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0493]: destructors cannot be evaluated at compile-time
2+
--> $DIR/drop-fail.rs:10:9
3+
|
4+
LL | let x = Some(Vec::new());
5+
| ^ constants cannot evaluate destructors
6+
7+
error[E0493]: destructors cannot be evaluated at compile-time
8+
--> $DIR/drop-fail.rs:41:9
9+
|
10+
LL | let mut tmp = None;
11+
| ^^^^^^^ constants cannot evaluate destructors
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0493`.

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

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
// revisions: stock precise
2+
13
#![feature(const_if_match)]
24
#![feature(const_loop)]
5+
#![cfg_attr(precise, feature(const_precise_live_drops))]
36

4-
// `x` is *not* always moved into the final value may be dropped inside the initializer.
7+
// `x` is *not* always moved into the final value and may be dropped inside the initializer.
58
const _: Option<Vec<i32>> = {
69
let y: Option<Vec<i32>> = None;
710
let x = Some(Vec::new());
8-
//~^ ERROR destructors cannot be evaluated at compile-time
11+
//[stock,precise]~^ ERROR destructors cannot be evaluated at compile-time
912

1013
if true {
1114
x
@@ -18,15 +21,15 @@ const _: Option<Vec<i32>> = {
1821
// existing analysis.
1922
const _: Vec<i32> = {
2023
let vec_tuple = (Vec::new(),);
21-
//~^ ERROR destructors cannot be evaluated at compile-time
24+
//[stock]~^ ERROR destructors cannot be evaluated at compile-time
2225

2326
vec_tuple.0
2427
};
2528

2629
// This applies to single-field enum variants as well.
2730
const _: Vec<i32> = {
2831
let x: Result<_, Vec<i32>> = Ok(Vec::new());
29-
//~^ ERROR destructors cannot be evaluated at compile-time
32+
//[stock]~^ ERROR destructors cannot be evaluated at compile-time
3033

3134
match x {
3235
Ok(x) | Err(x) => x,
@@ -36,7 +39,7 @@ const _: Vec<i32> = {
3639
const _: Option<Vec<i32>> = {
3740
let mut some = Some(Vec::new());
3841
let mut tmp = None;
39-
//~^ ERROR destructors cannot be evaluated at compile-time
42+
//[stock,precise]~^ ERROR destructors cannot be evaluated at compile-time
4043

4144
let mut i = 0;
4245
while i < 10 {

src/test/ui/consts/control-flow/drop-failure.stderr renamed to src/test/ui/consts/control-flow/drop-fail.stock.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
error[E0493]: destructors cannot be evaluated at compile-time
2-
--> $DIR/drop-failure.rs:7:9
2+
--> $DIR/drop-fail.rs:10:9
33
|
44
LL | let x = Some(Vec::new());
55
| ^ constants cannot evaluate destructors
66

77
error[E0493]: destructors cannot be evaluated at compile-time
8-
--> $DIR/drop-failure.rs:20:9
8+
--> $DIR/drop-fail.rs:23:9
99
|
1010
LL | let vec_tuple = (Vec::new(),);
1111
| ^^^^^^^^^ constants cannot evaluate destructors
1212

1313
error[E0493]: destructors cannot be evaluated at compile-time
14-
--> $DIR/drop-failure.rs:28:9
14+
--> $DIR/drop-fail.rs:31:9
1515
|
1616
LL | let x: Result<_, Vec<i32>> = Ok(Vec::new());
1717
| ^ constants cannot evaluate destructors
1818

1919
error[E0493]: destructors cannot be evaluated at compile-time
20-
--> $DIR/drop-failure.rs:38:9
20+
--> $DIR/drop-fail.rs:41:9
2121
|
2222
LL | let mut tmp = None;
2323
| ^^^^^^^ constants cannot evaluate destructors

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

+2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// run-pass
2+
// revisions: stock precise
23

34
#![feature(const_if_match)]
45
#![feature(const_loop)]
6+
#![cfg_attr(precise, feature(const_precise_live_drops))]
57

68
// `x` is always moved into the final value and is not dropped inside the initializer.
79
const _: Option<Vec<i32>> = {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// run-pass
2+
// gate-test-const_precise_live_drops
3+
4+
#![feature(const_if_match)]
5+
#![feature(const_loop)]
6+
#![feature(const_precise_live_drops)]
7+
8+
const _: Vec<i32> = {
9+
let vec_tuple = (Vec::new(),);
10+
vec_tuple.0
11+
};
12+
13+
const _: Vec<i32> = {
14+
let x: Result<_, Vec<i32>> = Ok(Vec::new());
15+
match x {
16+
Ok(x) | Err(x) => x,
17+
}
18+
};
19+
20+
fn main() {}

0 commit comments

Comments
 (0)