Skip to content

Commit 7650307

Browse files
committed
add test ensuring we cannot call const-stable unstable functions
1 parent 5c3ceb3 commit 7650307

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![feature(staged_api, rustc_attrs, intrinsics)]
2+
#![stable(since="1.0.0", feature = "stable")]
3+
4+
extern "rust-intrinsic" {
5+
#[unstable(feature = "unstable", issue = "42")]
6+
#[rustc_const_stable(feature = "stable", since = "1.0.0")]
7+
#[rustc_nounwind]
8+
pub fn write_bytes<T>(dst: *mut T, val: u8, count: usize);
9+
}
10+
11+
#[unstable(feature = "unstable", issue = "42")]
12+
#[rustc_const_stable(feature = "stable", since = "1.0.0")]
13+
pub const fn some_unstable_fn() {}

Diff for: tests/ui/consts/unstable-const-stable.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//@ aux-build:unstable_but_const_stable.rs
2+
3+
extern crate unstable_but_const_stable;
4+
use unstable_but_const_stable::*;
5+
6+
fn main() {
7+
some_unstable_fn(); //~ERROR use of unstable library feature
8+
unsafe { write_bytes(4 as *mut u8, 0, 0) }; //~ERROR use of unstable library feature
9+
}
10+
11+
const fn const_main() {
12+
some_unstable_fn(); //~ERROR use of unstable library feature
13+
unsafe { write_bytes(4 as *mut u8, 0, 0) }; //~ERROR use of unstable library feature
14+
}

Diff for: tests/ui/consts/unstable-const-stable.stderr

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
error[E0658]: use of unstable library feature 'unstable'
2+
--> $DIR/unstable-const-stable.rs:7:5
3+
|
4+
LL | some_unstable_fn();
5+
| ^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #42 <https://github.com/rust-lang/rust/issues/42> for more information
8+
= help: add `#![feature(unstable)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
11+
error[E0658]: use of unstable library feature 'unstable'
12+
--> $DIR/unstable-const-stable.rs:8:14
13+
|
14+
LL | unsafe { write_bytes(4 as *mut u8, 0, 0) };
15+
| ^^^^^^^^^^^
16+
|
17+
= note: see issue #42 <https://github.com/rust-lang/rust/issues/42> for more information
18+
= help: add `#![feature(unstable)]` to the crate attributes to enable
19+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
20+
21+
error[E0658]: use of unstable library feature 'unstable'
22+
--> $DIR/unstable-const-stable.rs:12:5
23+
|
24+
LL | some_unstable_fn();
25+
| ^^^^^^^^^^^^^^^^
26+
|
27+
= note: see issue #42 <https://github.com/rust-lang/rust/issues/42> for more information
28+
= help: add `#![feature(unstable)]` to the crate attributes to enable
29+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
30+
31+
error[E0658]: use of unstable library feature 'unstable'
32+
--> $DIR/unstable-const-stable.rs:13:14
33+
|
34+
LL | unsafe { write_bytes(4 as *mut u8, 0, 0) };
35+
| ^^^^^^^^^^^
36+
|
37+
= note: see issue #42 <https://github.com/rust-lang/rust/issues/42> for more information
38+
= help: add `#![feature(unstable)]` to the crate attributes to enable
39+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
40+
41+
error: aborting due to 4 previous errors
42+
43+
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)