'#[must_use]' not being the default on functions goes against "Rust has the safest defaults" principle
As a long-time C++ user, I am surprised that Rust makes the same (IMHO) mistake as C++17's [[nodiscard]] attribute. It should be the default on functions (and probably also types, but I haven't thought deeply about that yet), and there should be a #[discardable] attribute instead.
I have done some research and I have found some very old topics discussing this issue, but the counterarguments were in my opinion unconvincing.
Hear me out:
Most functions returning a value, regardless of whether they have side effects, should have their return value used in some way.
Some functions that return a value and have side effects might be correctly used without inspecting the return value (e.g. partition algorithm that returns the partition point -- sometimes you just want to partition and you don't care where the partition point ends up being).
It is beneficial for the compiler to warn when the return value of a function is unused, because in most cases that is a bug.
Therefore, as a responsible programmer, I should put
#[must_use]everywhere except in places where I intentionally decide that discarding a return value is not a bug.
The problem with the current solution is that, like with C++'s [[nodiscard]], the code becomes noisy due to having the wrong default. There's also a chance of forgetting to place #[must_use] on a function whose return value shouldn't be discarded, which can lead to real bugs.
As a thought experiment, imagine if instead of mut we had C++'s const-- you would have to say let const all over the place as immutability is a better default than mutability.
C++ is screwed because it doesn't have something like Rust's editions (my P1881 epochs proposal did not fly in the ISO Committee), so we are forced to use [[nodiscard]] or figure out guidelines on when to use it or not. This increases cognitive overhead or the noise in our codebases.
Rust can fix this issue with editions. We can say that in the next edition, #[must_use] is the default on every function, and that you can opt-out of this behavior by using the #[discardable] attribute (name subject to bikeshedding).
Is this something that the community agrees on? If not, I would like to convince you, or be convinced that I am wrong.
If there is consensus in the community, is there a formal proposal for this anywhere? If not, I would be happy to write one with the assistance of someone more experienced with Rust.