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

Constraints on nested associated types do not work #20543

Closed
carllerche opened this issue Jan 4, 2015 · 5 comments
Closed

Constraints on nested associated types do not work #20543

carllerche opened this issue Jan 4, 2015 · 5 comments
Labels
A-associated-items Area: Associated items (types, constants & functions)

Comments

@carllerche
Copy link
Member

#![feature(associated_types)]

pub trait Foo {
    type T;
}

pub trait Bar {
    type F: Foo;
}

pub fn stuff<B: Bar<F::T=()>>(b: B) {
}

pub fn main() {
}
@jroesch
Copy link
Member

jroesch commented Jan 5, 2015

I played with a variation on this to see if the actual constraint checking is possible but it looks like this doesn't work either:

#![feature(associated_types)]

pub trait Foo {
    type T;
}

pub trait Bar {
    type F: Foo;
}

trait TyEq<A> {}
impl<A> TyEq<A> for A {}

pub fn stuff<B: Bar>(b: B) where B::F::T : TyEq<()> {
}

pub fn main() {
}

This works though:

#![feature(associated_types)]

pub trait Foo {
    type T;
}

pub trait Bar {
    type F: Foo;
}

pub trait TyEq<A> {}
impl<A> TyEq<A> for A {}

pub fn stuff<B: Bar>(b: B) where <B::F as Foo>::T : TyEq<()> {
}

pub fn main() {
}

At first glance it appears to be a parsing bug to me, gonna spend a few minutes seeing if I can chase it down.

@nikomatsakis
Copy link
Contributor

This isn't really expected to work yet. You can typically introduce a new type variable to work around it.

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

Semi-dup of #20666

@nrc
Copy link
Member

nrc commented Jan 7, 2015

Parse error, for reference:

foo.rs:11:25: 11:26 Fatal: expected one of `(`, `+`, `,`, `::`, or `>`, found `=`
foo.rs:11 pub fn stuff<B: Bar<F::T=()>>(b: B) {

@nikomatsakis
Copy link
Contributor

So it's not clear that this particular syntax (Foo<X::Y=...>) is desired. Since the semantic problems with nested associated types are covered in #20666, we're going to close this issue as a dup for now.

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

No branches or pull requests

5 participants