Document missname_getters

This commit is contained in:
Sosthène Guédon 2022-11-01 21:36:18 +01:00
parent 81d4590834
commit 5fa0e07cdf
2 changed files with 20 additions and 3 deletions

View file

@ -177,6 +177,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
crate::from_raw_with_void_ptr::FROM_RAW_WITH_VOID_PTR_INFO,
crate::from_str_radix_10::FROM_STR_RADIX_10_INFO,
crate::functions::DOUBLE_MUST_USE_INFO,
crate::functions::MISSNAMED_GETTERS_INFO,
crate::functions::MUST_USE_CANDIDATE_INFO,
crate::functions::MUST_USE_UNIT_INFO,
crate::functions::NOT_UNSAFE_PTR_ARG_DEREF_INFO,
@ -184,7 +185,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
crate::functions::RESULT_UNIT_ERR_INFO,
crate::functions::TOO_MANY_ARGUMENTS_INFO,
crate::functions::TOO_MANY_LINES_INFO,
crate::functions::MISSNAMED_GETTERS_INFO,
crate::future_not_send::FUTURE_NOT_SEND_INFO,
crate::if_let_mutex::IF_LET_MUTEX_INFO,
crate::if_not_else::IF_NOT_ELSE_INFO,

View file

@ -263,21 +263,38 @@ declare_clippy_lint! {
declare_clippy_lint! {
/// ### 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
/// ```rust
/// struct A {
/// a: String,
/// b: String,
/// }
///
/// impl A {
/// fn a(&self) -> &str{
/// self.b
/// }
/// }
/// // example code where clippy issues a warning
/// ```
/// Use instead:
/// ```rust
/// // example code which does not raise clippy warning
/// impl A {
/// fn a(&self) -> &str{
/// self.a
/// }
/// }
/// ```
#[clippy::version = "1.66.0"]
pub MISSNAMED_GETTERS,
suspicious,
"default lint description"
"getter method returning the wrong field"
}
#[derive(Copy, Clone)]