Skip to content

Commit

Permalink
Add tests for const_precise_live_drops
Browse files Browse the repository at this point in the history
  • Loading branch information
ecstatic-morse committed Jun 13, 2020
1 parent 9e2ee32 commit 2dcf7db
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 9 deletions.
15 changes: 15 additions & 0 deletions src/test/ui/consts/control-flow/drop-fail.precise.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error[E0493]: destructors cannot be evaluated at compile-time
--> $DIR/drop-fail.rs:10:9
|
LL | let x = Some(Vec::new());
| ^ constants cannot evaluate destructors

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

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0493`.
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
// revisions: stock precise

#![feature(const_if_match)]
#![feature(const_loop)]
#![cfg_attr(precise, feature(const_precise_live_drops))]

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

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

vec_tuple.0
};

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

match x {
Ok(x) | Err(x) => x,
Expand All @@ -36,7 +39,7 @@ 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
//[stock,precise]~^ ERROR destructors cannot be evaluated at compile-time

let mut i = 0;
while i < 10 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
error[E0493]: destructors cannot be evaluated at compile-time
--> $DIR/drop-failure.rs:7:9
--> $DIR/drop-fail.rs:10:9
|
LL | let x = Some(Vec::new());
| ^ constants cannot evaluate destructors

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

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

error[E0493]: destructors cannot be evaluated at compile-time
--> $DIR/drop-failure.rs:38:9
--> $DIR/drop-fail.rs:41:9
|
LL | let mut tmp = None;
| ^^^^^^^ constants cannot evaluate destructors
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// run-pass
// revisions: stock precise

#![feature(const_if_match)]
#![feature(const_loop)]
#![cfg_attr(precise, feature(const_precise_live_drops))]

// `x` is always moved into the final value and is not dropped inside the initializer.
const _: Option<Vec<i32>> = {
Expand Down
20 changes: 20 additions & 0 deletions src/test/ui/consts/control-flow/drop-precise.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// run-pass
// gate-test-const_precise_live_drops

#![feature(const_if_match)]
#![feature(const_loop)]
#![feature(const_precise_live_drops)]

const _: Vec<i32> = {
let vec_tuple = (Vec::new(),);
vec_tuple.0
};

const _: Vec<i32> = {
let x: Result<_, Vec<i32>> = Ok(Vec::new());
match x {
Ok(x) | Err(x) => x,
}
};

fn main() {}

0 comments on commit 2dcf7db

Please sign in to comment.