Skip to content

Bounds don't work on nested associated types #20666

Closed
@japaric

Description

@japaric

STR

#![feature(associated_types)]

use std::slice;

trait Bound {}

impl<'a> Bound for &'a int {}

trait IntoIterator {
    type Iter: Iterator;

    fn into_iter(self) -> Self::Iter;
}

impl<'a, T> IntoIterator for &'a [T; 3] {
    type Iter = slice::Iter<'a, T>;

    fn into_iter(self) -> slice::Iter<'a, T> {
        self.iter()
    }
}

fn foo<X>(x: X) where
    X: IntoIterator,
    <<X as IntoIterator>::Iter as Iterator>::Item: Bound,
{
}

fn bar<T, I, X>(x: X) where
    T: Bound,
    I: Iterator<Item=T>,
    X: IntoIterator<Iter=I>,
{

}

fn main() {
    foo(&[0i, 1, 2]);
    //~^ error: the trait `Bound` is not implemented for the type `<<&[int; 3] as IntoIterator>::Iter as core::iter::Iterator>::Item`
    bar(&[0i, 1, 2]);
}

Version

rustc 1.0.0-dev (340ac040f 2015-01-06 08:25:32 +0000)

foo and bar should be are equivalent, but foo doesn't work.

cc @nikomatsakis

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions