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 some HIR nodes #58561

Merged
merged 13 commits into from
Feb 26, 2019
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
71 changes: 23 additions & 48 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,6 @@ impl<'a> LoweringContext<'a> {
);

hir::GenericParam {
id: node_id,
hir_id,
name: hir_name,
attrs: hir_vec![],
Expand Down Expand Up @@ -964,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 @@ -1300,7 +1298,6 @@ impl<'a> LoweringContext<'a> {
// Set the name to `impl Bound1 + Bound2`.
let ident = Ident::from_str(&pprust::ty_to_string(t)).with_span_pos(span);
in_band_ty_params.push(hir::GenericParam {
id: def_node_id,
hir_id,
name: ParamName::Plain(ident),
pure_wrt_drop: false,
Expand Down Expand Up @@ -1350,9 +1347,8 @@ impl<'a> LoweringContext<'a> {
TyKind::Mac(_) => panic!("TyMac should have been expanded by now."),
};

let LoweredNodeId { node_id, hir_id } = self.lower_node_id(t.id);
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(t.id);
hir::Ty {
id: node_id,
node: kind,
span: t.span,
hir_id,
Expand Down Expand Up @@ -1394,12 +1390,11 @@ impl<'a> LoweringContext<'a> {
);

self.with_hir_id_owner(exist_ty_node_id, |lctx| {
let LoweredNodeId { node_id, hir_id } = lctx.next_id();
let LoweredNodeId { node_id: _, hir_id } = lctx.next_id();
let exist_ty_item_kind = hir::ItemKind::Existential(hir::ExistTy {
generics: hir::Generics {
params: lifetime_defs,
where_clause: hir::WhereClause {
id: node_id,
hir_id,
predicates: Vec::new().into(),
},
Expand Down Expand Up @@ -1533,9 +1528,8 @@ impl<'a> LoweringContext<'a> {
&& !self.already_defined_lifetimes.contains(&name) {
self.already_defined_lifetimes.insert(name);

let LoweredNodeId { node_id, hir_id } = self.context.next_id();
let LoweredNodeId { node_id: _, hir_id } = self.context.next_id();
self.output_lifetimes.push(hir::GenericArg::Lifetime(hir::Lifetime {
id: node_id,
hir_id,
span: lifetime.span,
name,
Expand Down Expand Up @@ -1569,7 +1563,6 @@ impl<'a> LoweringContext<'a> {
};

self.output_lifetime_params.push(hir::GenericParam {
id: def_node_id,
hir_id,
name,
span: lifetime.span,
Expand Down Expand Up @@ -1980,8 +1973,8 @@ impl<'a> LoweringContext<'a> {
.map(|ty| this.lower_ty_direct(ty, ImplTraitContext::disallowed()))
.collect();
let mk_tup = |this: &mut Self, tys, span| {
let LoweredNodeId { node_id, hir_id } = this.next_id();
hir::Ty { node: hir::TyKind::Tup(tys), id: node_id, hir_id, span }
let LoweredNodeId { node_id: _, hir_id } = this.next_id();
hir::Ty { node: hir::TyKind::Tup(tys), hir_id, span }
};
let LoweredNodeId { node_id, hir_id } = this.next_id();

Expand Down Expand Up @@ -2318,9 +2311,8 @@ impl<'a> LoweringContext<'a> {
this.lower_ty(ty, ImplTraitContext::Existential(Some(fn_def_id)))
}
FunctionRetTy::Default(span) => {
let LoweredNodeId { node_id, hir_id } = this.next_id();
let LoweredNodeId { node_id: _, hir_id } = this.next_id();
P(hir::Ty {
id: node_id,
hir_id,
node: hir::TyKind::Tup(hir_vec![]),
span: *span,
Expand Down Expand Up @@ -2362,17 +2354,16 @@ impl<'a> LoweringContext<'a> {
];

if let Some((name, span)) = bound_lifetime {
let LoweredNodeId { node_id, hir_id } = this.next_id();
let LoweredNodeId { node_id: _, hir_id } = this.next_id();
bounds.push(hir::GenericBound::Outlives(
hir::Lifetime { id: node_id, hir_id, name, span }));
hir::Lifetime { hir_id, name, span }));
}

hir::HirVec::from(bounds)
});

let LoweredNodeId { node_id, hir_id } = self.next_id();
let LoweredNodeId { node_id: _, hir_id } = self.next_id();
let impl_trait_ty = P(hir::Ty {
id: node_id,
node: impl_trait_ty,
span,
hir_id,
Expand Down Expand Up @@ -2431,10 +2422,9 @@ impl<'a> LoweringContext<'a> {
span: Span,
name: hir::LifetimeName,
) -> hir::Lifetime {
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(id);
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(id);

hir::Lifetime {
id: node_id,
hir_id,
span,
name: name,
Expand Down Expand Up @@ -2524,10 +2514,9 @@ impl<'a> LoweringContext<'a> {
}
};

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

hir::GenericParam {
id: node_id,
hir_id,
name,
span: param.ident.span,
Expand Down Expand Up @@ -2608,10 +2597,9 @@ impl<'a> LoweringContext<'a> {
self.with_anonymous_lifetime_mode(
AnonymousLifetimeMode::ReportError,
|this| {
let LoweredNodeId { node_id, hir_id } = this.lower_node_id(wc.id);
let LoweredNodeId { node_id: _, hir_id } = this.lower_node_id(wc.id);

hir::WhereClause {
id: node_id,
hir_id,
predicates: wc.predicates
.iter()
Expand Down Expand Up @@ -2672,10 +2660,9 @@ impl<'a> LoweringContext<'a> {
ref rhs_ty,
span,
}) => {
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(id);
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(id);

hir::WherePredicate::EqPredicate(hir::WhereEqPredicate {
id: node_id,
hir_id,
lhs_ty: self.lower_ty(lhs_ty, ImplTraitContext::disallowed()),
rhs_ty: self.lower_ty(rhs_ty, ImplTraitContext::disallowed()),
Expand Down Expand Up @@ -2816,10 +2803,9 @@ impl<'a> LoweringContext<'a> {
}
}

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

P(hir::Block {
id: node_id,
hir_id,
stmts: stmts.into(),
expr,
Expand Down Expand Up @@ -3544,7 +3530,6 @@ impl<'a> LoweringContext<'a> {
name: ident.name,
vis,
attrs,
id: i.id,
hir_id,
span: i.span,
body,
Expand Down Expand Up @@ -3900,11 +3885,10 @@ impl<'a> LoweringContext<'a> {
// Wrap the `if let` expr in a block.
let span = els.span;
let els = P(self.lower_expr(els));
let LoweredNodeId { node_id, hir_id } = self.next_id();
let LoweredNodeId { node_id: _, hir_id } = self.next_id();
let blk = P(hir::Block {
stmts: hir_vec![],
expr: Some(els),
id: node_id,
hir_id,
rules: hir::DefaultBlock,
span,
Expand Down Expand Up @@ -3947,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 @@ -4135,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 @@ -4488,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 @@ -4635,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 @@ -4910,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 Expand Up @@ -4978,12 +4957,11 @@ impl<'a> LoweringContext<'a> {
stmts: hir::HirVec<hir::Stmt>,
expr: Option<P<hir::Expr>>,
) -> hir::Block {
let LoweredNodeId { node_id, hir_id } = self.next_id();
let LoweredNodeId { node_id: _, hir_id } = self.next_id();

hir::Block {
stmts,
expr,
id: node_id,
hir_id,
rules: hir::DefaultBlock,
span,
Expand Down Expand Up @@ -5108,7 +5086,6 @@ impl<'a> LoweringContext<'a> {
_ => hir::TyKind::Path(qpath),
};
hir::Ty {
id: id.node_id,
hir_id: id.hir_id,
node,
span,
Expand All @@ -5124,9 +5101,8 @@ impl<'a> LoweringContext<'a> {
// `'f`.
AnonymousLifetimeMode::CreateParameter => {
let fresh_name = self.collect_fresh_in_band_lifetime(span);
let LoweredNodeId { node_id, hir_id } = self.next_id();
let LoweredNodeId { node_id: _, hir_id } = self.next_id();
hir::Lifetime {
id: node_id,
hir_id,
span,
name: hir::LifetimeName::Param(fresh_name),
Expand Down Expand Up @@ -5227,10 +5203,9 @@ impl<'a> LoweringContext<'a> {
}

fn new_implicit_lifetime(&mut self, span: Span) -> hir::Lifetime {
let LoweredNodeId { node_id, hir_id } = self.next_id();
let LoweredNodeId { node_id: _, hir_id } = self.next_id();

hir::Lifetime {
id: node_id,
hir_id,
span,
name: hir::LifetimeName::Implicit,
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
Loading