Associated type "inherits" sizedness of `Self`?

Hmm… let’s take some type equality trait, and then we can start with

trait Foo {
    type Bar: ?Sized;
}

and add a second associated type equal to the first, and bounded by Sized … i.e. like this:

pub trait TypeIsEqual {
    type To: ?Sized;
}
impl<T: ?Sized> TypeIsEqual for T {
    type To = Self;
}

trait Foo {
    type Bar: ?Sized;
    type BarSized: Sized + TypeIsEqual<To = Self::Bar>
    where
        Self: Sized;
}

(I know the BarSized: Sized bound is redundant, but it’s more explicit this way)

Now the hackiness level of this is quite high. (In fact it’s already nontrivial to implement this at all for some non-Sized type.) This trait definition certainly not very comfortable to work with, in fact depending on what your exact use-case is like, it may probably not be usable at all.

On that matter, feel free to actually do share more about your use-case, then we could discuss the trickeries that could make this approach actually work.