Bounds issue on trait

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: Rust Playground
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?

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

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

1 Like