Handle list of const intrinsics properly for 1.49
CohenArthur opened this issue · comments
I tried this code:
#![feature(intrinsics)]
mod intrinsics {
extern "rust-intrinsic" {
fn unreachable() -> !;
}
}
#[inline]
#[stable(feature = "unreachable", since = "1.27.0")]
// #[rustc_const_unstable(feature = "const_unreachable_unchecked", issue = "53188")]
pub const unsafe fn unreachable_unchecked() -> ! {
// SAFETY: the safety contract for `intrinsics::unreachable` must
// be upheld by the caller.
unsafe { intrinsics::unreachable() }
}
I expected to see this happen: no errors. This is taken from core
1.49.
Instead, this happened:
test.rs:15:14: error: only functions marked as ‘const’ are allowed to be called from constant contexts [E0015]
15 | unsafe { intrinsics::unreachable() }
| ^~~~~~~~~~
The way this is handled is in collaboration with #2999, as per the doc:
Furthermore this attribute is needed to mark an intrinsic as const fn, because there's no way to add const to functions in extern blocks for now.
https://rustc-dev-guide.rust-lang.org/stability.html#rustc_const_unstable
(and similarly for #[rustc_const_stable]
)