Skip to content

Initializers of stable constants can call const unstable functions #68743

Open
@ecstatic-morse

Description

@ecstatic-morse

Crates using staged_api are forbidden from calling const unstable functions from stable const functions. However, this restriction does not extend to the initializers of consts or statics. Although unlikely, this could allow for "backdoor stabilization" of various const-eval features. For example, the following would lock in the current implementation of const_if_match.

#![stable(feature = "bar", since = "1.34")]

#![feature(staged_api)]
#![feature(const_if_match)]
#![feature(foo)]

#[rustc_const_unstable(feature = "foo", issue = "0")]
const fn foo() -> i32 {
    if true { 0 } else { 1 }
}

#[stable(feature = "bar", since = "1.34")]
pub const BAR: i32 = foo();

If BAR were a const fn instead of a const, that example would be rejected.

#[rustc_const_stable(feature = "bar", since = "1.34")]
pub const fn bar() -> i32 {
    foo()
}

cc @rust-lang/wg-const-eval

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)A-stabilityArea: `#[stable]`, `#[unstable]` etc.C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions