However, when I tried to compile the code like above in Rust 1.81.0, it compiled successfully.
Since when have impl Trait as an argument type been available as a mutable reference like &mut impl AsMut<[u8]>? Or has this been available since impl Trait was available?
and they can't be ?Sized, because buf is passed by value, and without a known size, the callee has no way of knowing how large argument it's receiving. Fat pointers contain the length, and in Rust if there's no pointer, there's no length.
It’s true that everywhere a dynamically-sized value exists in Rust today, there is a pointer type involved, but that is not a necessary property.
Today, the calling convention on a given platform often specifies that large values are passed as implicitly-created pointers. This implicit pointer could be accompanied by the metadata[1] without any language-level pointer existing.
Even without any pointers, there is no semantic reason Rust can’t use a (metadata, data...) representation if desired.
The compiler even already has unstable/internal support for this under feature(unsized_fn_params) — which is flawed as currently implemented, but demonstrates that it can be done at least in some cases; it just isn't stable and complete enough to offer to users.
Metadata is either a slice length or a vtable pointer containing a size. ↩︎