Skip to content

RPITIT with generic const constraint requires implied lifetime bounds to be explicitly specified in impls #138411

Open
@alice-emerson

Description

@alice-emerson

I tried this code:

#![feature(generic_const_exprs)]

trait Trait {}
struct Concrete;
impl Trait for Concrete {}

trait Demo<const N: usize> {
    fn neither() -> Concrete;
    fn bound_only() -> Concrete where [(); N-1]:;
    fn rpit_only() -> impl Trait;
    fn rpit_and_bound() -> impl Trait where [(); N-1]:;
}

impl<'a, T, const N: usize> Demo<N> for &'a T {
    // Compiles fine
    fn neither() -> Concrete { Concrete }
    fn bound_only() -> Concrete where [(); N-1]: { Concrete }
    fn rpit_only() -> impl Trait { Concrete }
    
    // Compile error
    fn rpit_and_bound() -> impl Trait where [(); N-1]: { Concrete }
}

I expected to see this happen: The code compiles without errors

Instead, this happened:

The [(); N-1]: bound in the trait definition is highlighted as an error complaining that T does not outlive 'a, and suggests adding T: 'a to the impl block.

Meta

rustc --version --verbose:

rustc 1.87.0-nightly (665025243 2025-03-11)
binary: rustc
commit-hash: 6650252439d4e03368b305c42a10006e36f1545e
commit-date: 2025-03-11
host: x86_64-unknown-linux-gnu
release: 1.87.0-nightly
LLVM version: 20.1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-generic_const_exprs`#![feature(generic_const_exprs)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-incomplete-featuresThis issue requires the use of incomplete features.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions