Skip to content

Commit 9d398cb

Browse files
committed
prevents len_without_is_empty from yielding positive when len takes
more than just `&self` in non-standard implementations. changelog: Fix [`len_without_is_empty`] false positive when len has a non-standard method signature Fixes #9520
1 parent 96c28d1 commit 9d398cb

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

clippy_lints/src/len_zero.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ impl<'tcx> LateLintPass<'tcx> for LenZero {
135135
if item.ident.name == sym::len;
136136
if let ImplItemKind::Fn(sig, _) = &item.kind;
137137
if sig.decl.implicit_self.has_implicit_self();
138+
if sig.decl.inputs.len() == 1;
138139
if cx.effective_visibilities.is_exported(item.owner_id.def_id);
139140
if matches!(sig.decl.output, FnRetTy::Return(_));
140141
if let Some(imp) = get_parent_as_impl(cx.tcx, item.hir_id());

tests/ui/len_without_is_empty.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,4 +282,17 @@ impl AsyncLen {
282282
}
283283
}
284284

285+
// issue #9520
286+
pub struct NonStandardLenAndIsEmptySignature;
287+
impl NonStandardLenAndIsEmptySignature {
288+
// don't lint
289+
pub fn len(&self, something: usize) -> usize {
290+
something
291+
}
292+
293+
pub fn is_empty(&self, something: usize) -> bool {
294+
something == 0
295+
}
296+
}
297+
285298
fn main() {}

0 commit comments

Comments
 (0)