- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Closed
Labels
A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-trait-systemArea: Trait systemArea: Trait systemA-type-systemArea: Type systemArea: Type systemC-bugCategory: This is a bug.Category: This is a bug.WG-traits[RETIRED] Working group: Traits[RETIRED] Working group: Traits
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.
minijackson and sorpaas
Metadata
Metadata
Assignees
Labels
A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-trait-systemArea: Trait systemArea: Trait systemA-type-systemArea: Type systemArea: Type systemC-bugCategory: This is a bug.Category: This is a bug.WG-traits[RETIRED] Working group: Traits[RETIRED] Working group: Traits