Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bounds don't work on nested associated types #20666

Closed
japaric opened this issue Jan 6, 2015 · 2 comments · Fixed by #20757
Closed

Bounds don't work on nested associated types #20666

japaric opened this issue Jan 6, 2015 · 2 comments · Fixed by #20757
Labels
A-associated-items Area: Associated items (types, constants & functions)

Comments

@japaric
Copy link
Member

japaric commented Jan 6, 2015

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

@huonw huonw added the A-associated-items Area: Associated items (types, constants & functions) label Jan 7, 2015
@nikomatsakis
Copy link
Contributor

I think the problem is that we normalize top-down not bottom-up.

@nikomatsakis
Copy link
Contributor

Fix pending in #20757.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants