Clippy lints / Pedantic
Clippy lint · Pedantic · checked with Clippy 0.1.99
clippy::must_use_candidate: Checks for public functions that have no #[must_use] attribute, but return something not already marked must-use, have no mutable arg and mutate no statics
What it meansChecks for public functions that have no #[must_use] attribute, but return something not already marked must-use, have no mutable arg and mutate no statics. It is in the pedantic group and off by default.
Does it matter?
Not bad at all, this lint just shows places where you could add the attribute.
Stricter lints with some false positives. Off by default; opt in with clippy::pedantic.
How to fix it
Clippy can fix this one for you: run cargo clippy --fix (add --allow-dirty if you have uncommitted changes). Review the diff before you commit.
Flagged
// this could be annotated with `#[must_use]`.
pub fn id<T>(t: T) -> T { t }
Turn it off, or on
It is off by default. To use it, set it to warn or deny:
Whole crate (Cargo.toml)
[lints.clippy]
must_use_candidate = "warn"In code
#![warn(clippy::must_use_candidate)]One run
cargo clippy -- -W clippy::must-use-candidateThe [lints] table needs Rust 1.74 or newer. In a workspace, put it under [workspace.lints.clippy] and add [lints] workspace = true to each member.
Clippy's own documentation
What it does
Checks for public functions that have no
#[must_use] attribute, but return something not already marked
must-use, have no mutable arg and mutate no statics.
Why is this bad?
Not bad at all, this lint just shows places where you could add the attribute.
Known problems
The lint only checks the arguments for mutable
types without looking if they are actually changed. On the other hand,
it also ignores a broad range of potentially interesting side effects,
because we cannot decide whether the programmer intends the function to
be called for the side effect or the result. Expect many false
positives. At least we don’t lint if the result type is unit or already
#[must_use].
Examples
// this could be annotated with `#[must_use]`.
pub fn id<T>(t: T) -> T { t }
From the Clippy lint list (0.1.99), part of the Rust project, MIT or Apache-2.0. Official entry.
Related lints
- too_many_linesChecks for functions with a large amount of lines
- missing_errors_docChecks the doc comments of publicly visible functions that return a Result type and warns if there is no # Errors section
- uninlined_format_argsDetect when a variable is not inlined in a format string, and suggests to inline it
- missing_fields_in_debugmanual `Debug` impl does not include all fields
- missing_panics_docChecks the doc comments of publicly visible functions that may panic and warns if there is no # Panics section
- mut_mutmultiple successive mutable borrows
- naive_bytecountChecks for naive byte counts
- needless_bitwise_booluse of bitwise operator instead of lazy operator between booleans
All 847 Clippy lints · Rust compiler errors · Cargo.toml checker
Up next
Related lintclippy::too_many_linesChecks for functions with a large amount of linesRead it next →Did this answer your question?