Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle list of const intrinsics properly for 1.49 #3039

Open
CohenArthur opened this issue May 24, 2024 · 0 comments
Open

Handle list of const intrinsics properly for 1.49 #3039

CohenArthur opened this issue May 24, 2024 · 0 comments

Comments

@CohenArthur
Copy link
Member

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 asconst’ 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])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant