I was recently caught by surprise when I tried to use
f64::round() to mutate the receiver:
…of course, what I should have written was:
value = value.round();
This was admittedly a “dumb” mistake, but I was surprised that
round() isn’t marked
#[must_use], so I didn’t get a warning.
Even so, this seems like something Clippy could catch, but currently, it doesn’t. For functions where all of the arguments are by-shared-reference or by-copy, and a value is returned, it seems likely to be a bug if the value is ignored.
Does treating such “pure” functions1 as automatically
#[must_use] seem like a good idea for a lint? If so, should I just go ahead and try to implement it in Clippy and submit it as a pull request?
1 I realize that Rust does not have a formal definition of “pure” functions, and that there’s not really a standard definition that could be easily applied. My suggestion for this lint is to ignore I/O and simply use mutability to determine whether a function is “pure”.