Skip to content

Return value from const_trait_impl did not promote to constant? #69574

Open
@crlf0710

Description

@crlf0710

I tried this code:

#![feature(const_trait_impl)]
#![feature(const_fn)]
use std::marker::PhantomData;

trait ConstDefault {
    fn const_default() -> Self;
}

impl const ConstDefault for u8 {
    fn const_default() -> Self { 0 }
}

const fn foo() -> &'static u8 {
    &u8::const_default()
}

I expected to see this happen: This should pass compile if i'm not mistaken.

Instead, this happened: The const value promotion did not happen.

cc @ecstatic-morse @oli-obk

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)A-const-propArea: Constant propagationA-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.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