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

Associated types should be permitted in impl headers #18757

Closed
carllerche opened this issue Nov 8, 2014 · 4 comments
Closed

Associated types should be permitted in impl headers #18757

carllerche opened this issue Nov 8, 2014 · 4 comments

Comments

@carllerche
Copy link
Member

Code

#![feature(associated_types)]

pub trait Foo {
    type Bar: Sized;

    fn invoke(&self, bar: <Self as Foo>::Bar);
}

pub struct Wrap<F, B> {
    foo: F,
    bar: B,
}

impl<F: Foo> Wrap<F, <F as Foo>::Bar> {
    // Does not compile  ^^
}

pub fn main() {
}

Output

$ rustc at.rs
at.rs:14:22: 14:37 error: this associated type is not allowed in this context
at.rs:14 impl<F: Foo> Wrap<F, <F as Foo>::Bar> {
                              ^~~~~~~~~~~~~~~
error: aborting due to previous error
@nikomatsakis
Copy link
Contributor

While I really want this to work, I think it will be relatively low priority. Once there is an explicit syntax for naming associated types (#18432), it can be worked around relatively easily, and to do this right is quite challenging (resolving <T as Foo>::Bar requires trait resolution; but here we have to do it as part of the impl, so there is a cyclic dependency). Given the existence of a workaround, I'm personally not inclined to hack something up but rather just to wait and fix the general issue.

@nikomatsakis
Copy link
Contributor

These are now permitted but don't, I think, work correctly most of the time.

@nikomatsakis
Copy link
Contributor

PR #20757 more or less fixes this.

@steveklabnik
Copy link
Member

That PR was merged, and this does compile today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants