Skip to content

Whether [const] RPIT is const depends on generic parameters #145202

@theemathas

Description

@theemathas

I'm not sure if this is correct behavior, but I find it to be rather weird, and I can't find any mention of this behavior in the RFC.

#![feature(const_trait_impl)]

const trait Trait {}

struct YesConst;
impl const Trait for YesConst {}
struct NotConst;
impl Trait for NotConst {}

fn require_const_trait(_: impl const Trait) {}

const fn not_generic() -> impl [const] Trait {
    YesConst
}

const fn generic<T: [const] Trait>() -> impl [const] Trait {
    YesConst
}

fn works() {
    require_const_trait(not_generic());
}

fn also_works() {
    require_const_trait(generic::<YesConst>());
}

fn fails() {
    require_const_trait(generic::<NotConst>());
}
error[E0277]: the trait bound `NotConst: const Trait` is not satisfied
  --> src/main.rs:29:25
   |
29 |     require_const_trait(generic::<NotConst>());
   |     ------------------- ^^^^^^^^^^^^^^^^^^^^^
   |     |
   |     required by a bound introduced by this call
   |
note: required by a bound in `require_const_trait`
  --> src/main.rs:10:32
   |
10 | fn require_const_trait(_: impl const Trait) {}
   |                                ^^^^^^^^^^^ required by this bound in `require_const_trait`

For more information about this error, try `rustc --explain E0277`.

@rustbot labels +F-const_trait_impl

Meta

Reproducible on the playground with version 1.91.0-nightly (2025-08-09 ca77504943887037504c)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.F-const_trait_impl`#![feature(const_trait_impl)]`PG-const-traitsProject group: Const traitsT-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