Skip to content

Commit 053caf8

Browse files
authored
Rollup merge of rust-lang#98639 - camsteffen:no-node-binding, r=compiler-errors
Factor out `hir::Node::Binding`
2 parents d5e33d3 + 5de8590 commit 053caf8

File tree

7 files changed

+11
-18
lines changed

7 files changed

+11
-18
lines changed

clippy_lints/src/escape.rs

+5-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::span_lint_hir;
22
use clippy_utils::ty::contains_ty;
33
use rustc_hir::intravisit;
4-
use rustc_hir::{self, AssocItemKind, Body, FnDecl, HirId, HirIdSet, Impl, ItemKind, Node};
4+
use rustc_hir::{self, AssocItemKind, Body, FnDecl, HirId, HirIdSet, Impl, ItemKind, Node, Pat, PatKind};
55
use rustc_infer::infer::TyCtxtInferExt;
66
use rustc_lint::{LateContext, LateLintPass};
77
use rustc_middle::mir::FakeReadCause;
@@ -132,7 +132,10 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal {
132132
// TODO: Replace with Map::is_argument(..) when it's fixed
133133
fn is_argument(map: rustc_middle::hir::map::Map<'_>, id: HirId) -> bool {
134134
match map.find(id) {
135-
Some(Node::Binding(_)) => (),
135+
Some(Node::Pat(Pat {
136+
kind: PatKind::Binding(..),
137+
..
138+
})) => (),
136139
_ => return false,
137140
}
138141

@@ -144,15 +147,6 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
144147
if cmt.place.projections.is_empty() {
145148
if let PlaceBase::Local(lid) = cmt.place.base {
146149
self.set.remove(&lid);
147-
let map = &self.cx.tcx.hir();
148-
if let Some(Node::Binding(_)) = map.find(cmt.hir_id) {
149-
if self.set.contains(&lid) {
150-
// let y = x where x is known
151-
// remove x, insert y
152-
self.set.insert(cmt.hir_id);
153-
self.set.remove(&lid);
154-
}
155-
}
156150
}
157151
}
158152
}

clippy_lints/src/explicit_write.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ fn look_in_block<'tcx, 'hir>(cx: &LateContext<'tcx>, kind: &'tcx ExprKind<'hir>)
125125
// Find id of the local that expr_end_of_block resolves to
126126
if let ExprKind::Path(QPath::Resolved(None, expr_path)) = expr_end_of_block.kind;
127127
if let Res::Local(expr_res) = expr_path.res;
128-
if let Some(Node::Binding(res_pat)) = cx.tcx.hir().find(expr_res);
128+
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
131131
if let PatKind::Binding(BindingAnnotation::Unannotated, local_hir_id, _ident, None) = local.pat.kind;

clippy_lints/src/loops/mut_range_bound.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ fn mut_warn_with_span(cx: &LateContext<'_>, span: Option<Span>) {
4343
fn check_for_mutability(cx: &LateContext<'_>, bound: &Expr<'_>) -> Option<HirId> {
4444
if_chain! {
4545
if let Some(hir_id) = path_to_local(bound);
46-
if let Node::Binding(pat) = cx.tcx.hir().get(hir_id);
46+
if let Node::Pat(pat) = cx.tcx.hir().get(hir_id);
4747
if let PatKind::Binding(BindingAnnotation::Mutable, ..) = pat.kind;
4848
then {
4949
return Some(hir_id);

clippy_lints/src/loops/same_item_push.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub(super) fn check<'tcx>(
6363
Res::Local(hir_id) => {
6464
let node = cx.tcx.hir().get(hir_id);
6565
if_chain! {
66-
if let Node::Binding(pat) = node;
66+
if let Node::Pat(pat) = node;
6767
if let PatKind::Binding(bind_ann, ..) = pat.kind;
6868
if !matches!(bind_ann, BindingAnnotation::RefMut | BindingAnnotation::Mutable);
6969
let parent_node = cx.tcx.hir().get_parent_node(hir_id);

clippy_lints/src/manual_rem_euclid.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualRemEuclid {
7171
&& let Some(const3) = check_for_unsigned_int_constant(cx, right)
7272
// Also ensures the const is nonzero since zero can't be a divisor
7373
&& const1 == const2 && const2 == const3
74-
&& let Some(hir_id) = path_to_local(expr3)
75-
&& let Some(Node::Binding(_)) = cx.tcx.hir().find(hir_id) {
74+
&& let Some(hir_id) = path_to_local(expr3) {
7675
// Apply only to params or locals with annotated types
7776
match cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) {
7877
Some(Node::Param(..)) => (),

clippy_lints/src/methods/iter_skip_next.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr
2222
|diag| {
2323
if_chain! {
2424
if let Some(id) = path_to_local(recv);
25-
if let Node::Binding(pat) = cx.tcx.hir().get(id);
25+
if let Node::Pat(pat) = cx.tcx.hir().get(id);
2626
if let PatKind::Binding(ann, _, _, _) = pat.kind;
2727
if ann != BindingAnnotation::Mutable;
2828
then {

clippy_utils/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ pub fn expr_or_init<'a, 'b, 'tcx: 'b>(cx: &LateContext<'tcx>, mut expr: &'a Expr
183183
pub fn find_binding_init<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<&'tcx Expr<'tcx>> {
184184
let hir = cx.tcx.hir();
185185
if_chain! {
186-
if let Some(Node::Binding(pat)) = hir.find(hir_id);
186+
if let Some(Node::Pat(pat)) = hir.find(hir_id);
187187
if matches!(pat.kind, PatKind::Binding(BindingAnnotation::Unannotated, ..));
188188
let parent = hir.get_parent_node(hir_id);
189189
if let Some(Node::Local(local)) = hir.find(parent);

0 commit comments

Comments
 (0)