Rust-GCC / Rust-GCC/gccrs

Handle list of const intrinsics properly for 1.49

Open
#3,039 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug HIR
Dominant language
C++
Stars
2.9k
Forks
231
Avg merge
19h 55m
Merged PRs (30d)
67

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the reported E0015 failure using the test.rs snippet in the issue. Read the rustc_const_unstable guidance and related issue #2999 to understand how const intrinsics are represented. Done means the core 1.49 example compiles without errors and the list of const intrinsics is handled correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.