Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove NodeId from Block and Expr #58698

Closed
wants to merge 12 commits into from
2 changes: 1 addition & 1 deletion src/librustc/cfg/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
args: I) -> CFGIndex {
let func_or_rcvr_exit = self.expr(func_or_rcvr, pred);
let ret = self.straightline(call_expr, func_or_rcvr_exit, args);
let m = self.tcx.hir().get_module_parent(call_expr.id);
let m = self.tcx.hir().get_module_parent_by_hir_id(call_expr.hir_id);
if self.tcx.is_ty_uninhabited_from(m, self.tables.expr_ty(call_expr)) {
self.add_unreachable_node()
} else {
Expand Down
16 changes: 5 additions & 11 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,6 @@ impl<'a> LoweringContext<'a> {
let closure_hir_id = self.lower_node_id(closure_node_id).hir_id;
let decl = self.lower_fn_decl(&decl, None, /* impl trait allowed */ false, None);
let generator = hir::Expr {
id: closure_node_id,
hir_id: closure_hir_id,
node: hir::ExprKind::Closure(capture_clause, decl, body_id, span,
Some(hir::GeneratorMovability::Static)),
Expand Down Expand Up @@ -3932,10 +3931,9 @@ impl<'a> LoweringContext<'a> {
let mut block = this.lower_block(body, true).into_inner();
let tail = block.expr.take().map_or_else(
|| {
let LoweredNodeId { node_id, hir_id } = this.next_id();
let LoweredNodeId { node_id: _, hir_id } = this.next_id();
let span = this.sess.source_map().end_point(unstable_span);
hir::Expr {
id: node_id,
span,
node: hir::ExprKind::Tup(hir_vec![]),
attrs: ThinVec::new(),
Expand Down Expand Up @@ -4120,10 +4118,9 @@ impl<'a> LoweringContext<'a> {
let struct_path = self.std_path(e.span, &struct_path, None, is_unit);
let struct_path = hir::QPath::Resolved(None, P(struct_path));

let LoweredNodeId { node_id, hir_id } = self.lower_node_id(e.id);
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(e.id);

return hir::Expr {
id: node_id,
hir_id,
node: if is_unit {
hir::ExprKind::Path(struct_path)
Expand Down Expand Up @@ -4473,9 +4470,8 @@ impl<'a> LoweringContext<'a> {
self.lower_label(opt_label),
hir::LoopSource::ForLoop,
);
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(e.id);
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(e.id);
let loop_expr = P(hir::Expr {
id: node_id,
hir_id,
node: loop_expr,
span: e.span,
Expand Down Expand Up @@ -4620,10 +4616,9 @@ impl<'a> LoweringContext<'a> {
ExprKind::Mac(_) => panic!("Shouldn't exist here"),
};

let LoweredNodeId { node_id, hir_id } = self.lower_node_id(e.id);
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(e.id);

hir::Expr {
id: node_id,
hir_id,
node: kind,
span: e.span,
Expand Down Expand Up @@ -4895,9 +4890,8 @@ impl<'a> LoweringContext<'a> {
}

fn expr(&mut self, span: Span, node: hir::ExprKind, attrs: ThinVec<Attribute>) -> hir::Expr {
let LoweredNodeId { node_id, hir_id } = self.next_id();
let LoweredNodeId { node_id: _, hir_id } = self.next_id();
hir::Expr {
id: node_id,
hir_id,
node,
span,
Expand Down
22 changes: 11 additions & 11 deletions src/librustc/hir/map/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ pub enum Code<'a> {
}

impl<'a> Code<'a> {
pub fn id(&self) -> NodeId {
pub fn id(&self) -> ast::HirId {
match *self {
Code::FnLike(node) => node.id(),
Code::Expr(block) => block.id,
Code::Expr(block) => block.hir_id,
}
}

Expand All @@ -104,7 +104,7 @@ struct ItemFnParts<'a> {
vis: &'a ast::Visibility,
generics: &'a ast::Generics,
body: ast::BodyId,
id: NodeId,
id: ast::HirId,
span: Span,
attrs: &'a [Attribute],
}
Expand All @@ -114,13 +114,13 @@ struct ItemFnParts<'a> {
struct ClosureParts<'a> {
decl: &'a FnDecl,
body: ast::BodyId,
id: NodeId,
id: ast::HirId,
span: Span,
attrs: &'a [Attribute],
}

impl<'a> ClosureParts<'a> {
fn new(d: &'a FnDecl, b: ast::BodyId, id: NodeId, s: Span, attrs: &'a [Attribute]) -> Self {
fn new(d: &'a FnDecl, b: ast::BodyId, id: ast::HirId, s: Span, attrs: &'a [Attribute]) -> Self {
ClosureParts {
decl: d,
body: b,
Expand Down Expand Up @@ -168,7 +168,7 @@ impl<'a> FnLikeNode<'a> {
|c: ClosureParts<'_>| c.span)
}

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

fn handle<A, I, M, C>(self, item_fn: I, method: M, closure: C) -> A where
I: FnOnce(ItemFnParts<'a>) -> A,
M: FnOnce(NodeId,
M: FnOnce(ast::HirId,
Ident,
&'a ast::MethodSig,
Option<&'a ast::Visibility>,
Expand All @@ -227,7 +227,7 @@ impl<'a> FnLikeNode<'a> {
map::Node::Item(i) => match i.node {
ast::ItemKind::Fn(ref decl, header, ref generics, block) =>
item_fn(ItemFnParts {
id: i.id,
id: i.hir_id,
ident: i.ident,
decl: &decl,
body: block,
Expand All @@ -241,21 +241,21 @@ impl<'a> FnLikeNode<'a> {
},
map::Node::TraitItem(ti) => match ti.node {
ast::TraitItemKind::Method(ref sig, ast::TraitMethod::Provided(body)) => {
method(ti.id, ti.ident, sig, None, body, ti.span, &ti.attrs)
method(ti.hir_id, ti.ident, sig, None, body, ti.span, &ti.attrs)
}
_ => bug!("trait method FnLikeNode that is not fn-like"),
},
map::Node::ImplItem(ii) => {
match ii.node {
ast::ImplItemKind::Method(ref sig, body) => {
method(ii.id, ii.ident, sig, Some(&ii.vis), body, ii.span, &ii.attrs)
method(ii.hir_id, ii.ident, sig, Some(&ii.vis), body, ii.span, &ii.attrs)
}
_ => bug!("impl method FnLikeNode that is not fn-like")
}
},
map::Node::Expr(e) => match e.node {
ast::ExprKind::Closure(_, ref decl, block, _fn_decl_span, _gen) =>
closure(ClosureParts::new(&decl, block, e.id, e.span, &e.attrs)),
closure(ClosureParts::new(&decl, block, e.hir_id, e.span, &e.attrs)),
_ => bug!("expr FnLikeNode that is not fn-like"),
},
_ => bug!("other FnLikeNode that is not fn-like"),
Expand Down
7 changes: 5 additions & 2 deletions src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ impl<'hir> Map<'hir> {
/// false
/// }
/// ```
pub fn get_return_block(&self, id: NodeId) -> Option<NodeId> {
pub fn get_return_block(&self, id: HirId) -> Option<HirId> {
let match_fn = |node: &Node<'_>| {
match *node {
Node::Item(_) |
Expand All @@ -822,7 +822,10 @@ impl<'hir> Map<'hir> {
}
};

self.walk_parent_nodes(id, match_fn, match_non_returning_block).ok()
let node_id = self.hir_to_node_id(id);
self.walk_parent_nodes(node_id, match_fn, match_non_returning_block)
.ok()
.map(|return_node_id| self.node_to_hir_id(return_node_id))
}

/// Retrieves the `NodeId` for `id`'s parent item, or `id` itself if no
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1333,7 +1333,6 @@ pub struct AnonConst {
/// An expression
#[derive(Clone, RustcEncodable, RustcDecodable)]
pub struct Expr {
pub id: NodeId,
pub span: Span,
pub node: ExprKind,
pub attrs: ThinVec<Attribute>,
Expand Down Expand Up @@ -1436,7 +1435,7 @@ impl Expr {

impl fmt::Debug for Expr {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "expr({}: {})", self.id,
write!(f, "expr({}: {})", self.hir_id,
print::to_string(print::NO_ANN, |s| s.print_expr(self)))
}
}
Expand Down
1 change: 0 additions & 1 deletion src/librustc/ich/impls_hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,6 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::Expr {
hasher: &mut StableHasher<W>) {
hcx.while_hashing_hir_bodies(true, |hcx| {
let hir::Expr {
id: _,
hir_id: _,
ref span,
ref node,
Expand Down
22 changes: 11 additions & 11 deletions src/librustc/lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ fn lint_levels<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, cnum: CrateNum)
};
let krate = tcx.hir().krate();

builder.with_lint_attrs(ast::CRATE_NODE_ID, &krate.attrs, |builder| {
builder.with_lint_attrs(hir::CRATE_HIR_ID, &krate.attrs, |builder| {
intravisit::walk_crate(builder, krate);
});

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

impl<'a, 'tcx> LintLevelMapBuilder<'a, 'tcx> {
fn with_lint_attrs<F>(&mut self,
id: ast::NodeId,
id: hir::HirId,
attrs: &[ast::Attribute],
f: F)
where F: FnOnce(&mut Self)
{
let push = self.levels.push(attrs);
self.levels.register_id(self.tcx.hir().definitions().node_to_hir_id(id));
self.levels.register_id(id);
f(self);
self.levels.pop(push);
}
Expand All @@ -755,25 +755,25 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for LintLevelMapBuilder<'a, 'tcx> {
}

fn visit_item(&mut self, it: &'tcx hir::Item) {
self.with_lint_attrs(it.id, &it.attrs, |builder| {
self.with_lint_attrs(it.hir_id, &it.attrs, |builder| {
intravisit::walk_item(builder, it);
});
}

fn visit_foreign_item(&mut self, it: &'tcx hir::ForeignItem) {
self.with_lint_attrs(it.id, &it.attrs, |builder| {
self.with_lint_attrs(it.hir_id, &it.attrs, |builder| {
intravisit::walk_foreign_item(builder, it);
})
}

fn visit_expr(&mut self, e: &'tcx hir::Expr) {
self.with_lint_attrs(e.id, &e.attrs, |builder| {
self.with_lint_attrs(e.hir_id, &e.attrs, |builder| {
intravisit::walk_expr(builder, e);
})
}

fn visit_struct_field(&mut self, s: &'tcx hir::StructField) {
self.with_lint_attrs(s.id, &s.attrs, |builder| {
self.with_lint_attrs(s.hir_id, &s.attrs, |builder| {
intravisit::walk_struct_field(builder, s);
})
}
Expand All @@ -782,25 +782,25 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for LintLevelMapBuilder<'a, 'tcx> {
v: &'tcx hir::Variant,
g: &'tcx hir::Generics,
item_id: hir::HirId) {
self.with_lint_attrs(v.node.data.id(), &v.node.attrs, |builder| {
self.with_lint_attrs(v.node.data.hir_id(), &v.node.attrs, |builder| {
intravisit::walk_variant(builder, v, g, item_id);
})
}

fn visit_local(&mut self, l: &'tcx hir::Local) {
self.with_lint_attrs(l.id, &l.attrs, |builder| {
self.with_lint_attrs(l.hir_id, &l.attrs, |builder| {
intravisit::walk_local(builder, l);
})
}

fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem) {
self.with_lint_attrs(trait_item.id, &trait_item.attrs, |builder| {
self.with_lint_attrs(trait_item.hir_id, &trait_item.attrs, |builder| {
intravisit::walk_trait_item(builder, trait_item);
});
}

fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem) {
self.with_lint_attrs(impl_item.id, &impl_item.attrs, |builder| {
self.with_lint_attrs(impl_item.hir_id, &impl_item.attrs, |builder| {
intravisit::walk_impl_item(builder, impl_item);
});
}
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/middle/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
}
}

fn handle_field_access(&mut self, lhs: &hir::Expr, node_id: ast::NodeId) {
fn handle_field_access(&mut self, lhs: &hir::Expr, hir_id: hir::HirId) {
match self.tables.expr_ty_adjusted(lhs).sty {
ty::Adt(def, _) => {
let index = self.tcx.field_index(node_id, self.tables);
let index = self.tcx.field_index(hir_id, self.tables);
self.insert_def_id(def.non_enum_variant().fields[index].did);
}
ty::Tuple(..) => {}
Expand All @@ -120,7 +120,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
if let PatKind::Wild = pat.node.pat.node {
continue;
}
let index = self.tcx.field_index(pat.node.id, self.tables);
let index = self.tcx.field_index(pat.node.hir_id, self.tables);
self.insert_def_id(variant.fields[index].did);
}
}
Expand Down Expand Up @@ -190,7 +190,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
fn mark_as_used_if_union(&mut self, adt: &ty::AdtDef, fields: &hir::HirVec<hir::Field>) {
if adt.is_union() && adt.non_enum_variant().fields.len() > 1 && adt.did.is_local() {
for field in fields {
let index = self.tcx.field_index(field.id, self.tables);
let index = self.tcx.field_index(field.hir_id, self.tables);
self.insert_def_id(adt.non_enum_variant().fields[index].did);
}
}
Expand Down Expand Up @@ -232,7 +232,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
self.lookup_and_handle_method(expr.hir_id);
}
hir::ExprKind::Field(ref lhs, ..) => {
self.handle_field_access(&lhs, expr.id);
self.handle_field_access(&lhs, expr.hir_id);
}
hir::ExprKind::Struct(_, ref fields, _) => {
if let ty::Adt(ref adt, _) = self.tables.expr_ty(expr).sty {
Expand Down
Loading