Open
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