Hi y'all,
given that the concern here seems to be performance (though, TBH, I doubt this particular case is much of a bottleneck), this seems to be far simpler to address as a compiler optimization - if the compiler can prove there are no other references to a `[]byte`, it can do the conversion cheaply. You need to implement that check anyway, and optimizations are transparent to the user, so the hurdle for them is lower.
The only problem with that is that it would need to happen cross-package. That's where the type-system might help. AFAICT however, if you're willing to change the API anyway, the simpler fix here would be to take an `io.Writer` instead of returning a `[]byte`. The user is then free to pass a `*bytes.Buffer` or a `*strings.Builder`, depending on which of the two they need. And if the wins of this optimization are large enough to justify changing the language (which, again, remains to be proven) they certainly are large enough to justify this slightly less user-friendly API.
So, really, IMO the case for language changes here is pretty weak.