2024-10-06 12:59:19 -05:00
|
|
|
//! 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 {
|
2024-11-01 16:19:42 -05:00
|
|
|
unstable_intrinsic::size_of_val(&x);
|
2024-11-02 18:10:24 -05:00
|
|
|
//~^ERROR: unstable library feature `unstable`
|
2024-10-06 12:59:19 -05:00
|
|
|
//~|ERROR: cannot be (indirectly) exposed to stable
|
2024-11-01 16:19:42 -05:00
|
|
|
unstable_intrinsic::min_align_of_val(&x);
|
2024-11-02 18:10:24 -05:00
|
|
|
//~^ERROR: unstable library feature `unstable`
|
2024-10-06 12:59:19 -05:00
|
|
|
//~|ERROR: not yet stable as a const intrinsic
|
|
|
|
|
2024-11-01 16:19:42 -05:00
|
|
|
size_of_val(&x);
|
2024-10-06 12:59:19 -05:00
|
|
|
//~^ERROR: cannot be (indirectly) exposed to stable
|
2024-11-01 16:19:42 -05:00
|
|
|
min_align_of_val(&x);
|
2024-10-06 12:59:19 -05:00
|
|
|
//~^ERROR: cannot use `#[feature(local)]`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-01 16:19:42 -05:00
|
|
|
#[unstable(feature = "local", issue = "42")]
|
|
|
|
#[rustc_intrinsic]
|
2024-11-02 02:49:49 -05:00
|
|
|
#[rustc_intrinsic_must_be_overridden]
|
2024-11-01 16:19:42 -05:00
|
|
|
pub const unsafe fn size_of_val<T>(x: *const T) -> usize { 42 }
|
2024-10-06 12:59:19 -05:00
|
|
|
|
2024-11-01 16:19:42 -05:00
|
|
|
#[unstable(feature = "local", issue = "42")]
|
|
|
|
#[rustc_const_unstable(feature = "local", issue = "42")]
|
|
|
|
#[rustc_intrinsic]
|
2024-11-02 02:49:49 -05:00
|
|
|
#[rustc_intrinsic_must_be_overridden]
|
2024-11-01 16:19:42 -05:00
|
|
|
pub const unsafe fn min_align_of_val<T>(x: *const T) -> usize { 42 }
|
2024-10-06 12:59:19 -05:00
|
|
|
|
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
|
|
|
#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")]
|
|
|
|
#[inline]
|
|
|
|
pub const unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
|
|
|
|
// Const stability attributes are not inherited from parent items.
|
2024-11-01 16:19:42 -05:00
|
|
|
#[rustc_intrinsic]
|
2024-11-02 02:49:49 -05:00
|
|
|
#[rustc_intrinsic_must_be_overridden]
|
2024-11-01 16:19:42 -05:00
|
|
|
const unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
|
|
|
|
unimplemented!()
|
2024-10-06 12:59:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
unsafe { copy(src, dst, count) }
|
2024-11-01 16:19:42 -05:00
|
|
|
//~^ ERROR cannot be (indirectly) exposed to stable
|
2024-10-06 12:59:19 -05:00
|
|
|
}
|
2024-11-02 02:49:49 -05:00
|
|
|
|
|
|
|
// Ensure that a fallback body is recursively-const-checked.
|
|
|
|
mod fallback {
|
|
|
|
#[rustc_intrinsic]
|
|
|
|
const unsafe fn copy<T>(src: *const T, _dst: *mut T, _count: usize) {
|
|
|
|
super::size_of_val(src);
|
|
|
|
//~^ ERROR cannot be (indirectly) exposed to stable
|
|
|
|
}
|
|
|
|
}
|