Skip to content

New lint: pure functions without #[must_use] #4526

Closed
@llogiq

Description

@llogiq

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lintsE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions