Skip to content

Commit

Permalink
Test that const_precise_live_drops can't be depended upon stably
Browse files Browse the repository at this point in the history
  • Loading branch information
ecstatic-morse committed Sep 16, 2020
1 parent 1e1257b commit abc7167
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/test/ui/consts/stable-precise-live-drops-in-libcore.rs
Original file line number Diff line number Diff line change
@@ -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() {}
12 changes: 12 additions & 0 deletions src/test/ui/consts/stable-precise-live-drops-in-libcore.stderr
Original file line number Diff line number Diff line change
@@ -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`.
23 changes: 23 additions & 0 deletions src/test/ui/consts/unstable-precise-live-drops-in-libcore.rs
Original file line number Diff line number Diff line change
@@ -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() {}

0 comments on commit abc7167

Please sign in to comment.