RS.CLIPPY.MISNAMED_GETTERS
Getter method returning the wrong field
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: misnamed_getters. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for getter methods that return a field that doesn't correspond to the name of the method, when there is a field's whose name matches that of the method.
Why is this bad?
It is most likely that such a method is a bug caused by a typo or by copy-pasting.
Example
struct A {
a: String,
b: String,
}
impl A {
fn a(&self) -> &str{
&self.b
}
}
Use instead:
struct A {
a: String,
b: String,
}
impl A {
fn a(&self) -> &str{
&self.a
}
}