Closed
Description
The following code fails to compile:
use std::iter::once;
trait TokenSpec {
type Ident;
}
impl TokenSpec for String {
type Ident = String;
}
struct Expr<I> {
ident: I,
}
type Input = Expr<<String as TokenSpec>::Ident>;
fn foo() -> impl Iterator<Item = Input> {
once(Expr { ident: "my_string".to_string() })
}
fn main() {
let v: Vec<_> = foo().collect();
println!("{:?}", v);
}
I get this error message:
error[E0271]: type mismatch resolving `<std::iter::Once<Expr<std::string::String>> as std::iter::Iterator>::Item == Expr<<std::string::String as TokenSpec>::Ident>`
--> src/main.rs:17:13
|
17 | fn foo() -> impl Iterator<Item = Input> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `std::string::String`, found associated type
|
= note: expected type `Expr<std::string::String>`
found type `Expr<<std::string::String as TokenSpec>::Ident>`
= note: the return type of a function must have a statically known size
I think this case should work, since <String as TokenSpec>::Ident
can be resolved at type checking time.