Skip to content

Commit d7ced1d

Browse files
committed
hir: remove NodeId from Expr
1 parent 021a140 commit d7ced1d

File tree

44 files changed

+307
-305
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+307
-305
lines changed

src/librustc/cfg/construct.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
398398
args: I) -> CFGIndex {
399399
let func_or_rcvr_exit = self.expr(func_or_rcvr, pred);
400400
let ret = self.straightline(call_expr, func_or_rcvr_exit, args);
401-
let m = self.tcx.hir().get_module_parent(call_expr.id);
401+
let m = self.tcx.hir().get_module_parent_by_hir_id(call_expr.hir_id);
402402
if self.tcx.is_ty_uninhabited_from(m, self.tables.expr_ty(call_expr)) {
403403
self.add_unreachable_node()
404404
} else {

src/librustc/hir/lowering.rs

+5-11
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,6 @@ impl<'a> LoweringContext<'a> {
963963
let closure_hir_id = self.lower_node_id(closure_node_id).hir_id;
964964
let decl = self.lower_fn_decl(&decl, None, /* impl trait allowed */ false, None);
965965
let generator = hir::Expr {
966-
id: closure_node_id,
967966
hir_id: closure_hir_id,
968967
node: hir::ExprKind::Closure(capture_clause, decl, body_id, span,
969968
Some(hir::GeneratorMovability::Static)),
@@ -3932,10 +3931,9 @@ impl<'a> LoweringContext<'a> {
39323931
let mut block = this.lower_block(body, true).into_inner();
39333932
let tail = block.expr.take().map_or_else(
39343933
|| {
3935-
let LoweredNodeId { node_id, hir_id } = this.next_id();
3934+
let LoweredNodeId { node_id: _, hir_id } = this.next_id();
39363935
let span = this.sess.source_map().end_point(unstable_span);
39373936
hir::Expr {
3938-
id: node_id,
39393937
span,
39403938
node: hir::ExprKind::Tup(hir_vec![]),
39413939
attrs: ThinVec::new(),
@@ -4120,10 +4118,9 @@ impl<'a> LoweringContext<'a> {
41204118
let struct_path = self.std_path(e.span, &struct_path, None, is_unit);
41214119
let struct_path = hir::QPath::Resolved(None, P(struct_path));
41224120

4123-
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(e.id);
4121+
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(e.id);
41244122

41254123
return hir::Expr {
4126-
id: node_id,
41274124
hir_id,
41284125
node: if is_unit {
41294126
hir::ExprKind::Path(struct_path)
@@ -4473,9 +4470,8 @@ impl<'a> LoweringContext<'a> {
44734470
self.lower_label(opt_label),
44744471
hir::LoopSource::ForLoop,
44754472
);
4476-
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(e.id);
4473+
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(e.id);
44774474
let loop_expr = P(hir::Expr {
4478-
id: node_id,
44794475
hir_id,
44804476
node: loop_expr,
44814477
span: e.span,
@@ -4620,10 +4616,9 @@ impl<'a> LoweringContext<'a> {
46204616
ExprKind::Mac(_) => panic!("Shouldn't exist here"),
46214617
};
46224618

4623-
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(e.id);
4619+
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(e.id);
46244620

46254621
hir::Expr {
4626-
id: node_id,
46274622
hir_id,
46284623
node: kind,
46294624
span: e.span,
@@ -4895,9 +4890,8 @@ impl<'a> LoweringContext<'a> {
48954890
}
48964891

48974892
fn expr(&mut self, span: Span, node: hir::ExprKind, attrs: ThinVec<Attribute>) -> hir::Expr {
4898-
let LoweredNodeId { node_id, hir_id } = self.next_id();
4893+
let LoweredNodeId { node_id: _, hir_id } = self.next_id();
48994894
hir::Expr {
4900-
id: node_id,
49014895
hir_id,
49024896
node,
49034897
span,

src/librustc/hir/map/blocks.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ pub enum Code<'a> {
7575
}
7676

7777
impl<'a> Code<'a> {
78-
pub fn id(&self) -> NodeId {
78+
pub fn id(&self) -> ast::HirId {
7979
match *self {
8080
Code::FnLike(node) => node.id(),
81-
Code::Expr(block) => block.id,
81+
Code::Expr(block) => block.hir_id,
8282
}
8383
}
8484

@@ -104,7 +104,7 @@ struct ItemFnParts<'a> {
104104
vis: &'a ast::Visibility,
105105
generics: &'a ast::Generics,
106106
body: ast::BodyId,
107-
id: NodeId,
107+
id: ast::HirId,
108108
span: Span,
109109
attrs: &'a [Attribute],
110110
}
@@ -114,13 +114,13 @@ struct ItemFnParts<'a> {
114114
struct ClosureParts<'a> {
115115
decl: &'a FnDecl,
116116
body: ast::BodyId,
117-
id: NodeId,
117+
id: ast::HirId,
118118
span: Span,
119119
attrs: &'a [Attribute],
120120
}
121121

122122
impl<'a> ClosureParts<'a> {
123-
fn new(d: &'a FnDecl, b: ast::BodyId, id: NodeId, s: Span, attrs: &'a [Attribute]) -> Self {
123+
fn new(d: &'a FnDecl, b: ast::BodyId, id: ast::HirId, s: Span, attrs: &'a [Attribute]) -> Self {
124124
ClosureParts {
125125
decl: d,
126126
body: b,
@@ -168,7 +168,7 @@ impl<'a> FnLikeNode<'a> {
168168
|c: ClosureParts<'_>| c.span)
169169
}
170170

171-
pub fn id(self) -> NodeId {
171+
pub fn id(self) -> ast::HirId {
172172
self.handle(|i: ItemFnParts<'_>| i.id,
173173
|id, _, _: &'a ast::MethodSig, _, _, _, _| id,
174174
|c: ClosureParts<'_>| c.id)
@@ -213,7 +213,7 @@ impl<'a> FnLikeNode<'a> {
213213

214214
fn handle<A, I, M, C>(self, item_fn: I, method: M, closure: C) -> A where
215215
I: FnOnce(ItemFnParts<'a>) -> A,
216-
M: FnOnce(NodeId,
216+
M: FnOnce(ast::HirId,
217217
Ident,
218218
&'a ast::MethodSig,
219219
Option<&'a ast::Visibility>,
@@ -227,7 +227,7 @@ impl<'a> FnLikeNode<'a> {
227227
map::Node::Item(i) => match i.node {
228228
ast::ItemKind::Fn(ref decl, header, ref generics, block) =>
229229
item_fn(ItemFnParts {
230-
id: i.id,
230+
id: i.hir_id,
231231
ident: i.ident,
232232
decl: &decl,
233233
body: block,
@@ -241,21 +241,21 @@ impl<'a> FnLikeNode<'a> {
241241
},
242242
map::Node::TraitItem(ti) => match ti.node {
243243
ast::TraitItemKind::Method(ref sig, ast::TraitMethod::Provided(body)) => {
244-
method(ti.id, ti.ident, sig, None, body, ti.span, &ti.attrs)
244+
method(ti.hir_id, ti.ident, sig, None, body, ti.span, &ti.attrs)
245245
}
246246
_ => bug!("trait method FnLikeNode that is not fn-like"),
247247
},
248248
map::Node::ImplItem(ii) => {
249249
match ii.node {
250250
ast::ImplItemKind::Method(ref sig, body) => {
251-
method(ii.id, ii.ident, sig, Some(&ii.vis), body, ii.span, &ii.attrs)
251+
method(ii.hir_id, ii.ident, sig, Some(&ii.vis), body, ii.span, &ii.attrs)
252252
}
253253
_ => bug!("impl method FnLikeNode that is not fn-like")
254254
}
255255
},
256256
map::Node::Expr(e) => match e.node {
257257
ast::ExprKind::Closure(_, ref decl, block, _fn_decl_span, _gen) =>
258-
closure(ClosureParts::new(&decl, block, e.id, e.span, &e.attrs)),
258+
closure(ClosureParts::new(&decl, block, e.hir_id, e.span, &e.attrs)),
259259
_ => bug!("expr FnLikeNode that is not fn-like"),
260260
},
261261
_ => bug!("other FnLikeNode that is not fn-like"),

src/librustc/hir/map/mod.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ impl<'hir> Map<'hir> {
799799
/// false
800800
/// }
801801
/// ```
802-
pub fn get_return_block(&self, id: NodeId) -> Option<NodeId> {
802+
pub fn get_return_block(&self, id: HirId) -> Option<HirId> {
803803
let match_fn = |node: &Node<'_>| {
804804
match *node {
805805
Node::Item(_) |
@@ -822,7 +822,10 @@ impl<'hir> Map<'hir> {
822822
}
823823
};
824824

825-
self.walk_parent_nodes(id, match_fn, match_non_returning_block).ok()
825+
let node_id = self.hir_to_node_id(id);
826+
self.walk_parent_nodes(node_id, match_fn, match_non_returning_block)
827+
.ok()
828+
.map(|return_node_id| self.node_to_hir_id(return_node_id))
826829
}
827830

828831
/// Retrieves the `NodeId` for `id`'s parent item, or `id` itself if no

src/librustc/hir/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,6 @@ pub struct AnonConst {
13331333
/// An expression
13341334
#[derive(Clone, RustcEncodable, RustcDecodable)]
13351335
pub struct Expr {
1336-
pub id: NodeId,
13371336
pub span: Span,
13381337
pub node: ExprKind,
13391338
pub attrs: ThinVec<Attribute>,
@@ -1436,7 +1435,7 @@ impl Expr {
14361435

14371436
impl fmt::Debug for Expr {
14381437
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1439-
write!(f, "expr({}: {})", self.id,
1438+
write!(f, "expr({}: {})", self.hir_id,
14401439
print::to_string(print::NO_ANN, |s| s.print_expr(self)))
14411440
}
14421441
}

src/librustc/ich/impls_hir.rs

-1
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,6 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::Expr {
559559
hasher: &mut StableHasher<W>) {
560560
hcx.while_hashing_hir_bodies(true, |hcx| {
561561
let hir::Expr {
562-
id: _,
563562
hir_id: _,
564563
ref span,
565564
ref node,

src/librustc/lint/mod.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ fn lint_levels<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, cnum: CrateNum)
723723
};
724724
let krate = tcx.hir().krate();
725725

726-
builder.with_lint_attrs(ast::CRATE_NODE_ID, &krate.attrs, |builder| {
726+
builder.with_lint_attrs(hir::CRATE_HIR_ID, &krate.attrs, |builder| {
727727
intravisit::walk_crate(builder, krate);
728728
});
729729

@@ -737,13 +737,13 @@ struct LintLevelMapBuilder<'a, 'tcx: 'a> {
737737

738738
impl<'a, 'tcx> LintLevelMapBuilder<'a, 'tcx> {
739739
fn with_lint_attrs<F>(&mut self,
740-
id: ast::NodeId,
740+
id: hir::HirId,
741741
attrs: &[ast::Attribute],
742742
f: F)
743743
where F: FnOnce(&mut Self)
744744
{
745745
let push = self.levels.push(attrs);
746-
self.levels.register_id(self.tcx.hir().definitions().node_to_hir_id(id));
746+
self.levels.register_id(id);
747747
f(self);
748748
self.levels.pop(push);
749749
}
@@ -755,25 +755,25 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for LintLevelMapBuilder<'a, 'tcx> {
755755
}
756756

757757
fn visit_item(&mut self, it: &'tcx hir::Item) {
758-
self.with_lint_attrs(it.id, &it.attrs, |builder| {
758+
self.with_lint_attrs(it.hir_id, &it.attrs, |builder| {
759759
intravisit::walk_item(builder, it);
760760
});
761761
}
762762

763763
fn visit_foreign_item(&mut self, it: &'tcx hir::ForeignItem) {
764-
self.with_lint_attrs(it.id, &it.attrs, |builder| {
764+
self.with_lint_attrs(it.hir_id, &it.attrs, |builder| {
765765
intravisit::walk_foreign_item(builder, it);
766766
})
767767
}
768768

769769
fn visit_expr(&mut self, e: &'tcx hir::Expr) {
770-
self.with_lint_attrs(e.id, &e.attrs, |builder| {
770+
self.with_lint_attrs(e.hir_id, &e.attrs, |builder| {
771771
intravisit::walk_expr(builder, e);
772772
})
773773
}
774774

775775
fn visit_struct_field(&mut self, s: &'tcx hir::StructField) {
776-
self.with_lint_attrs(s.id, &s.attrs, |builder| {
776+
self.with_lint_attrs(s.hir_id, &s.attrs, |builder| {
777777
intravisit::walk_struct_field(builder, s);
778778
})
779779
}
@@ -782,25 +782,25 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for LintLevelMapBuilder<'a, 'tcx> {
782782
v: &'tcx hir::Variant,
783783
g: &'tcx hir::Generics,
784784
item_id: hir::HirId) {
785-
self.with_lint_attrs(v.node.data.id(), &v.node.attrs, |builder| {
785+
self.with_lint_attrs(v.node.data.hir_id(), &v.node.attrs, |builder| {
786786
intravisit::walk_variant(builder, v, g, item_id);
787787
})
788788
}
789789

790790
fn visit_local(&mut self, l: &'tcx hir::Local) {
791-
self.with_lint_attrs(l.id, &l.attrs, |builder| {
791+
self.with_lint_attrs(l.hir_id, &l.attrs, |builder| {
792792
intravisit::walk_local(builder, l);
793793
})
794794
}
795795

796796
fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem) {
797-
self.with_lint_attrs(trait_item.id, &trait_item.attrs, |builder| {
797+
self.with_lint_attrs(trait_item.hir_id, &trait_item.attrs, |builder| {
798798
intravisit::walk_trait_item(builder, trait_item);
799799
});
800800
}
801801

802802
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem) {
803-
self.with_lint_attrs(impl_item.id, &impl_item.attrs, |builder| {
803+
self.with_lint_attrs(impl_item.hir_id, &impl_item.attrs, |builder| {
804804
intravisit::walk_impl_item(builder, impl_item);
805805
});
806806
}

src/librustc/middle/dead.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
9999
}
100100
}
101101

102-
fn handle_field_access(&mut self, lhs: &hir::Expr, node_id: ast::NodeId) {
102+
fn handle_field_access(&mut self, lhs: &hir::Expr, hir_id: hir::HirId) {
103103
match self.tables.expr_ty_adjusted(lhs).sty {
104104
ty::Adt(def, _) => {
105-
let index = self.tcx.field_index(node_id, self.tables);
105+
let index = self.tcx.field_index(hir_id, self.tables);
106106
self.insert_def_id(def.non_enum_variant().fields[index].did);
107107
}
108108
ty::Tuple(..) => {}
@@ -120,7 +120,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
120120
if let PatKind::Wild = pat.node.pat.node {
121121
continue;
122122
}
123-
let index = self.tcx.field_index(pat.node.id, self.tables);
123+
let index = self.tcx.field_index(pat.node.hir_id, self.tables);
124124
self.insert_def_id(variant.fields[index].did);
125125
}
126126
}
@@ -190,7 +190,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
190190
fn mark_as_used_if_union(&mut self, adt: &ty::AdtDef, fields: &hir::HirVec<hir::Field>) {
191191
if adt.is_union() && adt.non_enum_variant().fields.len() > 1 && adt.did.is_local() {
192192
for field in fields {
193-
let index = self.tcx.field_index(field.id, self.tables);
193+
let index = self.tcx.field_index(field.hir_id, self.tables);
194194
self.insert_def_id(adt.non_enum_variant().fields[index].did);
195195
}
196196
}
@@ -232,7 +232,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
232232
self.lookup_and_handle_method(expr.hir_id);
233233
}
234234
hir::ExprKind::Field(ref lhs, ..) => {
235-
self.handle_field_access(&lhs, expr.id);
235+
self.handle_field_access(&lhs, expr.hir_id);
236236
}
237237
hir::ExprKind::Struct(_, ref fields, _) => {
238238
if let ty::Adt(ref adt, _) = self.tables.expr_ty(expr).sty {

0 commit comments

Comments
 (0)