From 81904a413eb1d90d64e2450f075e38d7e0cf1c00 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Wed, 14 Jul 2021 16:17:04 -0500 Subject: [PATCH] Remove refs from pat slices --- clippy_lints/src/manual_unwrap_or.rs | 4 ++-- clippy_lints/src/matches.rs | 2 +- clippy_lints/src/option_if_let_else.rs | 2 +- clippy_lints/src/pattern_type_mismatch.rs | 2 +- clippy_utils/src/lib.rs | 18 +++++++++--------- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/clippy_lints/src/manual_unwrap_or.rs b/clippy_lints/src/manual_unwrap_or.rs index 18038dd781943..9d8d77cf8f089 100644 --- a/clippy_lints/src/manual_unwrap_or.rs +++ b/clippy_lints/src/manual_unwrap_or.rs @@ -61,13 +61,13 @@ fn lint_manual_unwrap_or<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { if let Some((idx, or_arm)) = arms.iter().enumerate().find(|(_, arm)| { match arm.pat.kind { PatKind::Path(ref qpath) => is_lang_ctor(cx, qpath, OptionNone), - PatKind::TupleStruct(ref qpath, &[pat], _) => + PatKind::TupleStruct(ref qpath, [pat], _) => matches!(pat.kind, PatKind::Wild) && is_lang_ctor(cx, qpath, ResultErr), _ => false, } }); let unwrap_arm = &arms[1 - idx]; - if let PatKind::TupleStruct(ref qpath, &[unwrap_pat], _) = unwrap_arm.pat.kind; + if let PatKind::TupleStruct(ref qpath, [unwrap_pat], _) = unwrap_arm.pat.kind; if is_lang_ctor(cx, qpath, OptionSome) || is_lang_ctor(cx, qpath, ResultOk); if let PatKind::Binding(_, binding_hir_id, ..) = unwrap_pat.kind; if path_to_local_id(unwrap_arm.body, binding_hir_id); diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index 986469a2b698c..6d5ce3373f79d 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -625,7 +625,7 @@ impl<'tcx> LateLintPass<'tcx> for Matches { if let PatKind::TupleStruct( QPath::Resolved(None, variant_name), args, _) = arms[0].pat.kind; if args.len() == 1; - if let PatKind::Binding(_, arg, ..) = strip_pat_refs(args[0]).kind; + if let PatKind::Binding(_, arg, ..) = strip_pat_refs(&args[0]).kind; let body = remove_blocks(arms[0].body); if path_to_local_id(body, arg); diff --git a/clippy_lints/src/option_if_let_else.rs b/clippy_lints/src/option_if_let_else.rs index b6af4175edfda..b2be35bdddb38 100644 --- a/clippy_lints/src/option_if_let_else.rs +++ b/clippy_lints/src/option_if_let_else.rs @@ -132,7 +132,7 @@ fn detect_option_if_let_else<'tcx>( if !is_else_clause(cx.tcx, expr); if arms.len() == 2; if !is_result_ok(cx, cond_expr); // Don't lint on Result::ok because a different lint does it already - if let PatKind::TupleStruct(struct_qpath, &[inner_pat], _) = &arms[0].pat.kind; + if let PatKind::TupleStruct(struct_qpath, [inner_pat], _) = &arms[0].pat.kind; if is_lang_ctor(cx, struct_qpath, OptionSome); if let PatKind::Binding(bind_annotation, _, id, _) = &inner_pat.kind; if !contains_return_break_continue_macro(arms[0].body); diff --git a/clippy_lints/src/pattern_type_mismatch.rs b/clippy_lints/src/pattern_type_mismatch.rs index 9bab783998aa5..ea4065d371b81 100644 --- a/clippy_lints/src/pattern_type_mismatch.rs +++ b/clippy_lints/src/pattern_type_mismatch.rs @@ -258,7 +258,7 @@ fn get_variant<'a>(adt_def: &'a AdtDef, qpath: &QPath<'_>) -> Option<&'a Variant fn find_first_mismatch_in_tuple<'tcx, I>( cx: &LateContext<'tcx>, - pats: &[&Pat<'_>], + pats: &[Pat<'_>], ty_iter_src: I, ) -> Option<(Span, Mutability, Level)> where diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 6db221ab0fdfd..4f0a9f442ed9f 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -255,7 +255,7 @@ pub fn in_macro(span: Span) -> bool { } /// Checks if given pattern is a wildcard (`_`) -pub fn is_wild<'tcx>(pat: &impl std::ops::Deref>) -> bool { +pub fn is_wild(pat: &Pat<'_>) -> bool { matches!(pat.kind, PatKind::Wild) } @@ -1023,8 +1023,8 @@ pub fn is_refutable(cx: &LateContext<'_>, pat: &Pat<'_>) -> bool { ) } - fn are_refutable<'a, I: Iterator>>(cx: &LateContext<'_>, mut i: I) -> bool { - i.any(|pat| is_refutable(cx, pat)) + fn are_refutable<'a, I: IntoIterator>>(cx: &LateContext<'_>, i: I) -> bool { + i.into_iter().any(|pat| is_refutable(cx, pat)) } match pat.kind { @@ -1035,23 +1035,23 @@ pub fn is_refutable(cx: &LateContext<'_>, pat: &Pat<'_>) -> bool { PatKind::Path(ref qpath) => is_enum_variant(cx, qpath, pat.hir_id), PatKind::Or(pats) => { // TODO: should be the honest check, that pats is exhaustive set - are_refutable(cx, pats.iter().map(|pat| &**pat)) + are_refutable(cx, pats) }, - PatKind::Tuple(pats, _) => are_refutable(cx, pats.iter().map(|pat| &**pat)), + PatKind::Tuple(pats, _) => are_refutable(cx, pats), PatKind::Struct(ref qpath, fields, _) => { is_enum_variant(cx, qpath, pat.hir_id) || are_refutable(cx, fields.iter().map(|field| &*field.pat)) }, PatKind::TupleStruct(ref qpath, pats, _) => { - is_enum_variant(cx, qpath, pat.hir_id) || are_refutable(cx, pats.iter().map(|pat| &**pat)) + is_enum_variant(cx, qpath, pat.hir_id) || are_refutable(cx, pats) }, - PatKind::Slice(head, ref middle, tail) => { + PatKind::Slice(head, middle, tail) => { match &cx.typeck_results().node_type(pat.hir_id).kind() { rustc_ty::Slice(..) => { // [..] is the only irrefutable slice pattern. !head.is_empty() || middle.is_none() || !tail.is_empty() }, rustc_ty::Array(..) => { - are_refutable(cx, head.iter().chain(middle).chain(tail.iter()).map(|pat| &**pat)) + are_refutable(cx, head.iter().chain(middle).chain(tail.iter())) }, _ => { // unreachable!() @@ -1066,7 +1066,7 @@ pub fn is_refutable(cx: &LateContext<'_>, pat: &Pat<'_>) -> bool { /// the function once on the given pattern. pub fn recurse_or_patterns<'tcx, F: FnMut(&'tcx Pat<'tcx>)>(pat: &'tcx Pat<'tcx>, mut f: F) { if let PatKind::Or(pats) = pat.kind { - pats.iter().copied().for_each(f); + pats.iter().for_each(f); } else { f(pat); }