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

Not able to infer equality in some special cases #16

Open
bvssvni opened this Issue Jul 26, 2015 · 3 comments

Comments

Projects
None yet
1 participant
@bvssvni
Copy link
Member

bvssvni commented Jul 26, 2015

Example:

 error: type mismatch resolving `<<F as device::backend::Associated>::Backend as device::backend::Backend>::Resources == <F as device::backend::OfBackend>::Resources`:
 expected trait `device::backend::Backend`,
    found trait `device::backend::OfBackend`

@bvssvni bvssvni added the bug label Jul 26, 2015

@bvssvni

This comment has been minimized.

Copy link
Member Author

bvssvni commented Jul 26, 2015

A similar error can be replicated in the_simpsons example:

fn foo<T: HasChildren>(a: T) -> T::Father { a.cutest().father() }
examples/the_simpsons.rs:59:45: 59:64 error: mismatched types:
 expected `<T as OfBackend>::Father`,
    found `<<T as OfBackend>::Kids as OfBackend>::Father`
(expected type parameter,
    found associated type) [E0308]
examples/the_simpsons.rs:59 fn foo<T: HasChildren>(a: T) -> T::Father { a.cutest().father() }
                                                                        ^~~~~~~~~~~~~~~~~~~
examples/the_simpsons.rs:59:45: 59:64 help: run `rustc --explain E0308` to see a detailed explanation
error: aborting due to previous error
Could not compile `backend`.
@bvssvni

This comment has been minimized.

Copy link
Member Author

bvssvni commented Oct 2, 2015

One solution could be to generate methods on the backend that converts the type safely.

@bvssvni

This comment has been minimized.

Copy link
Member Author

bvssvni commented Jan 1, 2016

It is possible to create an unsafe trait like this:

pub unsafe trait Cast<T, U> {
    fn cast(a: T) -> U  {
        unsafe { ::std::mem::transmute_copy(&a) }
    }
}

unsafe impl<T> Cast<<<T as OfBackend>::Kids as OfBackend>::Father, T::Father> for T
    where T: OfBackend
{}
fn foo<T: HasChildren>(a: T) -> T::Father { T::cast(a.cutest().father()) }

However, this does not work for T::cast(a.cutest().father().cutest().father()).

The impls will conflict, preventing one from supporting more than one cast method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.