Closed
Description
I tried this code:
// build-pass
#![crate_type = "lib"]
#![feature(generic_const_exprs)]
#![allow(incomplete_features)]
trait MyIterator {
type Output;
}
trait Foo {
const ABC: usize;
}
struct IteratorStruct<const N: usize>{
}
struct BarStruct<const N: usize> {
data: [usize; N]
}
impl<const N: usize> MyIterator for IteratorStruct<N> {
type Output = BarStruct<N>;
}
fn test<T: Foo>() -> impl MyIterator<Output = BarStruct<{T::ABC}>> where [(); {T::ABC}]: Sized {
IteratorStruct::<{T::ABC}>{}
}
This code should compile normally.
Instead, this happened:
error[E0599]: no associated item named `ABC` found for type parameter `T` in the current scope
--> /home/neo/rust/src/test/ui/const-generics/generic_const_exprs/my_test.rs:28:61
|
LL | fn test<T: Foo>() -> impl MyIterator<Output = BarStruct<{T::ABC}>> {
| - ^^^ associated item not found in `T`
| |
| associated item `ABC` not found for this type parameter
|
= help: items from traits can only be used if the type parameter is bounded by the trait
error: aborting due to previous error
For more information about this error, try `rustc --explain E0599`.
In the test
function, T was already bounded by the Foo
trait which does have an associated item named ABC
. However, Rust complains that no associated item named ABC
was found for T
.
Meta
rustc --version --verbose
:
rustc 1.64.0-nightly (62b272d25 2022-07-21)
binary: rustc
commit-hash: 62b272d25c5bb8b6bb8ac73797d82b8b9a1eabda
commit-date: 2022-07-21
host: x86_64-pc-windows-msvc
release: 1.64.0-nightly
LLVM version: 14.0.6