Test that const_precise_live_drops can't be depended upon stably

This commit is contained in:
Dylan MacKenzie 2020-09-16 13:19:45 -07:00
parent 1e1257b8f8
commit abc71677da
3 changed files with 57 additions and 0 deletions

View File

@ -0,0 +1,22 @@
#![stable(feature = "core", since = "1.6.0")]
#![feature(staged_api)]
#![feature(const_precise_live_drops, const_fn)]
enum Either<T, S> {
Left(T),
Right(S),
}
impl<T> Either<T, T> {
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "foo", since = "1.0.0")]
pub const fn unwrap(self) -> T {
//~^ ERROR destructors cannot be evaluated at compile-time
match self {
Self::Left(t) => t,
Self::Right(t) => t,
}
}
}
fn main() {}

View File

@ -0,0 +1,12 @@
error[E0493]: destructors cannot be evaluated at compile-time
--> $DIR/stable-precise-live-drops-in-libcore.rs:13:25
|
LL | pub const fn unwrap(self) -> T {
| ^^^^ constant functions cannot evaluate destructors
...
LL | }
| - value is dropped here
error: aborting due to previous error
For more information about this error, try `rustc --explain E0493`.

View File

@ -0,0 +1,23 @@
// check-pass
#![stable(feature = "core", since = "1.6.0")]
#![feature(staged_api)]
#![feature(const_precise_live_drops)]
enum Either<T, S> {
Left(T),
Right(S),
}
impl<T> Either<T, T> {
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "foo", issue = "none")]
pub const fn unwrap(self) -> T {
match self {
Self::Left(t) => t,
Self::Right(t) => t,
}
}
}
fn main() {}