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

Problem using function traits with associated types #20763

Closed
ghost opened this issue Jan 8, 2015 · 4 comments
Closed

Problem using function traits with associated types #20763

ghost opened this issue Jan 8, 2015 · 4 comments
Labels
A-associated-items Area: Associated items such as associated types and consts.

Comments

@ghost
Copy link

ghost commented Jan 8, 2015

Here's a small example that one might expect to work but doesn't:

trait T0 { type O; }

struct S<A>(A);
impl<A> T0 for S<A> { type O = A; }

trait T1: T0 {
    // this looks okay but as we see below, `f` is unusable
    fn m0<F: Fn(<Self as T0>::O) -> bool>(self, f: F) -> bool;
}

// // complains about the bounds on F here not being required by the trait
// impl<A> T1 for S<A> {
//     fn m0<F: Fn(A) -> bool>(self, f: F) -> bool { f(self.0) }
// }

// // complains about mismatched types: <S<A> as T0>::O vs. A
// impl<A> T1 for S<A>
// {
//     fn m0<F: Fn(<Self as T0>::O) -> bool>(self, f: F) -> bool { f(self.0) }
// }
@ghost
Copy link
Author

ghost commented Jan 8, 2015

Interestingly, this example does work if you move the bound on F to a where clause:

trait T1: T0 {
    fn m0<F>(self, f: F) -> bool where F: Fn(<Self as T0>::O) -> bool;
}

impl<A> T1 for S<A> {
    fn m0<F>(self, f: F) -> bool where F: Fn(A) -> bool { f(self.0) }
}

@jroesch
Copy link
Member

jroesch commented Jan 8, 2015

@darinmorrison I would expect this to be another sad consequence of handling the bounds placed on type parameters differently then the ones placed in where clauses. @nikomatsakis is helping me close down #20020 which should ideally fix this bug.

@kmcallister kmcallister added the A-associated-items Area: Associated items such as associated types and consts. label Jan 9, 2015
nikomatsakis added a commit to nikomatsakis/rust that referenced this issue Jan 16, 2015
@nikomatsakis
Copy link
Contributor

This seems to work now.

@ghost
Copy link
Author

ghost commented Jan 16, 2015

Awesome, thanks!

@ghost ghost closed this as completed Jan 16, 2015
This issue was closed.
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 such as associated types and consts.
Projects
None yet
Development

No branches or pull requests

3 participants