Unintuitive behaviour with passing a reference to trait object to function

Generic type parameters (e.g., <H : Hasher>) have an implicit : Sized bound, and dyn Hasher is not Sized.

On the other hand, H = &'_ mut dyn Hasher is Sized (and Hasher itself too), so you can use a &mut &mut dyn Hasher as your input: Playground


The fact that the Hash trait uses an implicit Sized bound on its generic parameter looks like an oversight / retrocompatibility artifact. I am pretty sure that a modern version of the trait would be using <H : ?Sized + Hasher>

1 Like