Skip to content

Bounds on associated types ignored #20979

@bgamari

Description

@bgamari

In,

trait BitIter {
    type Iter: Iterator<Item=bool>;
    pub fn bit_iter(self) -> <Self as BitIter>::Iter;
}

pub fn test_bad<Sym: BitIter>(sym: Sym) {
    let i = sym.bit_iter();
}

pub fn test_good<Sym: BitIter>(sym: Sym)
    where <Sym as BitIter>::Iter: Iterator<Item=bool> {
    let i = sym.bit_iter();
}

pub fn main() {}

test_bad fails to compile, despite the bounds on BitIter::Iter with,

hi.rs:7:17: 7:27 error: type mismatch resolving `<<Sym as BitIter>::Iter as core::iter::Iterator>::Item == bool`: expected associated type, found bool
hi.rs:7     let i = sym.bit_iter();
                        ^~~~~~~~~~

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions