Skip to content

Commit b099406

Browse files
committed
Make KNOW_TYPES static
1 parent 040d0ca commit b099406

File tree

1 file changed

+10
-10
lines changed
  • clippy_lints/src/methods

1 file changed

+10
-10
lines changed

clippy_lints/src/methods/mod.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,6 +1803,14 @@ fn lint_or_fun_call<'tcx>(
18031803
or_has_args: bool,
18041804
span: Span,
18051805
) {
1806+
// (path, fn_has_argument, methods, suffix)
1807+
static KNOW_TYPES: [(&[&str], bool, &[&str], &str); 4] = [
1808+
(&paths::BTREEMAP_ENTRY, false, &["or_insert"], "with"),
1809+
(&paths::HASHMAP_ENTRY, false, &["or_insert"], "with"),
1810+
(&paths::OPTION, false, &["map_or", "ok_or", "or", "unwrap_or"], "else"),
1811+
(&paths::RESULT, true, &["or", "unwrap_or"], "else"),
1812+
];
1813+
18061814
if let hir::ExprKind::MethodCall(ref path, _, ref args, _) = &arg.kind {
18071815
if path.ident.as_str() == "len" {
18081816
let ty = cx.typeck_results().expr_ty(&args[0]).peel_refs();
@@ -1818,24 +1826,16 @@ fn lint_or_fun_call<'tcx>(
18181826
}
18191827
}
18201828

1821-
// (path, fn_has_argument, methods, suffix)
1822-
let know_types: &[(&[_], _, &[_], _)] = &[
1823-
(&paths::BTREEMAP_ENTRY, false, &["or_insert"], "with"),
1824-
(&paths::HASHMAP_ENTRY, false, &["or_insert"], "with"),
1825-
(&paths::OPTION, false, &["map_or", "ok_or", "or", "unwrap_or"], "else"),
1826-
(&paths::RESULT, true, &["or", "unwrap_or"], "else"),
1827-
];
1828-
18291829
if_chain! {
1830-
if know_types.iter().any(|k| k.2.contains(&name));
1830+
if KNOW_TYPES.iter().any(|k| k.2.contains(&name));
18311831

18321832
if is_lazyness_candidate(cx, arg);
18331833
if !contains_return(&arg);
18341834

18351835
let self_ty = cx.typeck_results().expr_ty(self_expr);
18361836

18371837
if let Some(&(_, fn_has_arguments, poss, suffix)) =
1838-
know_types.iter().find(|&&i| match_type(cx, self_ty, i.0));
1838+
KNOW_TYPES.iter().find(|&&i| match_type(cx, self_ty, i.0));
18391839

18401840
if poss.contains(&name);
18411841

0 commit comments

Comments
 (0)