Skip to content

Commit 5fa0e07

Browse files
committed
Document missname_getters
1 parent 81d4590 commit 5fa0e07

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

clippy_lints/src/declared_lints.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,14 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
177177
crate::from_raw_with_void_ptr::FROM_RAW_WITH_VOID_PTR_INFO,
178178
crate::from_str_radix_10::FROM_STR_RADIX_10_INFO,
179179
crate::functions::DOUBLE_MUST_USE_INFO,
180+
crate::functions::MISSNAMED_GETTERS_INFO,
180181
crate::functions::MUST_USE_CANDIDATE_INFO,
181182
crate::functions::MUST_USE_UNIT_INFO,
182183
crate::functions::NOT_UNSAFE_PTR_ARG_DEREF_INFO,
183184
crate::functions::RESULT_LARGE_ERR_INFO,
184185
crate::functions::RESULT_UNIT_ERR_INFO,
185186
crate::functions::TOO_MANY_ARGUMENTS_INFO,
186187
crate::functions::TOO_MANY_LINES_INFO,
187-
crate::functions::MISSNAMED_GETTERS_INFO,
188188
crate::future_not_send::FUTURE_NOT_SEND_INFO,
189189
crate::if_let_mutex::IF_LET_MUTEX_INFO,
190190
crate::if_not_else::IF_NOT_ELSE_INFO,

clippy_lints/src/functions/mod.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,21 +263,38 @@ declare_clippy_lint! {
263263

264264
declare_clippy_lint! {
265265
/// ### What it does
266+
/// Checks for getter methods that return a field that doesn't correspond
267+
/// to the name of the method, when there is a field's whose name matches that of the method.
266268
///
267269
/// ### Why is this bad?
270+
/// It is most likely that such a method is a bug caused by a typo or by copy-pasting.
268271
///
269272
/// ### Example
270273
/// ```rust
274+
/// struct A {
275+
/// a: String,
276+
/// b: String,
277+
/// }
278+
///
279+
/// impl A {
280+
/// fn a(&self) -> &str{
281+
/// self.b
282+
/// }
283+
/// }
271284
/// // example code where clippy issues a warning
272285
/// ```
273286
/// Use instead:
274287
/// ```rust
275-
/// // example code which does not raise clippy warning
288+
/// impl A {
289+
/// fn a(&self) -> &str{
290+
/// self.a
291+
/// }
292+
/// }
276293
/// ```
277294
#[clippy::version = "1.66.0"]
278295
pub MISSNAMED_GETTERS,
279296
suspicious,
280-
"default lint description"
297+
"getter method returning the wrong field"
281298
}
282299

283300
#[derive(Copy, Clone)]

0 commit comments

Comments
 (0)