Skip to content

Treat const fn like fn for promotion. #75586

Closed
@RalfJung

Description

@RalfJung

rust-lang/const-eval#19 gives many arguments for why we should not promote const fn calls. However, we currently do promote const fn calls in const fn, even though that has all the same problems. This fails to compile, but really we shouldn't make this a hard error:

#![allow(unconditional_panic, const_err)]

const fn foo() { [()][42] }
pub const fn do_something(b: bool) -> i32 {
    if b {
        let _x = &foo();
    }
    13
}

This does not just apply to const fn calls; all promotion inside const fn should be treated like inside fn.

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, ...)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