From 5fa0e07cdf5e6798a71ff252f14a2713699ae99d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Tue, 1 Nov 2022 21:36:18 +0100 Subject: [PATCH] Document missname_getters --- clippy_lints/src/declared_lints.rs | 2 +- clippy_lints/src/functions/mod.rs | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index 0c9ae6380d8..bccf8425968 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -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, diff --git a/clippy_lints/src/functions/mod.rs b/clippy_lints/src/functions/mod.rs index 726df02444f..87792899b25 100644 --- a/clippy_lints/src/functions/mod.rs +++ b/clippy_lints/src/functions/mod.rs @@ -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)]