From 1122404be574be1120e8ba55052455c757864241 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Tue, 10 Dec 2019 21:24:46 -0800 Subject: [PATCH] Add qualif smoke tests for const loops --- .../ui/consts/control-flow/drop-failure.rs | 24 +++++++++++++++++++ .../ui/consts/control-flow/drop-success.rs | 21 ++++++++++++++++ .../control-flow/interior-mutability.rs | 16 +++++++++++++ 3 files changed, 61 insertions(+) diff --git a/src/test/ui/consts/control-flow/drop-failure.rs b/src/test/ui/consts/control-flow/drop-failure.rs index c6bea89e6e6..599ebc6243e 100644 --- a/src/test/ui/consts/control-flow/drop-failure.rs +++ b/src/test/ui/consts/control-flow/drop-failure.rs @@ -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> = { @@ -32,4 +33,27 @@ const _: Vec = { } }; +const _: Option> = { + 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() {} diff --git a/src/test/ui/consts/control-flow/drop-success.rs b/src/test/ui/consts/control-flow/drop-success.rs index 92b3f6ec92e..185d6b63996 100644 --- a/src/test/ui/consts/control-flow/drop-success.rs +++ b/src/test/ui/consts/control-flow/drop-success.rs @@ -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> = { @@ -21,4 +22,24 @@ const _: Option> = { } }; +const _: Option> = { + 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() {} diff --git a/src/test/ui/consts/control-flow/interior-mutability.rs b/src/test/ui/consts/control-flow/interior-mutability.rs index fcced75fcb0..d064041134f 100644 --- a/src/test/ui/consts/control-flow/interior-mutability.rs +++ b/src/test/ui/consts/control-flow/interior-mutability.rs @@ -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> = { y }; +const Z: Option> = { + 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 }