Skip to content

Commit ac4664b

Browse files
frank-kingMuscraft
authored andcommitted
Implement &pin patterns and ref pin bindings
1 parent 701315c commit ac4664b

20 files changed

+44
-39
lines changed

clippy_lints/src/equatable_if_let.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ fn unary_pattern(pat: &Pat<'_>) -> bool {
5555
| PatKind::Err(_) => false,
5656
PatKind::Struct(_, a, etc) => etc.is_none() && a.iter().all(|x| unary_pattern(x.pat)),
5757
PatKind::Tuple(a, etc) | PatKind::TupleStruct(_, a, etc) => etc.as_opt_usize().is_none() && array_rec(a),
58-
PatKind::Ref(x, _) | PatKind::Box(x) | PatKind::Deref(x) | PatKind::Guard(x, _) => unary_pattern(x),
58+
PatKind::Ref(x, _, _) | PatKind::Box(x) | PatKind::Deref(x) | PatKind::Guard(x, _) => unary_pattern(x),
5959
PatKind::Expr(_) => true,
6060
}
6161
}

clippy_lints/src/loops/manual_find.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub(super) fn check<'tcx>(
4343
let mut snippet = make_iterator_snippet(cx, arg, &mut applicability);
4444
// Checks if `pat` is a single reference to a binding (`&x`)
4545
let is_ref_to_binding =
46-
matches!(pat.kind, PatKind::Ref(inner, _) if matches!(inner.kind, PatKind::Binding(..)));
46+
matches!(pat.kind, PatKind::Ref(inner, _, _) if matches!(inner.kind, PatKind::Binding(..)));
4747
// If `pat` is not a binding or a reference to a binding (`x` or `&x`)
4848
// we need to map it to the binding returned by the function (i.e. `.map(|(x, _)| x)`)
4949
if !(matches!(pat.kind, PatKind::Binding(..)) || is_ref_to_binding) {

clippy_lints/src/manual_retain.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ fn check_iter(
157157
),
158158
);
159159
},
160-
hir::PatKind::Ref(pat, _) => make_span_lint_and_sugg(
160+
hir::PatKind::Ref(pat, _, _) => make_span_lint_and_sugg(
161161
cx,
162162
parent_expr_span,
163163
format!(
@@ -196,7 +196,7 @@ fn check_to_owned(
196196
&& let filter_body = cx.tcx.hir_body(closure.body)
197197
&& let [filter_params] = filter_body.params
198198
&& msrv.meets(cx, msrvs::STRING_RETAIN)
199-
&& let hir::PatKind::Ref(pat, _) = filter_params.pat.kind
199+
&& let hir::PatKind::Ref(pat, _, _) = filter_params.pat.kind
200200
{
201201
make_span_lint_and_sugg(
202202
cx,

clippy_lints/src/matches/manual_ok_err.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ fn is_variant_or_wildcard(cx: &LateContext<'_>, pat: &Pat<'_>, can_be_wild: bool
7878
.is_lang_item(cx, ResultErr)
7979
== must_match_err
8080
},
81-
PatKind::Binding(_, _, _, Some(pat)) | PatKind::Ref(pat, _) => {
81+
PatKind::Binding(_, _, _, Some(pat)) | PatKind::Ref(pat, _, _) => {
8282
is_variant_or_wildcard(cx, pat, can_be_wild, must_match_err)
8383
},
8484
_ => false,

clippy_lints/src/matches/manual_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ pub(super) fn try_parse_pattern<'tcx>(
254254
) -> Option<OptionPat<'tcx>> {
255255
match pat.kind {
256256
PatKind::Wild => Some(OptionPat::Wild),
257-
PatKind::Ref(pat, _) => f(cx, pat, ref_count + 1, ctxt),
257+
PatKind::Ref(pat, _, _) => f(cx, pat, ref_count + 1, ctxt),
258258
PatKind::Expr(PatExpr {
259259
kind: PatExprKind::Path(qpath),
260260
hir_id,

clippy_lints/src/matches/match_ref_pats.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ where
5050
}
5151

5252
let remaining_suggs = pats.filter_map(|pat| {
53-
if let PatKind::Ref(refp, _) = pat.kind {
53+
if let PatKind::Ref(refp, _, _) = pat.kind {
5454
Some((pat.span, snippet(cx, refp.span, "..").to_string()))
5555
} else {
5656
None

clippy_lints/src/matches/match_same_arms.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ impl<'a> NormalizedPat<'a> {
264264
PatKind::Binding(.., Some(pat))
265265
| PatKind::Box(pat)
266266
| PatKind::Deref(pat)
267-
| PatKind::Ref(pat, _)
267+
| PatKind::Ref(pat, _, _)
268268
| PatKind::Guard(pat, _) => Self::from_pat(cx, arena, pat),
269269
PatKind::Never => Self::Never,
270270
PatKind::Struct(ref path, fields, _) => {

clippy_lints/src/matches/redundant_guards.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'tcx>], msrv:
3030
&& !pat_contains_disallowed_or(cx, arm.pat, msrv)
3131
{
3232
let pat_span = match (arm.pat.kind, binding.byref_ident) {
33-
(PatKind::Ref(pat, _), Some(_)) => pat.span,
33+
(PatKind::Ref(pat, _, _), Some(_)) => pat.span,
3434
(PatKind::Ref(..), None) | (_, Some(_)) => continue,
3535
_ => arm.pat.span,
3636
};
@@ -49,7 +49,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'tcx>], msrv:
4949
&& !pat_contains_disallowed_or(cx, let_expr.pat, msrv)
5050
{
5151
let pat_span = match (let_expr.pat.kind, binding.byref_ident) {
52-
(PatKind::Ref(pat, _), Some(_)) => pat.span,
52+
(PatKind::Ref(pat, _, _), Some(_)) => pat.span,
5353
(PatKind::Ref(..), None) | (_, Some(_)) => continue,
5454
_ => let_expr.pat.span,
5555
};

clippy_lints/src/matches/redundant_pattern_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ fn find_method_sugg_for_if_let<'tcx>(
186186
// also look inside refs
187187
// if we have &None for example, peel it so we can detect "if let None = x"
188188
let check_pat = match let_pat.kind {
189-
PatKind::Ref(inner, _mutability) => inner,
189+
PatKind::Ref(inner, _pinnedness, _mutability) => inner,
190190
_ => let_pat,
191191
};
192192
let op_ty = cx.typeck_results().expr_ty(let_expr);

clippy_lints/src/matches/single_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ impl<'a> PatState<'a> {
373373
},
374374

375375
// Patterns for things which can only contain a single sub-pattern.
376-
PatKind::Binding(_, _, _, Some(pat)) | PatKind::Ref(pat, _) | PatKind::Box(pat) | PatKind::Deref(pat) => {
376+
PatKind::Binding(_, _, _, Some(pat)) | PatKind::Ref(pat, _, _) | PatKind::Box(pat) | PatKind::Deref(pat) => {
377377
self.add_pat(cx, pat)
378378
},
379379
PatKind::Tuple([sub_pat], pos)

0 commit comments

Comments
 (0)