Skip to content

Commit 50b8bc8

Browse files
committed
hir: remove NodeId from Pat and FieldPat
1 parent 77fa041 commit 50b8bc8

File tree

17 files changed

+87
-102
lines changed

17 files changed

+87
-102
lines changed

src/librustc/hir/lowering.rs

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3740,12 +3740,11 @@ impl<'a> LoweringContext<'a> {
37403740
let fs = fields
37413741
.iter()
37423742
.map(|f| {
3743-
let LoweredNodeId { node_id, hir_id } = self.next_id();
3743+
let LoweredNodeId { node_id: _, hir_id } = self.next_id();
37443744

37453745
Spanned {
37463746
span: f.span,
37473747
node: hir::FieldPat {
3748-
id: node_id,
37493748
hir_id,
37503749
ident: f.node.ident,
37513750
pat: self.lower_pat(&f.node.pat),
@@ -3777,9 +3776,8 @@ impl<'a> LoweringContext<'a> {
37773776
PatKind::Mac(_) => panic!("Shouldn't exist here"),
37783777
};
37793778

3780-
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(p.id);
3779+
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(p.id);
37813780
P(hir::Pat {
3782-
id: node_id,
37833781
hir_id,
37843782
node,
37853783
span: p.span,
@@ -4353,7 +4351,7 @@ impl<'a> LoweringContext<'a> {
43534351
let iter = self.str_to_ident("iter");
43544352

43554353
let next_ident = self.str_to_ident("__next");
4356-
let next_pat = self.pat_ident_binding_mode(
4354+
let (next_pat, next_pat_nid) = self.pat_ident_binding_mode(
43574355
desugared_span,
43584356
next_ident,
43594357
hir::BindingAnnotation::Mutable,
@@ -4362,9 +4360,9 @@ impl<'a> LoweringContext<'a> {
43624360
// `::std::option::Option::Some(val) => next = val`
43634361
let pat_arm = {
43644362
let val_ident = self.str_to_ident("val");
4365-
let val_pat = self.pat_ident(pat.span, val_ident);
4366-
let val_expr = P(self.expr_ident(pat.span, val_ident, val_pat.id));
4367-
let next_expr = P(self.expr_ident(pat.span, next_ident, next_pat.id));
4363+
let (val_pat, val_pat_nid) = self.pat_ident(pat.span, val_ident);
4364+
let val_expr = P(self.expr_ident(pat.span, val_ident, val_pat_nid));
4365+
let next_expr = P(self.expr_ident(pat.span, next_ident, next_pat_nid));
43684366
let assign = P(self.expr(
43694367
pat.span,
43704368
hir::ExprKind::Assign(next_expr, val_expr),
@@ -4383,15 +4381,15 @@ impl<'a> LoweringContext<'a> {
43834381
};
43844382

43854383
// `mut iter`
4386-
let iter_pat = self.pat_ident_binding_mode(
4384+
let (iter_pat, iter_pat_nid) = self.pat_ident_binding_mode(
43874385
desugared_span,
43884386
iter,
43894387
hir::BindingAnnotation::Mutable
43904388
);
43914389

43924390
// `match ::std::iter::Iterator::next(&mut iter) { ... }`
43934391
let match_expr = {
4394-
let iter = P(self.expr_ident(head_sp, iter, iter_pat.id));
4392+
let iter = P(self.expr_ident(head_sp, iter, iter_pat_nid));
43954393
let ref_mut_iter = self.expr_mut_addr_of(head_sp, iter);
43964394
let next_path = &["iter", "Iterator", "next"];
43974395
let next_path = P(self.expr_std_path(head_sp, next_path, None, ThinVec::new()));
@@ -4415,7 +4413,7 @@ impl<'a> LoweringContext<'a> {
44154413
span: head_sp,
44164414
};
44174415

4418-
let next_expr = P(self.expr_ident(head_sp, next_ident, next_pat.id));
4416+
let next_expr = P(self.expr_ident(head_sp, next_ident, next_pat_nid));
44194417

44204418
// `let mut __next`
44214419
let next_let = self.stmt_let_pat(
@@ -4542,11 +4540,11 @@ impl<'a> LoweringContext<'a> {
45424540
// `Ok(val) => #[allow(unreachable_code)] val,`
45434541
let ok_arm = {
45444542
let val_ident = self.str_to_ident("val");
4545-
let val_pat = self.pat_ident(e.span, val_ident);
4543+
let (val_pat, val_pat_nid) = self.pat_ident(e.span, val_ident);
45464544
let val_expr = P(self.expr_ident_with_attrs(
45474545
e.span,
45484546
val_ident,
4549-
val_pat.id,
4547+
val_pat_nid,
45504548
ThinVec::from(attrs.clone()),
45514549
));
45524550
let ok_pat = self.pat_ok(e.span, val_pat);
@@ -4558,12 +4556,12 @@ impl<'a> LoweringContext<'a> {
45584556
// return Try::from_error(From::from(err)),`
45594557
let err_arm = {
45604558
let err_ident = self.str_to_ident("err");
4561-
let err_local = self.pat_ident(e.span, err_ident);
4559+
let (err_local, err_local_nid) = self.pat_ident(e.span, err_ident);
45624560
let from_expr = {
45634561
let path = &["convert", "From", "from"];
45644562
let from = P(self.expr_std_path(
45654563
e.span, path, None, ThinVec::new()));
4566-
let err_expr = self.expr_ident(e.span, err_ident, err_local.id);
4564+
let err_expr = self.expr_ident(e.span, err_ident, err_local_nid);
45674565

45684566
self.expr_call(e.span, from, hir_vec![err_expr])
45694567
};
@@ -4911,15 +4909,15 @@ impl<'a> LoweringContext<'a> {
49114909
ident: Ident,
49124910
ex: P<hir::Expr>,
49134911
) -> (hir::Stmt, NodeId) {
4914-
let pat = if mutbl {
4912+
let (pat, pat_nid) = if mutbl {
49154913
self.pat_ident_binding_mode(sp, ident, hir::BindingAnnotation::Mutable)
49164914
} else {
49174915
self.pat_ident(sp, ident)
49184916
};
4919-
let pat_id = pat.id;
4917+
49204918
(
49214919
self.stmt_let_pat(sp, Some(ex), pat, hir::LocalSource::Normal),
4922-
pat_id,
4920+
pat_nid,
49234921
)
49244922
}
49254923

@@ -4977,7 +4975,7 @@ impl<'a> LoweringContext<'a> {
49774975
self.pat(span, pt)
49784976
}
49794977

4980-
fn pat_ident(&mut self, span: Span, ident: Ident) -> P<hir::Pat> {
4978+
fn pat_ident(&mut self, span: Span, ident: Ident) -> (P<hir::Pat>, NodeId) {
49814979
self.pat_ident_binding_mode(span, ident, hir::BindingAnnotation::Unannotated)
49824980
}
49834981

@@ -4986,25 +4984,26 @@ impl<'a> LoweringContext<'a> {
49864984
span: Span,
49874985
ident: Ident,
49884986
bm: hir::BindingAnnotation,
4989-
) -> P<hir::Pat> {
4987+
) -> (P<hir::Pat>, NodeId) {
49904988
let LoweredNodeId { node_id, hir_id } = self.next_id();
49914989

4992-
P(hir::Pat {
4993-
id: node_id,
4994-
hir_id,
4995-
node: hir::PatKind::Binding(bm, node_id, hir_id, ident.with_span_pos(span), None),
4996-
span,
4997-
})
4990+
(
4991+
P(hir::Pat {
4992+
hir_id,
4993+
node: hir::PatKind::Binding(bm, node_id, hir_id, ident.with_span_pos(span), None),
4994+
span,
4995+
}),
4996+
node_id
4997+
)
49984998
}
49994999

50005000
fn pat_wild(&mut self, span: Span) -> P<hir::Pat> {
50015001
self.pat(span, hir::PatKind::Wild)
50025002
}
50035003

50045004
fn pat(&mut self, span: Span, pat: hir::PatKind) -> P<hir::Pat> {
5005-
let LoweredNodeId { node_id, hir_id } = self.next_id();
5005+
let LoweredNodeId { node_id: _, hir_id } = self.next_id();
50065006
P(hir::Pat {
5007-
id: node_id,
50085007
hir_id,
50095008
node: pat,
50105009
span,

src/librustc/hir/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -834,15 +834,14 @@ pub struct Block {
834834

835835
#[derive(Clone, RustcEncodable, RustcDecodable)]
836836
pub struct Pat {
837-
pub id: NodeId,
838837
pub hir_id: HirId,
839838
pub node: PatKind,
840839
pub span: Span,
841840
}
842841

843842
impl fmt::Debug for Pat {
844843
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
845-
write!(f, "pat({}: {})", self.id,
844+
write!(f, "pat({}: {})", self.hir_id,
846845
print::to_string(print::NO_ANN, |s| s.print_pat(self)))
847846
}
848847
}
@@ -897,7 +896,6 @@ impl Pat {
897896
/// except `is_shorthand` is true.
898897
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
899898
pub struct FieldPat {
900-
pub id: NodeId,
901899
pub hir_id: HirId,
902900
/// The identifier for the field.
903901
pub ident: Ident,

src/librustc/ich/impls_hir.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,6 @@ impl_stable_hash_for!(struct hir::Block {
421421
});
422422

423423
impl_stable_hash_for!(struct hir::Pat {
424-
id -> _,
425424
hir_id -> _,
426425
node,
427426
span,
@@ -430,7 +429,6 @@ impl_stable_hash_for!(struct hir::Pat {
430429
impl_stable_hash_for_spanned!(hir::FieldPat);
431430

432431
impl_stable_hash_for!(struct hir::FieldPat {
433-
id -> _,
434432
hir_id -> _,
435433
ident -> (ident.name),
436434
pat,

src/librustc/middle/expr_use_visitor.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use crate::ty::{self, TyCtxt, adjustment};
1919
use crate::hir::{self, PatKind};
2020
use rustc_data_structures::sync::Lrc;
2121
use std::rc::Rc;
22-
use syntax::ast;
2322
use syntax::ptr::P;
2423
use syntax_pos::Span;
2524
use crate::util::nodemap::ItemLocalSet;
@@ -74,7 +73,7 @@ pub trait Delegate<'tcx> {
7473

7574
// The local variable `id` is declared but not initialized.
7675
fn decl_without_init(&mut self,
77-
id: ast::NodeId,
76+
id: hir::HirId,
7877
span: Span);
7978

8079
// The path at `cmt` is being assigned to.
@@ -609,8 +608,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
609608
match local.init {
610609
None => {
611610
local.pat.each_binding(|_, hir_id, span, _| {
612-
let node_id = self.mc.tcx.hir().hir_to_node_id(hir_id);
613-
self.delegate.decl_without_init(node_id, span);
611+
self.delegate.decl_without_init(hir_id, span);
614612
})
615613
}
616614

src/librustc/middle/mem_categorization.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub enum Categorization<'tcx> {
8888
ThreadLocal(ty::Region<'tcx>), // value that cannot move, but still restricted in scope
8989
StaticItem,
9090
Upvar(Upvar), // upvar referenced by closure env
91-
Local(ast::NodeId), // local variable
91+
Local(hir::HirId), // local variable
9292
Deref(cmt<'tcx>, PointerKind<'tcx>), // deref of a ptr
9393
Interior(cmt<'tcx>, InteriorKind), // something interior: field, tuple, etc
9494
Downcast(cmt<'tcx>, DefId), // selects a particular enum variant (*1)
@@ -198,9 +198,9 @@ pub struct cmt_<'tcx> {
198198
pub type cmt<'tcx> = Rc<cmt_<'tcx>>;
199199

200200
pub enum ImmutabilityBlame<'tcx> {
201-
ImmLocal(ast::NodeId),
201+
ImmLocal(hir::HirId),
202202
ClosureEnv(LocalDefId),
203-
LocalDeref(ast::NodeId),
203+
LocalDeref(hir::HirId),
204204
AdtFieldDeref(&'tcx ty::AdtDef, &'tcx ty::FieldDef)
205205
}
206206

@@ -230,8 +230,8 @@ impl<'tcx> cmt_<'tcx> {
230230
Categorization::Deref(ref base_cmt, BorrowedPtr(ty::ImmBorrow, _)) => {
231231
// try to figure out where the immutable reference came from
232232
match base_cmt.cat {
233-
Categorization::Local(node_id) =>
234-
Some(ImmutabilityBlame::LocalDeref(node_id)),
233+
Categorization::Local(hir_id) =>
234+
Some(ImmutabilityBlame::LocalDeref(hir_id)),
235235
Categorization::Interior(ref base_cmt, InteriorField(field_index)) => {
236236
base_cmt.resolve_field(field_index.0).map(|(adt_def, field_def)| {
237237
ImmutabilityBlame::AdtFieldDeref(adt_def, field_def)
@@ -247,8 +247,8 @@ impl<'tcx> cmt_<'tcx> {
247247
_ => None
248248
}
249249
}
250-
Categorization::Local(node_id) => {
251-
Some(ImmutabilityBlame::ImmLocal(node_id))
250+
Categorization::Local(hir_id) => {
251+
Some(ImmutabilityBlame::ImmLocal(hir_id))
252252
}
253253
Categorization::Rvalue(..) |
254254
Categorization::Upvar(..) |
@@ -741,7 +741,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
741741
Ok(cmt_ {
742742
hir_id,
743743
span,
744-
cat: Categorization::Local(vid),
744+
cat: Categorization::Local(self.tcx.hir().node_to_hir_id(vid)),
745745
mutbl: MutabilityCategory::from_local(self.tcx, self.tables, vid),
746746
ty: expr_ty,
747747
note: NoteNone
@@ -1495,7 +1495,7 @@ impl<'tcx> cmt_<'tcx> {
14951495
"non-place".into()
14961496
}
14971497
Categorization::Local(vid) => {
1498-
if tcx.hir().is_argument(vid) {
1498+
if tcx.hir().is_argument(tcx.hir().hir_to_node_id(vid)) {
14991499
"argument"
15001500
} else {
15011501
"local variable"

src/librustc/middle/resolve_lifetime.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2397,7 +2397,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
23972397

23982398
let help_name = if let Some(body) = parent {
23992399
let arg = &self.tcx.hir().body(body).arguments[index];
2400-
format!("`{}`", self.tcx.hir().node_to_pretty_string(arg.pat.id))
2400+
format!("`{}`", self.tcx.hir().hir_to_pretty_string(arg.pat.hir_id))
24012401
} else {
24022402
format!("argument {}", index + 1)
24032403
};

src/librustc_borrowck/borrowck/check_loans.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use rustc::middle::mem_categorization as mc;
1717
use rustc::middle::mem_categorization::Categorization;
1818
use rustc::middle::region;
1919
use rustc::ty::{self, TyCtxt, RegionKind};
20-
use syntax::ast;
2120
use syntax_pos::Span;
2221
use rustc::hir;
2322
use rustc::hir::Node;
@@ -177,7 +176,7 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for CheckLoanCtxt<'a, 'tcx> {
177176
self.check_assignment(assignment_id.local_id, assignment_span, assignee_cmt);
178177
}
179178

180-
fn decl_without_init(&mut self, _id: ast::NodeId, _span: Span) { }
179+
fn decl_without_init(&mut self, _id: hir::HirId, _span: Span) { }
181180
}
182181

183182
pub fn check_loans<'a, 'b, 'c, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
@@ -887,11 +886,10 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
887886
// Check for reassignments to (immutable) local variables. This
888887
// needs to be done here instead of in check_loans because we
889888
// depend on move data.
890-
if let Categorization::Local(local_id) = assignee_cmt.cat {
889+
if let Categorization::Local(hir_id) = assignee_cmt.cat {
891890
let lp = opt_loan_path(assignee_cmt).unwrap();
892891
self.move_data.each_assignment_of(assignment_id, &lp, |assign| {
893892
if assignee_cmt.mutbl.is_mutable() {
894-
let hir_id = self.bccx.tcx.hir().node_to_hir_id(local_id);
895893
self.bccx.used_mut_nodes.borrow_mut().insert(hir_id);
896894
} else {
897895
self.bccx.report_reassigned_immutable_variable(

src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use rustc::middle::mem_categorization::InteriorOffsetKind as Kind;
1111
use rustc::ty::{self, Ty};
1212

1313
use std::rc::Rc;
14-
use syntax::ast;
1514
use syntax_pos::Span;
1615
use rustc::hir::*;
1716
use rustc::hir::Node;
@@ -48,9 +47,9 @@ pub enum PatternSource<'tcx> {
4847
/// with a reference to the let
4948
fn get_pattern_source<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, pat: &Pat) -> PatternSource<'tcx> {
5049

51-
let parent = tcx.hir().get_parent_node(pat.id);
50+
let parent = tcx.hir().get_parent_node_by_hir_id(pat.hir_id);
5251

53-
match tcx.hir().get(parent) {
52+
match tcx.hir().get_by_hir_id(parent) {
5453
Node::Expr(ref e) => {
5554
// the enclosing expression must be a `match` or something else
5655
assert!(match e.node {
@@ -67,11 +66,10 @@ fn get_pattern_source<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, pat: &Pat) -> Patte
6766

6867
pub fn gather_decl<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
6968
move_data: &MoveData<'tcx>,
70-
var_id: ast::NodeId,
69+
var_id: hir::HirId,
7170
var_ty: Ty<'tcx>) {
7271
let loan_path = Rc::new(LoanPath::new(LpVar(var_id), var_ty));
73-
let hir_id = bccx.tcx.hir().node_to_hir_id(var_id);
74-
move_data.add_move(bccx.tcx, loan_path, hir_id.local_id, Declared);
72+
move_data.add_move(bccx.tcx, loan_path, var_id.local_id, Declared);
7573
}
7674

7775
pub fn gather_move_from_expr<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,

src/librustc_borrowck/borrowck/gather_loans/lifetime.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ impl<'a, 'tcx> GuaranteeLifetimeContext<'a, 'tcx> {
104104
Categorization::Upvar(..) => {
105105
self.bccx.tcx.mk_region(ty::ReScope(self.item_scope))
106106
}
107-
Categorization::Local(local_id) => {
108-
let hir_id = self.bccx.tcx.hir().node_to_hir_id(local_id);
107+
Categorization::Local(hir_id) => {
109108
self.bccx.tcx.mk_region(ty::ReScope(
110109
self.bccx.region_scope_tree.var_scope(hir_id.local_id)))
111110
}

0 commit comments

Comments
 (0)