diff options
| author | Jeremy Stucki <stucki.jeremy@gmail.com> | 2019-08-21 21:19:28 +0200 |
|---|---|---|
| committer | Jeremy Stucki <dev@jeremystucki.ch> | 2020-05-25 21:41:20 +0200 |
| commit | 566377f6272b0a3b9fa65dabe1f39ee82be80d4e (patch) | |
| tree | 728804f468310b60891c9bb724792d57907ca4f9 | |
| parent | 6bd9cd99a3da53bdda4530dde9f737a843de6c91 (diff) | |
| download | rust-566377f6272b0a3b9fa65dabe1f39ee82be80d4e.tar.gz rust-566377f6272b0a3b9fa65dabe1f39ee82be80d4e.zip | |
Ignore calls to 'len'
| -rw-r--r-- | clippy_lints/src/methods/mod.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 32b3b7f7947..c82cf57a4b1 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -1614,6 +1614,21 @@ fn lint_or_fun_call<'a, 'tcx>( or_has_args: bool, span: Span, ) { + if let hir::ExprKind::MethodCall(ref path, _, ref args) = &arg.node { + if path.ident.as_str() == "len" { + let ty = walk_ptrs_ty(cx.tables.expr_ty(&args[0])); + + match ty.sty { + ty::Slice(_) | ty::Array(_, _) => return, + _ => (), + } + + if match_type(cx, ty, &paths::VEC) { + return; + } + } + } + // (path, fn_has_argument, methods, suffix) let know_types: &[(&[_], _, &[_], _)] = &[ (&paths::BTREEMAP_ENTRY, false, &["or_insert"], "with"), |
