RPITIT with generic const constraint requires implied lifetime bounds to be explicitly specified in impls
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by compiling the reported nightly Rust reproducer with generic_const_exprs and inspect the lifetime diagnostic around the rpit_and_bound method and its [(); N-1]: bound. Compare the four trait and impl methods to isolate why only the combined case fails; done means the example compiles without requiring an explicit T: 'a bound.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100