If you have a trait with a lifetime, you can quite simply and expressively do:
trait WithLifetime<'a> {}
trait Erased: for<'a> WithLifetime<'a> {}
And if you have one with an actual type you can go with:
trait NamesType<T> {}
trait AsAssociated: NamesType<Self::T> {
type T;
}
But trying to do similarly with a const generic is just.... broken:
#![feature(generic_const_exprs)]
trait NamesConst<const N: usize> {}
trait SelectConst: NamesConst<{ Self::N }>
where
[(); { Self::N }]: ,
{
const N: usize;
}
Hooray! All that fussing about with nightly and adding weird bounds just to end up with a cycle detected in compilation...
[playground]
I know const generics are one of the targets for Rust 2024, but is there any way to work around
this currently? Or, am I just going to have to carry around an extra const N: usize
generic parameter for a while longer?