Skip to content

Commit 4df9604

Browse files
authored
Rollup merge of rust-lang#98639 - camsteffen:no-node-binding, r=compiler-errors
Factor out `hir::Node::Binding`
2 parents a9d53c3 + 716af21 commit 4df9604

File tree

17 files changed

+21
-35
lines changed

17 files changed

+21
-35
lines changed

compiler/rustc_ast_lowering/src/index.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
192192
}
193193

194194
fn visit_pat(&mut self, pat: &'hir Pat<'hir>) {
195-
let node =
196-
if let PatKind::Binding(..) = pat.kind { Node::Binding(pat) } else { Node::Pat(pat) };
197-
self.insert(pat.span, pat.hir_id, node);
195+
self.insert(pat.span, pat.hir_id, Node::Pat(pat));
198196

199197
self.with_parent(pat.hir_id, |this| {
200198
intravisit::walk_pat(this, pat);

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
362362

363363
let upvar_hir_id = captured_place.get_root_variable();
364364

365-
if let Some(Node::Binding(pat)) = self.infcx.tcx.hir().find(upvar_hir_id)
365+
if let Some(Node::Pat(pat)) = self.infcx.tcx.hir().find(upvar_hir_id)
366366
&& let hir::PatKind::Binding(
367367
hir::BindingAnnotation::Unannotated,
368368
_,

compiler/rustc_const_eval/src/interpret/validity.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
244244
// for a generator).
245245
let var_hir_id = captured_place.get_root_variable();
246246
let node = self.ecx.tcx.hir().get(var_hir_id);
247-
if let hir::Node::Binding(pat) = node {
247+
if let hir::Node::Pat(pat) = node {
248248
if let hir::PatKind::Binding(_, _, ident, _) = pat.kind {
249249
name = Some(ident.name);
250250
}

compiler/rustc_hir/src/hir.rs

-2
Original file line numberDiff line numberDiff line change
@@ -3326,7 +3326,6 @@ pub enum Node<'hir> {
33263326
Ty(&'hir Ty<'hir>),
33273327
TypeBinding(&'hir TypeBinding<'hir>),
33283328
TraitRef(&'hir TraitRef<'hir>),
3329-
Binding(&'hir Pat<'hir>),
33303329
Pat(&'hir Pat<'hir>),
33313330
Arm(&'hir Arm<'hir>),
33323331
Block(&'hir Block<'hir>),
@@ -3378,7 +3377,6 @@ impl<'hir> Node<'hir> {
33783377
| Node::Block(..)
33793378
| Node::Ctor(..)
33803379
| Node::Pat(..)
3381-
| Node::Binding(..)
33823380
| Node::Arm(..)
33833381
| Node::Local(..)
33843382
| Node::Crate(..)

compiler/rustc_hir_pretty/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl<'a> State<'a> {
8787
Node::Ty(a) => self.print_type(&a),
8888
Node::TypeBinding(a) => self.print_type_binding(&a),
8989
Node::TraitRef(a) => self.print_trait_ref(&a),
90-
Node::Binding(a) | Node::Pat(a) => self.print_pat(&a),
90+
Node::Pat(a) => self.print_pat(&a),
9191
Node::Arm(a) => self.print_arm(&a),
9292
Node::Infer(_) => self.word("_"),
9393
Node::Block(a) => {

compiler/rustc_middle/src/hir/map/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,6 @@ impl<'hir> Map<'hir> {
302302
| Node::Infer(_)
303303
| Node::TraitRef(_)
304304
| Node::Pat(_)
305-
| Node::Binding(_)
306305
| Node::Local(_)
307306
| Node::Param(_)
308307
| Node::Arm(_)
@@ -901,7 +900,7 @@ impl<'hir> Map<'hir> {
901900
#[inline]
902901
fn opt_ident(self, id: HirId) -> Option<Ident> {
903902
match self.get(id) {
904-
Node::Binding(&Pat { kind: PatKind::Binding(_, _, ident, _), .. }) => Some(ident),
903+
Node::Pat(&Pat { kind: PatKind::Binding(_, _, ident, _), .. }) => Some(ident),
905904
// A `Ctor` doesn't have an identifier itself, but its parent
906905
// struct/variant does. Compare with `hir::Map::opt_span`.
907906
Node::Ctor(..) => match self.find(self.get_parent_node(id))? {
@@ -969,7 +968,6 @@ impl<'hir> Map<'hir> {
969968
Node::Ty(ty) => ty.span,
970969
Node::TypeBinding(tb) => tb.span,
971970
Node::TraitRef(tr) => tr.path.span,
972-
Node::Binding(pat) => pat.span,
973971
Node::Pat(pat) => pat.span,
974972
Node::Arm(arm) => arm.span,
975973
Node::Block(block) => block.span,
@@ -1203,7 +1201,6 @@ fn hir_id_to_string(map: Map<'_>, id: HirId) -> String {
12031201
Some(Node::Ty(_)) => node_str("type"),
12041202
Some(Node::TypeBinding(_)) => node_str("type binding"),
12051203
Some(Node::TraitRef(_)) => node_str("trait ref"),
1206-
Some(Node::Binding(_)) => node_str("local"),
12071204
Some(Node::Pat(_)) => node_str("pat"),
12081205
Some(Node::Param(_)) => node_str("param"),
12091206
Some(Node::Arm(_)) => node_str("arm"),

compiler/rustc_mir_build/src/build/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
997997
continue;
998998
};
999999
let pat = match tcx.hir().get(arg.pat.hir_id) {
1000-
Node::Pat(pat) | Node::Binding(pat) => pat,
1000+
Node::Pat(pat) => pat,
10011001
node => bug!("pattern became {:?}", node),
10021002
};
10031003
let pattern = pat_from_hir(tcx, self.param_env, self.typeck_results, pat);

compiler/rustc_mir_build/src/thir/cx/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl<'tcx> Cx<'tcx> {
101101
#[tracing::instrument(level = "debug", skip(self))]
102102
pub(crate) fn pattern_from_hir(&mut self, p: &hir::Pat<'_>) -> Pat<'tcx> {
103103
let p = match self.tcx.hir().get(p.hir_id) {
104-
Node::Pat(p) | Node::Binding(p) => p,
104+
Node::Pat(p) => p,
105105
node => bug!("pattern became {:?}", node),
106106
};
107107
pat_from_hir(self.tcx, self.param_env, self.typeck_results(), p)

compiler/rustc_save_analysis/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -623,9 +623,9 @@ impl<'tcx> SaveContext<'tcx> {
623623
}
624624
},
625625

626-
Node::Binding(&hir::Pat {
627-
kind: hir::PatKind::Binding(_, canonical_id, ..), ..
628-
}) => Res::Local(canonical_id),
626+
Node::Pat(&hir::Pat { kind: hir::PatKind::Binding(_, canonical_id, ..), .. }) => {
627+
Res::Local(canonical_id)
628+
}
629629

630630
_ => Res::Err,
631631
}

compiler/rustc_typeck/src/check/demand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
223223
None,
224224
hir::Path { res: hir::def::Res::Local(hir_id), .. },
225225
)) => {
226-
if let Some(hir::Node::Binding(pat)) = self.tcx.hir().find(*hir_id) {
226+
if let Some(hir::Node::Pat(pat)) = self.tcx.hir().find(*hir_id) {
227227
let parent = self.tcx.hir().get_parent_node(pat.hir_id);
228228
primary_span = pat.span;
229229
secondary_span = pat.span;

compiler/rustc_typeck/src/check/generator_interior/drop_ranges/cfg_build.rs

-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ impl<'a, 'tcx> DropRangeVisitor<'a, 'tcx> {
251251
| hir::Node::Ty(..)
252252
| hir::Node::TypeBinding(..)
253253
| hir::Node::TraitRef(..)
254-
| hir::Node::Binding(..)
255254
| hir::Node::Pat(..)
256255
| hir::Node::Arm(..)
257256
| hir::Node::Local(..)

src/tools/clippy/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;
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;
@@ -131,7 +131,10 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal {
131131
// TODO: Replace with Map::is_argument(..) when it's fixed
132132
fn is_argument(map: rustc_middle::hir::map::Map<'_>, id: HirId) -> bool {
133133
match map.find(id) {
134-
Some(Node::Binding(_)) => (),
134+
Some(Node::Pat(Pat {
135+
kind: PatKind::Binding(..),
136+
..
137+
})) => (),
135138
_ => return false,
136139
}
137140

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

src/tools/clippy/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;

src/tools/clippy/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);

src/tools/clippy/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);

src/tools/clippy/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 {

src/tools/clippy/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)