Skip to content

Commit 1b0e578

Browse files
committed
Auto merge of #87140 - camsteffen:pat-slice-refs, r=oli-obk
Remove refs from Pat slices Changes `PatKind::Or(&'hir [&'hir Pat<'hir>])` to `PatKind::Or(&'hir [Pat<'hir>])` and others. This is more consistent with `ExprKind`, saves a little memory, and is a little easier to use.
2 parents 5c54d04 + 81904a4 commit 1b0e578

File tree

5 files changed

+14
-14
lines changed

5 files changed

+14
-14
lines changed

clippy_lints/src/manual_unwrap_or.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ fn lint_manual_unwrap_or<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
6161
if let Some((idx, or_arm)) = arms.iter().enumerate().find(|(_, arm)| {
6262
match arm.pat.kind {
6363
PatKind::Path(ref qpath) => is_lang_ctor(cx, qpath, OptionNone),
64-
PatKind::TupleStruct(ref qpath, &[pat], _) =>
64+
PatKind::TupleStruct(ref qpath, [pat], _) =>
6565
matches!(pat.kind, PatKind::Wild) && is_lang_ctor(cx, qpath, ResultErr),
6666
_ => false,
6767
}
6868
});
6969
let unwrap_arm = &arms[1 - idx];
70-
if let PatKind::TupleStruct(ref qpath, &[unwrap_pat], _) = unwrap_arm.pat.kind;
70+
if let PatKind::TupleStruct(ref qpath, [unwrap_pat], _) = unwrap_arm.pat.kind;
7171
if is_lang_ctor(cx, qpath, OptionSome) || is_lang_ctor(cx, qpath, ResultOk);
7272
if let PatKind::Binding(_, binding_hir_id, ..) = unwrap_pat.kind;
7373
if path_to_local_id(unwrap_arm.body, binding_hir_id);

clippy_lints/src/matches.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ impl<'tcx> LateLintPass<'tcx> for Matches {
625625
if let PatKind::TupleStruct(
626626
QPath::Resolved(None, variant_name), args, _) = arms[0].pat.kind;
627627
if args.len() == 1;
628-
if let PatKind::Binding(_, arg, ..) = strip_pat_refs(args[0]).kind;
628+
if let PatKind::Binding(_, arg, ..) = strip_pat_refs(&args[0]).kind;
629629
let body = remove_blocks(arms[0].body);
630630
if path_to_local_id(body, arg);
631631

clippy_lints/src/option_if_let_else.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ fn detect_option_if_let_else<'tcx>(
132132
if !is_else_clause(cx.tcx, expr);
133133
if arms.len() == 2;
134134
if !is_result_ok(cx, cond_expr); // Don't lint on Result::ok because a different lint does it already
135-
if let PatKind::TupleStruct(struct_qpath, &[inner_pat], _) = &arms[0].pat.kind;
135+
if let PatKind::TupleStruct(struct_qpath, [inner_pat], _) = &arms[0].pat.kind;
136136
if is_lang_ctor(cx, struct_qpath, OptionSome);
137137
if let PatKind::Binding(bind_annotation, _, id, _) = &inner_pat.kind;
138138
if !contains_return_break_continue_macro(arms[0].body);

clippy_lints/src/pattern_type_mismatch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ fn get_variant<'a>(adt_def: &'a AdtDef, qpath: &QPath<'_>) -> Option<&'a Variant
258258

259259
fn find_first_mismatch_in_tuple<'tcx, I>(
260260
cx: &LateContext<'tcx>,
261-
pats: &[&Pat<'_>],
261+
pats: &[Pat<'_>],
262262
ty_iter_src: I,
263263
) -> Option<(Span, Mutability, Level)>
264264
where

clippy_utils/src/lib.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ pub fn in_macro(span: Span) -> bool {
255255
}
256256

257257
/// Checks if given pattern is a wildcard (`_`)
258-
pub fn is_wild<'tcx>(pat: &impl std::ops::Deref<Target = Pat<'tcx>>) -> bool {
258+
pub fn is_wild(pat: &Pat<'_>) -> bool {
259259
matches!(pat.kind, PatKind::Wild)
260260
}
261261

@@ -1023,8 +1023,8 @@ pub fn is_refutable(cx: &LateContext<'_>, pat: &Pat<'_>) -> bool {
10231023
)
10241024
}
10251025

1026-
fn are_refutable<'a, I: Iterator<Item = &'a Pat<'a>>>(cx: &LateContext<'_>, mut i: I) -> bool {
1027-
i.any(|pat| is_refutable(cx, pat))
1026+
fn are_refutable<'a, I: IntoIterator<Item = &'a Pat<'a>>>(cx: &LateContext<'_>, i: I) -> bool {
1027+
i.into_iter().any(|pat| is_refutable(cx, pat))
10281028
}
10291029

10301030
match pat.kind {
@@ -1035,23 +1035,23 @@ pub fn is_refutable(cx: &LateContext<'_>, pat: &Pat<'_>) -> bool {
10351035
PatKind::Path(ref qpath) => is_enum_variant(cx, qpath, pat.hir_id),
10361036
PatKind::Or(pats) => {
10371037
// TODO: should be the honest check, that pats is exhaustive set
1038-
are_refutable(cx, pats.iter().map(|pat| &**pat))
1038+
are_refutable(cx, pats)
10391039
},
1040-
PatKind::Tuple(pats, _) => are_refutable(cx, pats.iter().map(|pat| &**pat)),
1040+
PatKind::Tuple(pats, _) => are_refutable(cx, pats),
10411041
PatKind::Struct(ref qpath, fields, _) => {
10421042
is_enum_variant(cx, qpath, pat.hir_id) || are_refutable(cx, fields.iter().map(|field| &*field.pat))
10431043
},
10441044
PatKind::TupleStruct(ref qpath, pats, _) => {
1045-
is_enum_variant(cx, qpath, pat.hir_id) || are_refutable(cx, pats.iter().map(|pat| &**pat))
1045+
is_enum_variant(cx, qpath, pat.hir_id) || are_refutable(cx, pats)
10461046
},
1047-
PatKind::Slice(head, ref middle, tail) => {
1047+
PatKind::Slice(head, middle, tail) => {
10481048
match &cx.typeck_results().node_type(pat.hir_id).kind() {
10491049
rustc_ty::Slice(..) => {
10501050
// [..] is the only irrefutable slice pattern.
10511051
!head.is_empty() || middle.is_none() || !tail.is_empty()
10521052
},
10531053
rustc_ty::Array(..) => {
1054-
are_refutable(cx, head.iter().chain(middle).chain(tail.iter()).map(|pat| &**pat))
1054+
are_refutable(cx, head.iter().chain(middle).chain(tail.iter()))
10551055
},
10561056
_ => {
10571057
// unreachable!()
@@ -1066,7 +1066,7 @@ pub fn is_refutable(cx: &LateContext<'_>, pat: &Pat<'_>) -> bool {
10661066
/// the function once on the given pattern.
10671067
pub fn recurse_or_patterns<'tcx, F: FnMut(&'tcx Pat<'tcx>)>(pat: &'tcx Pat<'tcx>, mut f: F) {
10681068
if let PatKind::Or(pats) = pat.kind {
1069-
pats.iter().copied().for_each(f);
1069+
pats.iter().for_each(f);
10701070
} else {
10711071
f(pat);
10721072
}

0 commit comments

Comments
 (0)