Bounds issue on trait


#1

One of my experiments with the Frunk crate is to iterate all types of an heterogeneous list as a common ancestor type.

trait Gatherer<'me, Abstraction, Result>
where
    Abstraction: 'me + ?Sized,
    Result: 'me,
{
    // Into<Result> IS NOT USED because it erases the lifetimes during
    // transformation. The closure itself is responsible for properly
    // returning the correct type.
    // This could? allow for borrows within result targetting a specific list item.
    fn gather<F>(&'me self, collector: &'me mut [Option<Result>], closure: F)
    where
        F: for<'collect> Fn(&'me Abstraction, &'collect mut Option<Result>) -> ();

In short: the Gatherer trait takes a reference to the HList, a collector and a closure inspecting each element.
This works so far, but it requires the precondition that collector must be of size at least as big as the HList itself (Self)

I wanted to make this function unsafe and force the correct size through the type system, but then the compiler started to complain (a lot).
I have a reproduction here: https://play.rust-lang.org/?gist=cd8ca583e100eb55628945f93be15aaf&version=stable&mode=release&edition=2015
The compiler recommends me to add various bounds so the types are compatible, but these bounds are already in place. There is something else going on that i don’t understand.

These errors are the same in this exact case AND when i directly use HList::LEN.

Does anyone have any ideas how to get this to compile?


#2

I suppose this is related to the static-array length issues. e.g. https://github.com/rust-lang/rust/issues/52070


#3

Yeah, this is a long-standing issue; I think https://github.com/rust-lang/rust/issues/43408 is the current “active” issue for it.