Clippy lints / Restriction
Clippy lint · Restriction · checked with Clippy 0.1.99
clippy::renamed_function_params: renamed function parameter of trait impl
What it meansLints when the name of function parameters from trait impl is different than its default implementation. It is in the restriction group and off by default.
What you see
warning: renamed function parameter of trait impl --> main.rs:6:18 | 6 | fn eq(&self, b: &Self) -> bool { | ^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/stable/index.html#renamed_function_params = note: requested on the command line with `-W clippy::renamed-function-params` help: consider using the default name | 6 - fn eq(&self, b: &Self) -> bool { 6 + fn eq(&self, other: &Self) -> bool { |
Real output of Clippy 0.1.99 (Rust 1.99) on the example below. Names and line numbers in yours will differ.
Does it matter?
Using the default name for parameters of a trait method is more consistent.
Lints that forbid language features for specific codebases (no unwrap, no indexing...). Off by default; pick them one by one, never the whole group.
How to fix it
Clippy does not fix this one automatically. Change the code by hand:
Flagged
struct A(u32);
impl PartialEq for A {
fn eq(&self, b: &Self) -> bool {
self.0 == b.0
}
}
Write this instead
struct A(u32);
impl PartialEq for A {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}
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]
renamed_function_params = "warn"In code
#![warn(clippy::renamed_function_params)]One run
cargo clippy -- -W clippy::renamed-function-paramsThe [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
Lints when the name of function parameters from trait impl is different than its default implementation.
Why restrict this?
Using the default name for parameters of a trait method is more consistent.
Example
struct A(u32);
impl PartialEq for A {
fn eq(&self, b: &Self) -> bool {
self.0 == b.0
}
}
Use instead:
struct A(u32);
impl PartialEq for A {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}
Configuration
allow-renamed-params-for: List of trait paths to ignore when checking renamed function parameters.
Example
allow-renamed-params-for = [ "std::convert::From" ]
Noteworthy
-
By default, the following traits are ignored:
From,TryFrom,FromStr -
".."can be used as part of the list to indicate that the configured values should be appended to the default configuration of Clippy. By default, any configuration will replace the default value.(default:
["core::convert::From", "core::convert::TryFrom", "core::str::FromStr"])
From the Clippy lint list (0.1.99), part of the Rust project, MIT or Apache-2.0. Official entry.
Related lints
- unwrap_usedChecks for .unwrap() or .unwrap_err() calls on Results and .unwrap() call on Options
- module_name_repetitionsDetects public item names that are prefixed or suffixed by the containing public module’s name
- expect_usedChecks for .expect() or .expect_err() calls on Results and .expect() call on Options
- redundant_test_prefixChecks for test functions (functions annotated with #[test]) that are prefixed with test_ which is redundant
- redundant_type_annotationsredundant type annotation
- ref_patternsusage of ref pattern
- rest_pat_in_fully_bound_structsChecks for unnecessary ‘..’ pattern binding on struct when all fields are explicitly matched
- rest_pattern_accessible_fieldstruct destructuring with rest (`..`)
- return_and_thenuse the `?` operator instead of an `and_then` call
All 847 Clippy lints · Rust compiler errors · Cargo.toml checker
Up next
Related lintclippy::unwrap_usedChecks for .unwrap() or .unwrap_err() calls on Results and .unwrap() call on OptionsRead it next →Did this answer your question?