RS.CLIPPY.SINGLE_CALL_FN
Checks for functions that are only used once
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: single_call_fn. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for functions that are only used once. Does not lint tests.
Why restrict this?
If a function is only used once (perhaps because it used to be used more widely), then the code could be simplified by moving that function's code into its caller.
However, there are reasons not to do this everywhere:
- Splitting a large function into multiple parts often improves readability by giving names to its parts.
- A function's signature might serve a necessary purpose, such as constraining the type of a closure passed to it.
- Generic functions might call non-generic functions to reduce duplication in the produced machine code.
If this lint is used, prepare to #[allow] it a lot.
Example
pub fn a<T>(t: &T)
where
T: AsRef<str>,
{
a_inner(t.as_ref())
}
fn a_inner(t: &str) {
/* snip */
}
Use instead:
pub fn a<T>(t: &T)
where
T: AsRef<str>,
{
let t = t.as_ref();
/* snip */
}
Configuration
-
avoid-breaking-exported-api: Suppress lints whenever the suggested change would cause breakage for other crates.(default:
true)