From 74977fd4fc9d5b46f1252e4e5ea6740e46337cf0 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 30 Sep 2024 20:49:35 +0200 Subject: [PATCH] add test ensuring we cannot call const-stable unstable functions --- .../auxiliary/unstable_but_const_stable.rs | 14 ++++++ tests/ui/consts/unstable-const-stable.rs | 14 ++++++ tests/ui/consts/unstable-const-stable.stderr | 43 +++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 tests/ui/consts/auxiliary/unstable_but_const_stable.rs create mode 100644 tests/ui/consts/unstable-const-stable.rs create mode 100644 tests/ui/consts/unstable-const-stable.stderr diff --git a/tests/ui/consts/auxiliary/unstable_but_const_stable.rs b/tests/ui/consts/auxiliary/unstable_but_const_stable.rs new file mode 100644 index 0000000000000..137a06958699e --- /dev/null +++ b/tests/ui/consts/auxiliary/unstable_but_const_stable.rs @@ -0,0 +1,14 @@ +#![feature(staged_api, rustc_attrs, intrinsics)] +#![stable(since="1.0.0", feature = "stable")] + +extern "rust-intrinsic" { + #[unstable(feature = "unstable", issue = "42")] + #[rustc_const_stable(feature = "stable", since = "1.0.0")] + #[rustc_nounwind] + pub fn write_bytes(dst: *mut T, val: u8, count: usize); +} + +#[unstable(feature = "unstable", issue = "42")] +#[rustc_const_stable(feature = "stable", since = "1.0.0")] +pub const fn some_unstable_fn() {} + diff --git a/tests/ui/consts/unstable-const-stable.rs b/tests/ui/consts/unstable-const-stable.rs new file mode 100644 index 0000000000000..f69e8d0efe593 --- /dev/null +++ b/tests/ui/consts/unstable-const-stable.rs @@ -0,0 +1,14 @@ +//@ aux-build:unstable_but_const_stable.rs + +extern crate unstable_but_const_stable; +use unstable_but_const_stable::*; + +fn main() { + some_unstable_fn(); //~ERROR use of unstable library feature + unsafe { write_bytes(4 as *mut u8, 0, 0) }; //~ERROR use of unstable library feature +} + +const fn const_main() { + some_unstable_fn(); //~ERROR use of unstable library feature + unsafe { write_bytes(4 as *mut u8, 0, 0) }; //~ERROR use of unstable library feature +} diff --git a/tests/ui/consts/unstable-const-stable.stderr b/tests/ui/consts/unstable-const-stable.stderr new file mode 100644 index 0000000000000..c4ffbbb60db3c --- /dev/null +++ b/tests/ui/consts/unstable-const-stable.stderr @@ -0,0 +1,43 @@ +error[E0658]: use of unstable library feature 'unstable' + --> $DIR/unstable-const-stable.rs:7:5 + | +LL | some_unstable_fn(); + | ^^^^^^^^^^^^^^^^ + | + = note: see issue #42 for more information + = help: add `#![feature(unstable)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: use of unstable library feature 'unstable' + --> $DIR/unstable-const-stable.rs:8:14 + | +LL | unsafe { write_bytes(4 as *mut u8, 0, 0) }; + | ^^^^^^^^^^^ + | + = note: see issue #42 for more information + = help: add `#![feature(unstable)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: use of unstable library feature 'unstable' + --> $DIR/unstable-const-stable.rs:12:5 + | +LL | some_unstable_fn(); + | ^^^^^^^^^^^^^^^^ + | + = note: see issue #42 for more information + = help: add `#![feature(unstable)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: use of unstable library feature 'unstable' + --> $DIR/unstable-const-stable.rs:13:14 + | +LL | unsafe { write_bytes(4 as *mut u8, 0, 0) }; + | ^^^^^^^^^^^ + | + = note: see issue #42 for more information + = help: add `#![feature(unstable)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0658`.