Closed
Description
#![feature(generic_const_exprs)]
#![allow(incomplete_features)]
struct Num<const N: usize>;
trait NumT {
const VALUE: usize;
}
impl<const N: usize> NumT for Num<N> {
const VALUE: usize = N;
}
struct Foo<'a, N: NumT>(&'a [u32; N::VALUE]) where [(); N::VALUE]:;
trait Bar {
type Size: NumT;
fn bar<'a>(foo: &Foo<'a, Self::Size>) where [(); Self::Size::VALUE]: {
todo!();
}
}
trait Baz<'a> {
type Size: NumT;
fn baz(foo: &Foo<'a, Self::Size>) where [(); Self::Size::VALUE]: {
todo!();
}
}
results in
error: unconstrained generic constant
--> src/lib.rs:27:17
|
27 | fn baz(foo: &Foo<'a, Self::Size>) where [(); Self::Size::VALUE]: {
| ^^^^^^^^^^^^^^^^^^^^
|
= help: try adding a `where` bound using this expression: `where [(); N::VALUE]:`
note: required by a bound in `Foo`
--> src/lib.rs:14:57
|
14 | struct Foo<'a, N: NumT>(&'a [u32; N::VALUE]) where [(); N::VALUE]:;
| ^^^^^^^^ required by this bound in `Foo`
but should compile.
I assume that the error is caused by this structural comparison here
rust/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs
Lines 767 to 769 in d017d59
We probably want to erase lifetimes at some earlier point, probably during the construction of the AbstractConst
s.