-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Closed
Copy link
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)A-stabilityArea: `#[stable]`, `#[unstable]` etc.Area: `#[stable]`, `#[unstable]` etc.C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Some operations, such as raw pointer comparisons, require unsafe
when inside a const context. To my knowledge, none of these operations have been const-stabilized. Accordingly, the following example fails to compile due to a missing unsafe block.
#![feature(const_compare_raw_pointers)]
#![feature(const_fn)]
const fn unstable(a: *const i32, b: *const i32) -> bool {
a == b
}
However, the check does not run for const_unstable
functions. The following compiles successfully:
#![stable(feature = "foo", since = "1.33.0")]
#![feature(staged_api)]
#![feature(const_compare_raw_pointers)]
#![feature(const_fn)]
#[stable(feature = "foo", since = "1.33.0")]
#[rustc_const_unstable(feature = "const_foo", issue = "none")]
const fn unstable(a: *const i32, b: *const i32) -> bool {
a == b
}
This is an easy problem to fix, but the root cause here is poor naming. Specifically, fn_queries::is_const_fn
should be renamed is_callable_as_const_fn
and is_const_fn_raw
should be is_declared_const_fn
. We have had other issues due to this in the past. cc @rust-lang/wg-const-eval to weigh in on the renaming.
Metadata
Metadata
Assignees
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)A-stabilityArea: `#[stable]`, `#[unstable]` etc.Area: `#[stable]`, `#[unstable]` etc.C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.