Skip to content

Commit 558a07b

Browse files
committed
hir: remove NodeId from PatKind
1 parent 78f91e3 commit 558a07b

File tree

24 files changed

+48
-53
lines changed

24 files changed

+48
-53
lines changed

src/librustc/hir/intravisit.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -697,8 +697,8 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) {
697697
PatKind::Ref(ref subpattern, _) => {
698698
visitor.visit_pat(subpattern)
699699
}
700-
PatKind::Binding(_, canonical_id, _hir_id, ident, ref optional_subpattern) => {
701-
visitor.visit_def_mention(Def::Local(canonical_id));
700+
PatKind::Binding(_, _hir_id, ident, ref optional_subpattern) => {
701+
// visitor.visit_def_mention(Def::Local(hir_id));
702702
visitor.visit_ident(ident);
703703
walk_list!(visitor, visit_pat, optional_subpattern);
704704
}

src/librustc/hir/lowering.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -3679,11 +3679,10 @@ impl<'a> LoweringContext<'a> {
36793679
Some(Def::Local(id)) => id,
36803680
_ => p.id,
36813681
};
3682-
let hir_id = self.lower_node_id(canonical_id).hir_id;
3682+
36833683
hir::PatKind::Binding(
36843684
self.lower_binding_mode(binding_mode),
3685-
canonical_id,
3686-
hir_id,
3685+
self.lower_node_id(canonical_id).hir_id,
36873686
ident,
36883687
sub.as_ref().map(|x| self.lower_pat(x)),
36893688
)
@@ -4985,7 +4984,7 @@ impl<'a> LoweringContext<'a> {
49854984
(
49864985
P(hir::Pat {
49874986
hir_id,
4988-
node: hir::PatKind::Binding(bm, node_id, hir_id, ident.with_span_pos(span), None),
4987+
node: hir::PatKind::Binding(bm, hir_id, ident.with_span_pos(span), None),
49894988
span,
49904989
}),
49914990
node_id

src/librustc/hir/map/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ impl<'hir> Map<'hir> {
10161016
Node::Field(f) => f.ident.name,
10171017
Node::Lifetime(lt) => lt.name.ident().name,
10181018
Node::GenericParam(param) => param.name.ident().name,
1019-
Node::Binding(&Pat { node: PatKind::Binding(_, _, _, l, _), .. }) => l.name,
1019+
Node::Binding(&Pat { node: PatKind::Binding(_, _, l, _), .. }) => l.name,
10201020
Node::StructCtor(_) => self.name(self.get_parent(id)),
10211021
_ => bug!("no name for {}", self.node_to_string(id))
10221022
}

src/librustc/hir/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -936,10 +936,10 @@ pub enum PatKind {
936936
Wild,
937937

938938
/// A fresh binding `ref mut binding @ OPT_SUBPATTERN`.
939-
/// The `NodeId` is the canonical ID for the variable being bound,
939+
/// The `HirId` is the canonical ID for the variable being bound,
940940
/// (e.g., in `Ok(x) | Err(x)`, both `x` use the same canonical ID),
941941
/// which is the pattern ID of the first `x`.
942-
Binding(BindingAnnotation, NodeId, HirId, Ident, Option<P<Pat>>),
942+
Binding(BindingAnnotation, HirId, Ident, Option<P<Pat>>),
943943

944944
/// A struct or struct variant pattern (e.g., `Variant {x, y, ..}`).
945945
/// The `bool` is `true` in the presence of a `..`.

src/librustc/hir/pat_util.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl hir::Pat {
7070
where F: FnMut(hir::BindingAnnotation, HirId, Span, ast::Ident),
7171
{
7272
self.walk(|p| {
73-
if let PatKind::Binding(binding_mode, _, _, ident, _) = p.node {
73+
if let PatKind::Binding(binding_mode, _, ident, _) = p.node {
7474
f(binding_mode, p.hir_id, p.span, ident);
7575
}
7676
true
@@ -110,8 +110,8 @@ impl hir::Pat {
110110

111111
pub fn simple_ident(&self) -> Option<ast::Ident> {
112112
match self.node {
113-
PatKind::Binding(hir::BindingAnnotation::Unannotated, _, _, ident, None) |
114-
PatKind::Binding(hir::BindingAnnotation::Mutable, _, _, ident, None) => Some(ident),
113+
PatKind::Binding(hir::BindingAnnotation::Unannotated, _, ident, None) |
114+
PatKind::Binding(hir::BindingAnnotation::Mutable, _, ident, None) => Some(ident),
115115
_ => None,
116116
}
117117
}

src/librustc/hir/print.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1765,7 +1765,7 @@ impl<'a> State<'a> {
17651765
// is that it doesn't matter
17661766
match pat.node {
17671767
PatKind::Wild => self.s.word("_")?,
1768-
PatKind::Binding(binding_mode, _, _, ident, ref sub) => {
1768+
PatKind::Binding(binding_mode, _, ident, ref sub) => {
17691769
match binding_mode {
17701770
hir::BindingAnnotation::Ref => {
17711771
self.word_nbsp("ref")?;

src/librustc/ich/impls_hir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ impl_stable_hash_for!(enum hir::RangeEnd {
448448

449449
impl_stable_hash_for!(enum hir::PatKind {
450450
Wild,
451-
Binding(binding_mode, var, hir_id, name, sub),
451+
Binding(binding_mode, hir_id, name, sub),
452452
Struct(path, field_pats, dotdot),
453453
TupleStruct(path, field_pats, dotdot),
454454
Path(path),

src/librustc/middle/expr_use_visitor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
860860

861861
// Each match binding is effectively an assignment to the
862862
// binding being produced.
863-
let def = Def::Local(canonical_id);
863+
let def = Def::Local(mc.tcx.hir().hir_to_node_id(canonical_id));
864864
if let Ok(ref binding_cmt) = mc.cat_def(pat.hir_id, pat.span, pat_ty, def) {
865865
delegate.mutate(pat.hir_id, pat.span, binding_cmt, MutateMode::Init);
866866
}

src/librustc/middle/liveness.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ fn add_from_pat<'a, 'tcx>(ir: &mut IrMaps<'a, 'tcx>, pat: &P<hir::Pat>) {
407407
while let Some(pat) = pats.pop_front() {
408408
use crate::hir::PatKind::*;
409409
match pat.node {
410-
Binding(_, _, _, _, ref inner_pat) => {
410+
Binding(_, _, _, ref inner_pat) => {
411411
pats.extend(inner_pat.iter());
412412
}
413413
Struct(_, ref fields, _) => {

src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub fn gather_move_from_pat<'a, 'c, 'tcx: 'c>(bccx: &BorrowckCtxt<'a, 'tcx>,
9898
cmt: &'c mc::cmt_<'tcx>) {
9999
let source = get_pattern_source(bccx.tcx,move_pat);
100100
let pat_span_path_opt = match move_pat.node {
101-
PatKind::Binding(_, _, _, ident, _) => {
101+
PatKind::Binding(_, _, ident, _) => {
102102
Some(MovePlace {
103103
span: move_pat.span,
104104
name: ident.name,

src/librustc_lint/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonShorthandFieldPatterns {
198198
// (Issue #49588)
199199
continue;
200200
}
201-
if let PatKind::Binding(_, _, _, ident, None) = fieldpat.node.pat.node {
201+
if let PatKind::Binding(_, _, ident, None) = fieldpat.node.pat.node {
202202
if cx.tcx.find_field_index(ident, &variant) ==
203203
Some(cx.tcx.field_index(fieldpat.node.hir_id, cx.tables)) {
204204
let mut err = cx.struct_span_lint(NON_SHORTHAND_FIELD_PATTERNS,

src/librustc_lint/nonstandard_style.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
358358
}
359359

360360
fn check_pat(&mut self, cx: &LateContext<'_, '_>, p: &hir::Pat) {
361-
if let &PatKind::Binding(_, _, _, ident, _) = &p.node {
361+
if let &PatKind::Binding(_, _, ident, _) = &p.node {
362362
self.check_snake_case(cx, "variable", &ident);
363363
}
364364
}

src/librustc_metadata/encoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
978978
let body = self.tcx.hir().body(body_id);
979979
self.lazy_seq(body.arguments.iter().map(|arg| {
980980
match arg.pat.node {
981-
PatKind::Binding(_, _, _, ident, _) => ident.name,
981+
PatKind::Binding(_, _, ident, _) => ident.name,
982982
_ => keywords::Invalid.name(),
983983
}
984984
}))

src/librustc_mir/borrow_check/mutability_errors.rs

-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,6 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
314314
if let hir::PatKind::Binding(
315315
hir::BindingAnnotation::Unannotated,
316316
_,
317-
_,
318317
upvar_ident,
319318
_,
320319
) = pat.node

src/librustc_mir/build/matches/mod.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ use crate::build::ForGuard::{self, OutsideGuard, RefWithinGuard};
1010
use crate::build::{BlockAnd, BlockAndExtension, Builder};
1111
use crate::build::{GuardFrame, GuardFrameLocal, LocalsForNode};
1212
use crate::hair::{self, *};
13+
use rustc::hir::HirId;
1314
use rustc::mir::*;
1415
use rustc::ty::{self, CanonicalUserTypeAnnotation, Ty};
1516
use rustc::ty::layout::VariantIdx;
1617
use rustc_data_structures::bit_set::BitSet;
1718
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
18-
use syntax::ast::{Name, NodeId};
19+
use syntax::ast::Name;
1920
use syntax_pos::Span;
2021

2122
// helper functions, broken out by category:
@@ -530,7 +531,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
530531
pub fn storage_live_binding(
531532
&mut self,
532533
block: BasicBlock,
533-
var: NodeId,
534+
var: HirId,
534535
span: Span,
535536
for_guard: ForGuard,
536537
) -> Place<'tcx> {
@@ -545,17 +546,15 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
545546
);
546547
let place = Place::Base(PlaceBase::Local(local_id));
547548
let var_ty = self.local_decls[local_id].ty;
548-
let hir_id = self.hir.tcx().hir().node_to_hir_id(var);
549-
let region_scope = self.hir.region_scope_tree.var_scope(hir_id.local_id);
549+
let region_scope = self.hir.region_scope_tree.var_scope(var.local_id);
550550
self.schedule_drop(span, region_scope, &place, var_ty, DropKind::Storage);
551551
place
552552
}
553553

554-
pub fn schedule_drop_for_binding(&mut self, var: NodeId, span: Span, for_guard: ForGuard) {
554+
pub fn schedule_drop_for_binding(&mut self, var: HirId, span: Span, for_guard: ForGuard) {
555555
let local_id = self.var_local_id(var, for_guard);
556556
let var_ty = self.local_decls[local_id].ty;
557-
let hir_id = self.hir.tcx().hir().node_to_hir_id(var);
558-
let region_scope = self.hir.region_scope_tree.var_scope(hir_id.local_id);
557+
let region_scope = self.hir.region_scope_tree.var_scope(var.local_id);
559558
self.schedule_drop(
560559
span,
561560
region_scope,
@@ -576,7 +575,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
576575
Mutability,
577576
Name,
578577
BindingMode,
579-
NodeId,
578+
HirId,
580579
Span,
581580
Ty<'tcx>,
582581
UserTypeProjections<'tcx>,
@@ -703,7 +702,7 @@ struct Binding<'tcx> {
703702
span: Span,
704703
source: Place<'tcx>,
705704
name: Name,
706-
var_id: NodeId,
705+
var_id: HirId,
707706
var_ty: Ty<'tcx>,
708707
mutability: Mutability,
709708
binding_mode: BindingMode,
@@ -1694,7 +1693,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
16941693
mutability: Mutability,
16951694
name: Name,
16961695
mode: BindingMode,
1697-
var_id: NodeId,
1696+
var_id: HirId,
16981697
var_ty: Ty<'tcx>,
16991698
user_ty: UserTypeProjections<'tcx>,
17001699
has_guard: ArmHasGuard,

src/librustc_mir/build/mod.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@ use rustc::mir::*;
1313
use rustc::mir::visit::{MutVisitor, TyContext};
1414
use rustc::ty::{self, Ty, TyCtxt};
1515
use rustc::ty::subst::SubstsRef;
16-
use rustc::util::nodemap::NodeMap;
16+
use rustc::util::nodemap::HirIdMap;
1717
use rustc_target::spec::PanicStrategy;
1818
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
1919
use std::mem;
2020
use std::u32;
2121
use rustc_target::spec::abi::Abi;
22-
use syntax::ast;
2322
use syntax::attr::{self, UnwindAttr};
2423
use syntax::symbol::keywords;
2524
use syntax_pos::Span;
@@ -376,7 +375,7 @@ struct Builder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
376375

377376
/// Maps `NodeId`s of variable bindings to the `Local`s created for them.
378377
/// (A match binding can have two locals; the 2nd is for the arm's guard.)
379-
var_indices: NodeMap<LocalsForNode>,
378+
var_indices: HirIdMap<LocalsForNode>,
380379
local_decls: IndexVec<Local, LocalDecl<'tcx>>,
381380
canonical_user_type_annotations: ty::CanonicalUserTypeAnnotations<'tcx>,
382381
upvar_decls: Vec<UpvarDecl>,
@@ -392,11 +391,11 @@ struct Builder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
392391
}
393392

394393
impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
395-
fn is_bound_var_in_guard(&self, id: ast::NodeId) -> bool {
394+
fn is_bound_var_in_guard(&self, id: hir::HirId) -> bool {
396395
self.guard_context.iter().any(|frame| frame.locals.iter().any(|local| local.id == id))
397396
}
398397

399-
fn var_local_id(&self, id: ast::NodeId, for_guard: ForGuard) -> Local {
398+
fn var_local_id(&self, id: hir::HirId, for_guard: ForGuard) -> Local {
400399
self.var_indices[&id].local_id(for_guard)
401400
}
402401
}
@@ -471,11 +470,11 @@ enum LocalsForNode {
471470

472471
#[derive(Debug)]
473472
struct GuardFrameLocal {
474-
id: ast::NodeId,
473+
id: hir::HirId,
475474
}
476475

477476
impl GuardFrameLocal {
478-
fn new(id: ast::NodeId, _binding_mode: BindingMode) -> Self {
477+
fn new(id: hir::HirId, _binding_mode: BindingMode) -> Self {
479478
GuardFrameLocal {
480479
id: id,
481480
}
@@ -650,7 +649,7 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
650649
mutability: Mutability::Not,
651650
};
652651
if let Some(Node::Binding(pat)) = tcx_hir.find(var_node_id) {
653-
if let hir::PatKind::Binding(_, _, _, ident, _) = pat.node {
652+
if let hir::PatKind::Binding(_, _, ident, _) = pat.node {
654653
decl.debug_name = ident.name;
655654
if let Some(&bm) = hir.tables.pat_binding_modes().get(pat.hir_id) {
656655
if bm == ty::BindByValue(hir::MutMutable) {
@@ -855,8 +854,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
855854
let mut name = None;
856855
if let Some(pat) = pattern {
857856
match pat.node {
858-
hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, _, _, ident, _)
859-
| hir::PatKind::Binding(hir::BindingAnnotation::Mutable, _, _, ident, _) => {
857+
hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, _, ident, _)
858+
| hir::PatKind::Binding(hir::BindingAnnotation::Mutable, _, ident, _) => {
860859
name = Some(ident.name);
861860
}
862861
_ => (),

src/librustc_mir/hair/cx/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ fn convert_var<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
992992
let temp_lifetime = cx.region_scope_tree.temporary_scope(expr.hir_id.local_id);
993993

994994
match def {
995-
Def::Local(id) => ExprKind::VarRef { id },
995+
Def::Local(id) => ExprKind::VarRef { id: cx.tcx.hir().node_to_hir_id(id) },
996996

997997
Def::Upvar(var_id, index, closure_expr_id) => {
998998
debug!("convert_var(upvar({:?}, {:?}, {:?}))",

src/librustc_mir/hair/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use rustc::ty::subst::SubstsRef;
1212
use rustc::ty::{AdtDef, UpvarSubsts, Ty, Const, LazyConst, UserType};
1313
use rustc::ty::layout::VariantIdx;
1414
use rustc::hir;
15-
use syntax::ast;
1615
use syntax_pos::Span;
1716
use self::cx::Cx;
1817

@@ -230,7 +229,7 @@ pub enum ExprKind<'tcx> {
230229
index: ExprRef<'tcx>,
231230
},
232231
VarRef {
233-
id: ast::NodeId,
232+
id: hir::HirId,
234233
},
235234
/// first argument, used for self in a closure
236235
SelfRef,

src/librustc_mir/hair/pattern/check_match.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> {
315315

316316
fn check_for_bindings_named_same_as_variants(cx: &MatchVisitor<'_, '_>, pat: &Pat) {
317317
pat.walk(|p| {
318-
if let PatKind::Binding(_, _, _, ident, None) = p.node {
318+
if let PatKind::Binding(_, _, ident, None) = p.node {
319319
if let Some(&bm) = cx.tables.pat_binding_modes().get(p.hir_id) {
320320
if bm != ty::BindByValue(hir::MutImmutable) {
321321
// Nothing to check.
@@ -590,7 +590,7 @@ fn check_legality_of_move_bindings(
590590

591591
for pat in pats {
592592
pat.walk(|p| {
593-
if let PatKind::Binding(_, _, _, _, ref sub) = p.node {
593+
if let PatKind::Binding(_, _, _, ref sub) = p.node {
594594
if let Some(&bm) = cx.tables.pat_binding_modes().get(p.hir_id) {
595595
match bm {
596596
ty::BindByValue(..) => {

src/librustc_mir/hair/pattern/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ pub enum PatternKind<'tcx> {
126126
mutability: Mutability,
127127
name: ast::Name,
128128
mode: BindingMode,
129-
var: ast::NodeId,
129+
var: hir::HirId,
130130
ty: Ty<'tcx>,
131131
subpattern: Option<Pattern<'tcx>>,
132132
},
@@ -559,7 +559,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
559559
}
560560
}
561561

562-
PatKind::Binding(_, id, _, ident, ref sub) => {
562+
PatKind::Binding(_, id, ident, ref sub) => {
563563
let var_ty = self.tables.node_type(pat.hir_id);
564564
if let ty::Error = var_ty.sty {
565565
// Avoid ICE
@@ -1090,7 +1090,7 @@ macro_rules! CloneImpls {
10901090
}
10911091

10921092
CloneImpls!{ <'tcx>
1093-
Span, Field, Mutability, ast::Name, ast::NodeId, usize, ty::Const<'tcx>,
1093+
Span, Field, Mutability, ast::Name, hir::HirId, usize, ty::Const<'tcx>,
10941094
Region<'tcx>, Ty<'tcx>, BindingMode, &'tcx AdtDef,
10951095
SubstsRef<'tcx>, &'tcx Kind<'tcx>, UserType<'tcx>,
10961096
UserTypeProjection<'tcx>, PatternTypeProjection<'tcx>

src/librustc_save_analysis/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
647647
Node::Binding(&hir::Pat {
648648
node: hir::PatKind::Binding(_, canonical_id, ..),
649649
..
650-
}) => HirDef::Local(canonical_id),
650+
}) => HirDef::Local(self.tcx.hir().hir_to_node_id(canonical_id)),
651651

652652
Node::Ty(ty) => if let hir::Ty {
653653
node: hir::TyKind::Path(ref qpath),

src/librustc_typeck/check/_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
227227
self.demand_eqtype_pat(pat.span, expected, rhs_ty, match_discrim_span);
228228
common_type
229229
}
230-
PatKind::Binding(ba, _, var_id, _, ref sub) => {
230+
PatKind::Binding(ba, var_id, _, ref sub) => {
231231
let bm = if ba == hir::BindingAnnotation::Unannotated {
232232
def_bm
233233
} else {

src/librustc_typeck/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for GatherLocalsVisitor<'a, 'gcx, 'tcx> {
10041004

10051005
// Add pattern bindings.
10061006
fn visit_pat(&mut self, p: &'gcx hir::Pat) {
1007-
if let PatKind::Binding(_, _, _, ident, _) = p.node {
1007+
if let PatKind::Binding(_, _, ident, _) = p.node {
10081008
let var_ty = self.assign(p.span, p.hir_id, None);
10091009

10101010
let node_id = self.fcx.tcx.hir().hir_to_node_id(p.hir_id);

0 commit comments

Comments
 (0)