Skip to content

HKL issues with deep associated types. #34142

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

Closed
pierzchalski opened this issue Jun 7, 2016 · 1 comment
Closed

HKL issues with deep associated types. #34142

pierzchalski opened this issue Jun 7, 2016 · 1 comment

Comments

@pierzchalski
Copy link
Contributor

Using HKL and associated types, one can write constraints that should be accepted which the compiler rejects (mostly using the IntoIterator: IntoIter: Iterator: IteratorWithSomeProperty hierarchy).

'Motivating' example here and a minimal one here. The intermediate trait is required to show the error.

To reiterate what's in the comments of the first example, consider the following trait and function:

trait Tr {}
impl<A> Tr for Vec<A> {}

fn fancy_constraints<A, T: Tr>(t: T)
  where for<'a> &'a T: IntoIterator,
        for<'a> <&'a T as IntoIterator>::IntoIter: ExactSizeIterator,
{} 

Does Vec<A> satisfy these constraints? &'a Vec<A> has an IntoIterator implementation via Deref<Target=[A]> (this indirection isn't the issue: we can make a newtype wrapper around Vec<A> which directly implements IntoIterator and still exhibits the problem).

We have <&'a Vec<A> as IntoIterator>::IntoIter == Iter<'a, A>, and Iter<'a, A>: ExactSizeIterator>, so this should satisfy the constraints given in fancy_constraints above. Instead, we get the following error message:

error: the trait bound `for<'a> <&'a _ as std::iter::IntoIterator>::IntoIter: std::iter::ExactSizeIterator` is not satisfied [--explain E0277]
  --> <anon>:13:5
13 |>     fancy_constraints(vec![0u8]);
   |>     ^^^^^^^^^^^^^^^^^
help: the following implementations were found:
help:   <&'a mut I as std::iter::ExactSizeIterator>
note: required by `fancy_constraints`

The help message is somewhat confusing (I couldn't find the implementation it mentions, but I didn't look very hard), and I couldn't find a way to use it to fix the problem.

@Mark-Simulacrum
Copy link
Member

The example given compiles with only unused code warnings today, so closing.

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

2 participants