Skip to content

Commit 9ea82d5

Browse files
committed
clippy: BindingAnnotation change
1 parent ac4bb00 commit 9ea82d5

35 files changed

+95
-103
lines changed

src/tools/clippy/clippy_lints/src/dereference.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing {
503503
}
504504

505505
fn check_pat(&mut self, cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>) {
506-
if let PatKind::Binding(BindingAnnotation::Ref, id, name, _) = pat.kind {
506+
if let PatKind::Binding(BindingAnnotation::REF, id, name, _) = pat.kind {
507507
if let Some(opt_prev_pat) = self.ref_locals.get_mut(&id) {
508508
// This binding id has been seen before. Add this pattern to the list of changes.
509509
if let Some(prev_pat) = opt_prev_pat {

src/tools/clippy/clippy_lints/src/explicit_write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ fn look_in_block<'tcx, 'hir>(cx: &LateContext<'tcx>, kind: &'tcx ExprKind<'hir>)
128128
if let Some(Node::Pat(res_pat)) = cx.tcx.hir().find(expr_res);
129129

130130
// Find id of the local we found in the block
131-
if let PatKind::Binding(BindingAnnotation::Unannotated, local_hir_id, _ident, None) = local.pat.kind;
131+
if let PatKind::Binding(BindingAnnotation::NONE, local_hir_id, _ident, None) = local.pat.kind;
132132

133133
// If those two are the same hir id
134134
if res_pat.hir_id == local_hir_id;

src/tools/clippy/clippy_lints/src/index_refutable_slice.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,14 @@ fn find_slice_values(cx: &LateContext<'_>, pat: &hir::Pat<'_>) -> FxIndexMap<hir
9595
let mut removed_pat: FxHashSet<hir::HirId> = FxHashSet::default();
9696
let mut slices: FxIndexMap<hir::HirId, SliceLintInformation> = FxIndexMap::default();
9797
pat.walk_always(|pat| {
98-
if let hir::PatKind::Binding(binding, value_hir_id, ident, sub_pat) = pat.kind {
99-
// We'll just ignore mut and ref mut for simplicity sake right now
100-
if let hir::BindingAnnotation::Mutable | hir::BindingAnnotation::RefMut = binding {
101-
return;
102-
}
103-
98+
// We'll just ignore mut and ref mut for simplicity sake right now
99+
if let hir::PatKind::Binding(
100+
hir::BindingAnnotation(by_ref, hir::Mutability::Not),
101+
value_hir_id,
102+
ident,
103+
sub_pat,
104+
) = pat.kind
105+
{
104106
// This block catches bindings with sub patterns. It would be hard to build a correct suggestion
105107
// for them and it's likely that the user knows what they are doing in such a case.
106108
if removed_pat.contains(&value_hir_id) {
@@ -116,7 +118,7 @@ fn find_slice_values(cx: &LateContext<'_>, pat: &hir::Pat<'_>) -> FxIndexMap<hir
116118
if let ty::Slice(inner_ty) | ty::Array(inner_ty, _) = bound_ty.peel_refs().kind() {
117119
// The values need to use the `ref` keyword if they can't be copied.
118120
// This will need to be adjusted if the lint want to support mutable access in the future
119-
let src_is_ref = bound_ty.is_ref() && binding != hir::BindingAnnotation::Ref;
121+
let src_is_ref = bound_ty.is_ref() && by_ref != hir::ByRef::Yes;
120122
let needs_ref = !(src_is_ref || is_copy(cx, *inner_ty));
121123

122124
let slice_info = slices

src/tools/clippy/clippy_lints/src/let_if_seq.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use clippy_utils::{path_to_local_id, visitors::is_local_used};
44
use if_chain::if_chain;
55
use rustc_errors::Applicability;
66
use rustc_hir as hir;
7-
use rustc_hir::BindingAnnotation;
7+
use rustc_hir::{BindingAnnotation, Mutability};
88
use rustc_lint::{LateContext, LateLintPass};
99
use rustc_session::{declare_lint_pass, declare_tool_lint};
1010

@@ -98,7 +98,7 @@ impl<'tcx> LateLintPass<'tcx> for LetIfSeq {
9898
};
9999

100100
let mutability = match mode {
101-
BindingAnnotation::RefMut | BindingAnnotation::Mutable => "<mut> ",
101+
BindingAnnotation(_, Mutability::Mut) => "<mut> ",
102102
_ => "",
103103
};
104104

src/tools/clippy/clippy_lints/src/loops/manual_find.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ fn get_binding(pat: &Pat<'_>) -> Option<HirId> {
106106
hir_id = None;
107107
return;
108108
}
109-
if let BindingAnnotation::Unannotated = annotation {
109+
if let BindingAnnotation::NONE = annotation {
110110
hir_id = Some(id);
111111
}
112112
});

src/tools/clippy/clippy_lints/src/loops/mut_range_bound.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn check_for_mutability(cx: &LateContext<'_>, bound: &Expr<'_>) -> Option<HirId>
4444
if_chain! {
4545
if let Some(hir_id) = path_to_local(bound);
4646
if let Node::Pat(pat) = cx.tcx.hir().get(hir_id);
47-
if let PatKind::Binding(BindingAnnotation::Mutable, ..) = pat.kind;
47+
if let PatKind::Binding(BindingAnnotation::MUT, ..) = pat.kind;
4848
then {
4949
return Some(hir_id);
5050
}

src/tools/clippy/clippy_lints/src/loops/same_item_push.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use if_chain::if_chain;
77
use rustc_data_structures::fx::FxHashSet;
88
use rustc_hir::def::{DefKind, Res};
99
use rustc_hir::intravisit::{walk_expr, Visitor};
10-
use rustc_hir::{BindingAnnotation, Block, Expr, ExprKind, HirId, Node, Pat, PatKind, Stmt, StmtKind};
10+
use rustc_hir::{BindingAnnotation, Block, Expr, ExprKind, HirId, Mutability, Node, Pat, PatKind, Stmt, StmtKind};
1111
use rustc_lint::LateContext;
1212
use rustc_span::symbol::sym;
1313
use std::iter::Iterator;
@@ -65,7 +65,7 @@ pub(super) fn check<'tcx>(
6565
if_chain! {
6666
if let Node::Pat(pat) = node;
6767
if let PatKind::Binding(bind_ann, ..) = pat.kind;
68-
if !matches!(bind_ann, BindingAnnotation::RefMut | BindingAnnotation::Mutable);
68+
if !matches!(bind_ann, BindingAnnotation(_, Mutability::Mut));
6969
let parent_node = cx.tcx.hir().get_parent_node(hir_id);
7070
if let Some(Node::Local(parent_let_expr)) = cx.tcx.hir().find(parent_node);
7171
if let Some(init) = parent_let_expr.init;

src/tools/clippy/clippy_lints/src/matches/manual_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ fn check<'tcx>(
165165
}
166166

167167
// `ref` and `ref mut` annotations were handled earlier.
168-
let annotation = if matches!(annotation, BindingAnnotation::Mutable) {
168+
let annotation = if matches!(annotation, BindingAnnotation::MUT) {
169169
"mut "
170170
} else {
171171
""

src/tools/clippy/clippy_lints/src/matches/match_as_ref.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,25 @@ use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::source::snippet_with_applicability;
33
use clippy_utils::{is_lang_ctor, peel_blocks};
44
use rustc_errors::Applicability;
5-
use rustc_hir::{Arm, BindingAnnotation, Expr, ExprKind, LangItem, PatKind, QPath};
5+
use rustc_hir::{Arm, BindingAnnotation, ByRef, Expr, ExprKind, LangItem, Mutability, PatKind, QPath};
66
use rustc_lint::LateContext;
77
use rustc_middle::ty;
88

99
use super::MATCH_AS_REF;
1010

1111
pub(crate) fn check(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>) {
1212
if arms.len() == 2 && arms[0].guard.is_none() && arms[1].guard.is_none() {
13-
let arm_ref: Option<BindingAnnotation> = if is_none_arm(cx, &arms[0]) {
13+
let arm_ref_mut = if is_none_arm(cx, &arms[0]) {
1414
is_ref_some_arm(cx, &arms[1])
1515
} else if is_none_arm(cx, &arms[1]) {
1616
is_ref_some_arm(cx, &arms[0])
1717
} else {
1818
None
1919
};
20-
if let Some(rb) = arm_ref {
21-
let suggestion = if rb == BindingAnnotation::Ref {
22-
"as_ref"
23-
} else {
24-
"as_mut"
20+
if let Some(rb) = arm_ref_mut {
21+
let suggestion = match rb {
22+
Mutability::Not => "as_ref",
23+
Mutability::Mut => "as_mut",
2524
};
2625

2726
let output_ty = cx.typeck_results().expr_ty(expr);
@@ -66,19 +65,18 @@ fn is_none_arm(cx: &LateContext<'_>, arm: &Arm<'_>) -> bool {
6665
}
6766

6867
// Checks if arm has the form `Some(ref v) => Some(v)` (checks for `ref` and `ref mut`)
69-
fn is_ref_some_arm(cx: &LateContext<'_>, arm: &Arm<'_>) -> Option<BindingAnnotation> {
68+
fn is_ref_some_arm(cx: &LateContext<'_>, arm: &Arm<'_>) -> Option<Mutability> {
7069
if_chain! {
7170
if let PatKind::TupleStruct(ref qpath, [first_pat, ..], _) = arm.pat.kind;
7271
if is_lang_ctor(cx, qpath, LangItem::OptionSome);
73-
if let PatKind::Binding(rb, .., ident, _) = first_pat.kind;
74-
if rb == BindingAnnotation::Ref || rb == BindingAnnotation::RefMut;
72+
if let PatKind::Binding(BindingAnnotation(ByRef::Yes, mutabl), .., ident, _) = first_pat.kind;
7573
if let ExprKind::Call(e, [arg]) = peel_blocks(arm.body).kind;
7674
if let ExprKind::Path(ref some_path) = e.kind;
7775
if is_lang_ctor(cx, some_path, LangItem::OptionSome);
7876
if let ExprKind::Path(QPath::Resolved(_, path2)) = arg.kind;
7977
if path2.segments.len() == 1 && ident.name == path2.segments[0].ident.name;
8078
then {
81-
return Some(rb)
79+
return Some(mutabl)
8280
}
8381
}
8482
None

src/tools/clippy/clippy_lints/src/matches/needless_match.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use clippy_utils::{
88
};
99
use rustc_errors::Applicability;
1010
use rustc_hir::LangItem::OptionNone;
11-
use rustc_hir::{Arm, BindingAnnotation, Expr, ExprKind, FnRetTy, Guard, Node, Pat, PatKind, Path, QPath};
11+
use rustc_hir::{Arm, BindingAnnotation, ByRef, Expr, ExprKind, FnRetTy, Guard, Node, Pat, PatKind, Path, QPath};
1212
use rustc_lint::LateContext;
1313
use rustc_span::sym;
1414
use rustc_typeck::hir_ty_to_ty;
@@ -189,8 +189,7 @@ fn pat_same_as_expr(pat: &Pat<'_>, expr: &Expr<'_>) -> bool {
189189
},
190190
)),
191191
) => {
192-
return !matches!(annot, BindingAnnotation::Ref | BindingAnnotation::RefMut)
193-
&& pat_ident.name == first_seg.ident.name;
192+
return !matches!(annot, BindingAnnotation(ByRef::Yes, _)) && pat_ident.name == first_seg.ident.name;
194193
},
195194
// Example: `Custom::TypeA => Custom::TypeB`, or `None => None`
196195
(PatKind::Path(QPath::Resolved(_, p_path)), ExprKind::Path(QPath::Resolved(_, e_path))) => {

0 commit comments

Comments
 (0)