Comment by lifthrasiir
2 years ago
While that's a valid concern, it is an orthogoal issue as it can be similarly replicated in Rust as well. Rust references always track mutability but we can sidestep that by using `std::borrow::Cow`:
fn compacted<T: ...>(input: Cow<'_, [T]>) -> Cow<'_, [T]> { ... }
Then it is clear that, for example, `compacted(vec![...].into());` as a statement will exhibit the same behavior because `Cow` doesn't have `#[must_use]`. Rust avoids this issue mainly by encouraging explicitly mutable or immutable values by default, and at this point the language should have substantially altered that Go can do the same.
must_use doesn’t have to be on a type, it can be applied to a function