Description
I often see rust PRs that mark pure functions as #[must_use]
, which makes sense, as discarding their results will more often than not be in error. As #[must_use]
is now available for user code, we may want to lint functions that should have them.
To make this lintable at all, we need to first define "pure":
A pure function has no mutable argument and does not mutate global state.
Arguments that are mutable: &mut _
, &Atomic*
, &UnsafeCell
, &Cell*
, &RefCell*
, &Mutex<_>
, &RwLock<_>
, &Sender
, &Receiver
Mutating global state can be done via *Assign
ops where self
is static mut
, direct assignment to a static mut
or calling a method on a static mut
that takes &mut self
. For simplicity, it should suffice if we match those operations on anything that is not local to the body (or the args).