forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test checking that we don't accidentally expose const-unstable in…
…trinsics
- Loading branch information
Showing
3 changed files
with
278 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#![feature(staged_api, rustc_attrs, intrinsics)] | ||
#![stable(since="1.0.0", feature = "stable")] | ||
|
||
#[stable(since="1.0.0", feature = "stable")] | ||
pub mod old_way { | ||
extern "rust-intrinsic" { | ||
#[unstable(feature = "unstable", issue = "42")] | ||
pub fn size_of_val<T>(x: *const T) -> usize; | ||
|
||
#[unstable(feature = "unstable", issue = "42")] | ||
#[rustc_const_unstable(feature = "unstable", issue = "42")] | ||
pub fn min_align_of_val<T>(x: *const T) -> usize; | ||
} | ||
} | ||
|
||
#[stable(since="1.0.0", feature = "stable")] | ||
pub mod new_way { | ||
#[unstable(feature = "unstable", issue = "42")] | ||
#[rustc_intrinsic] | ||
pub const unsafe fn size_of_val<T>(x: *const T) -> usize { 42 } | ||
|
||
#[unstable(feature = "unstable", issue = "42")] | ||
#[rustc_const_unstable(feature = "unstable", issue = "42")] | ||
#[rustc_intrinsic] | ||
pub const unsafe fn min_align_of_val<T>(x: *const T) -> usize { 42 } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
//! Ensure that unstable intrinsics can actually not be called, | ||
//! neither within a crate nor cross-crate. | ||
//@ aux-build:unstable_intrinsic.rs | ||
#![feature(staged_api, rustc_attrs, intrinsics)] | ||
#![stable(since="1.0.0", feature = "stable")] | ||
#![feature(local)] | ||
|
||
extern crate unstable_intrinsic; | ||
|
||
fn main() { | ||
const_main(); | ||
} | ||
|
||
const fn const_main() { | ||
let x = 42; | ||
unsafe { | ||
unstable_intrinsic::old_way::size_of_val(&x); | ||
//~^ERROR: unstable library feature 'unstable' | ||
//~|ERROR: cannot call non-const fn | ||
unstable_intrinsic::old_way::min_align_of_val(&x); | ||
//~^ERROR: unstable library feature 'unstable' | ||
//~|ERROR: not yet stable as a const fn | ||
//~|ERROR: cannot use `#[feature(unstable)]` | ||
unstable_intrinsic::new_way::size_of_val(&x); | ||
//~^ERROR: unstable library feature 'unstable' | ||
//~|ERROR: not yet stable as a const fn | ||
//~|ERROR: cannot use `#[feature(unstable)]` | ||
unstable_intrinsic::new_way::min_align_of_val(&x); | ||
//~^ERROR: unstable library feature 'unstable' | ||
//~|ERROR: not yet stable as a const fn | ||
//~|ERROR: cannot use `#[feature(unstable)]` | ||
|
||
old_way::size_of_val(&x); | ||
//~^ERROR: cannot call non-const fn | ||
old_way::min_align_of_val(&x); | ||
//~^ERROR: cannot use `#[feature(local)]` | ||
new_way::size_of_val(&x); | ||
//~^ERROR: cannot use `#[feature(local)]` | ||
new_way::min_align_of_val(&x); | ||
//~^ERROR: cannot use `#[feature(local)]` | ||
} | ||
} | ||
|
||
#[stable(since="1.0.0", feature = "stable")] | ||
pub mod old_way { | ||
extern "rust-intrinsic" { | ||
#[unstable(feature = "local", issue = "42")] | ||
pub fn size_of_val<T>(x: *const T) -> usize; | ||
|
||
#[unstable(feature = "local", issue = "42")] | ||
#[rustc_const_unstable(feature = "local", issue = "42")] | ||
pub fn min_align_of_val<T>(x: *const T) -> usize; | ||
} | ||
} | ||
|
||
#[stable(since="1.0.0", feature = "stable")] | ||
pub mod new_way { | ||
#[unstable(feature = "local", issue = "42")] | ||
#[rustc_intrinsic] | ||
pub const unsafe fn size_of_val<T>(x: *const T) -> usize { 42 } | ||
|
||
#[unstable(feature = "local", issue = "42")] | ||
#[rustc_const_unstable(feature = "local", issue = "42")] | ||
#[rustc_intrinsic] | ||
pub const unsafe fn min_align_of_val<T>(x: *const T) -> usize { 42 } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
error[E0658]: use of unstable library feature 'unstable' | ||
--> $DIR/const-unstable-intrinsic.rs:17:9 | ||
| | ||
LL | unstable_intrinsic::old_way::size_of_val(&x); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: see issue #42 <https://github.com/rust-lang/rust/issues/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/const-unstable-intrinsic.rs:20:9 | ||
| | ||
LL | unstable_intrinsic::old_way::min_align_of_val(&x); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: see issue #42 <https://github.com/rust-lang/rust/issues/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/const-unstable-intrinsic.rs:24:9 | ||
| | ||
LL | unstable_intrinsic::new_way::size_of_val(&x); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: see issue #42 <https://github.com/rust-lang/rust/issues/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/const-unstable-intrinsic.rs:28:9 | ||
| | ||
LL | unstable_intrinsic::new_way::min_align_of_val(&x); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: see issue #42 <https://github.com/rust-lang/rust/issues/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[E0015]: cannot call non-const fn `unstable_intrinsic::old_way::size_of_val::<i32>` in constant functions | ||
--> $DIR/const-unstable-intrinsic.rs:17:9 | ||
| | ||
LL | unstable_intrinsic::old_way::size_of_val(&x); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants | ||
|
||
error: const function that might be (indirectly) exposed to stable cannot use `#[feature(unstable)]` | ||
--> $DIR/const-unstable-intrinsic.rs:20:9 | ||
| | ||
LL | unstable_intrinsic::old_way::min_align_of_val(&x); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: if the function is not (yet) meant to be exposed to stable, add `#[rustc_const_unstable]` (this what you probably want to do) | ||
| | ||
LL + #[rustc_const_unstable(feature = "...", issue = "...")] | ||
LL | const fn const_main() { | ||
| | ||
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval) | ||
| | ||
LL + #[rustc_allow_const_fn_unstable(unstable)] | ||
LL | const fn const_main() { | ||
| | ||
|
||
error: `unstable_intrinsic::old_way::min_align_of_val` is not yet stable as a const fn | ||
--> $DIR/const-unstable-intrinsic.rs:20:9 | ||
| | ||
LL | unstable_intrinsic::old_way::min_align_of_val(&x); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: add `#![feature(unstable)]` to the crate attributes to enable | ||
|
||
error: const function that might be (indirectly) exposed to stable cannot use `#[feature(unstable)]` | ||
--> $DIR/const-unstable-intrinsic.rs:24:9 | ||
| | ||
LL | unstable_intrinsic::new_way::size_of_val(&x); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: if the function is not (yet) meant to be exposed to stable, add `#[rustc_const_unstable]` (this what you probably want to do) | ||
| | ||
LL + #[rustc_const_unstable(feature = "...", issue = "...")] | ||
LL | const fn const_main() { | ||
| | ||
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval) | ||
| | ||
LL + #[rustc_allow_const_fn_unstable(unstable)] | ||
LL | const fn const_main() { | ||
| | ||
|
||
error: `unstable_intrinsic::new_way::size_of_val` is not yet stable as a const fn | ||
--> $DIR/const-unstable-intrinsic.rs:24:9 | ||
| | ||
LL | unstable_intrinsic::new_way::size_of_val(&x); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: add `#![feature(unstable)]` to the crate attributes to enable | ||
|
||
error: const function that might be (indirectly) exposed to stable cannot use `#[feature(unstable)]` | ||
--> $DIR/const-unstable-intrinsic.rs:28:9 | ||
| | ||
LL | unstable_intrinsic::new_way::min_align_of_val(&x); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: if the function is not (yet) meant to be exposed to stable, add `#[rustc_const_unstable]` (this what you probably want to do) | ||
| | ||
LL + #[rustc_const_unstable(feature = "...", issue = "...")] | ||
LL | const fn const_main() { | ||
| | ||
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval) | ||
| | ||
LL + #[rustc_allow_const_fn_unstable(unstable)] | ||
LL | const fn const_main() { | ||
| | ||
|
||
error: `unstable_intrinsic::new_way::min_align_of_val` is not yet stable as a const fn | ||
--> $DIR/const-unstable-intrinsic.rs:28:9 | ||
| | ||
LL | unstable_intrinsic::new_way::min_align_of_val(&x); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: add `#![feature(unstable)]` to the crate attributes to enable | ||
|
||
error[E0015]: cannot call non-const fn `old_way::size_of_val::<i32>` in constant functions | ||
--> $DIR/const-unstable-intrinsic.rs:33:9 | ||
| | ||
LL | old_way::size_of_val(&x); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants | ||
|
||
error: const function that might be (indirectly) exposed to stable cannot use `#[feature(local)]` | ||
--> $DIR/const-unstable-intrinsic.rs:35:9 | ||
| | ||
LL | old_way::min_align_of_val(&x); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: if the function is not (yet) meant to be exposed to stable, add `#[rustc_const_unstable]` (this what you probably want to do) | ||
| | ||
LL + #[rustc_const_unstable(feature = "...", issue = "...")] | ||
LL | const fn const_main() { | ||
| | ||
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval) | ||
| | ||
LL + #[rustc_allow_const_fn_unstable(local)] | ||
LL | const fn const_main() { | ||
| | ||
|
||
error: const function that might be (indirectly) exposed to stable cannot use `#[feature(local)]` | ||
--> $DIR/const-unstable-intrinsic.rs:37:9 | ||
| | ||
LL | new_way::size_of_val(&x); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: if the function is not (yet) meant to be exposed to stable, add `#[rustc_const_unstable]` (this what you probably want to do) | ||
| | ||
LL + #[rustc_const_unstable(feature = "...", issue = "...")] | ||
LL | const fn const_main() { | ||
| | ||
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval) | ||
| | ||
LL + #[rustc_allow_const_fn_unstable(local)] | ||
LL | const fn const_main() { | ||
| | ||
|
||
error: const function that might be (indirectly) exposed to stable cannot use `#[feature(local)]` | ||
--> $DIR/const-unstable-intrinsic.rs:39:9 | ||
| | ||
LL | new_way::min_align_of_val(&x); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: if the function is not (yet) meant to be exposed to stable, add `#[rustc_const_unstable]` (this what you probably want to do) | ||
| | ||
LL + #[rustc_const_unstable(feature = "...", issue = "...")] | ||
LL | const fn const_main() { | ||
| | ||
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval) | ||
| | ||
LL + #[rustc_allow_const_fn_unstable(local)] | ||
LL | const fn const_main() { | ||
| | ||
|
||
error: aborting due to 15 previous errors | ||
|
||
Some errors have detailed explanations: E0015, E0658. | ||
For more information about an error, try `rustc --explain E0015`. |