Skip to content

Commit 4a760c6

Browse files
committed
add regression test for issue 67053
1 parent bc0df79 commit 4a760c6

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// This is a non-regression test for const-qualification of unstable items in libcore
2+
// as explained in issue #67053.
3+
// const-qualification could miss some `const fn`s if they were unstable and the feature
4+
// gate was not enabled in libcore.
5+
6+
#![stable(feature = "core", since = "1.6.0")]
7+
#![feature(const_if_match)]
8+
#![feature(rustc_const_unstable)]
9+
#![feature(staged_api)]
10+
11+
enum Opt<T> {
12+
Some(T),
13+
None,
14+
}
15+
16+
impl<T> Opt<T> {
17+
#[rustc_const_unstable(feature = "foo")]
18+
#[stable(feature = "rust1", since = "1.0.0")]
19+
const fn unwrap_or_else<F: FnOnce() -> T>(self, f: F) -> T {
20+
//~^ ERROR destructors cannot be evaluated at compile-time
21+
//~| ERROR destructors cannot be evaluated at compile-time
22+
match self {
23+
Opt::Some(t) => t,
24+
Opt::None => f(), //~ ERROR E0015
25+
}
26+
}
27+
}
28+
29+
fn main() {}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants
2+
--> $DIR/unstable-const-fn-in-libcore.rs:24:26
3+
|
4+
LL | Opt::None => f(),
5+
| ^^^
6+
7+
error[E0493]: destructors cannot be evaluated at compile-time
8+
--> $DIR/unstable-const-fn-in-libcore.rs:19:53
9+
|
10+
LL | const fn unwrap_or_else<F: FnOnce() -> T>(self, f: F) -> T {
11+
| ^ constant functions cannot evaluate destructors
12+
13+
error[E0493]: destructors cannot be evaluated at compile-time
14+
--> $DIR/unstable-const-fn-in-libcore.rs:19:47
15+
|
16+
LL | const fn unwrap_or_else<F: FnOnce() -> T>(self, f: F) -> T {
17+
| ^^^^ constant functions cannot evaluate destructors
18+
19+
error: aborting due to 3 previous errors
20+
21+
Some errors have detailed explanations: E0015, E0493.
22+
For more information about an error, try `rustc --explain E0015`.

0 commit comments

Comments
 (0)