Skip to content

Commit

Permalink
Auto merge of #58754 - ljedrz:I_hate_NodeIds, r=Zoxc
Browse files Browse the repository at this point in the history
Remove NodeId from more HIR nodes

The next iteration of HirIdification (#57578).

Removes `NodeId` from:

- [x] `Stmt`
- [x] `Local`
- [x] `Field`
- [x] `AnonConst`
- [x] `TraitItem`
- [x] `ImplItem`
- [x] `TypeBinding`
- [x] `Arg`
- [x] `TraitRef`
- [x] `VisibilityKind`

It will most probably break clippy again; I'd appreciate a **delegate** again if/when it is good to go so I can attach a clippy fix later.

r? @Zoxc
  • Loading branch information
bors committed Mar 1, 2019
2 parents 17add24 + 9cd1845 commit c1d2d83
Show file tree
Hide file tree
Showing 45 changed files with 368 additions and 429 deletions.
3 changes: 1 addition & 2 deletions src/librustc/hir/intravisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,6 @@ pub fn walk_trait_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, trait_item_ref:
pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplItem) {
// N.B., deliberately force a compilation error if/when new fields are added.
let ImplItem {
id: _,
hir_id: _,
ident,
ref vis,
Expand Down Expand Up @@ -1106,7 +1105,7 @@ pub fn walk_arm<'v, V: Visitor<'v>>(visitor: &mut V, arm: &'v Arm) {
}

pub fn walk_vis<'v, V: Visitor<'v>>(visitor: &mut V, vis: &'v Visibility) {
if let VisibilityKind::Restricted { ref path, id: _, hir_id } = vis.node {
if let VisibilityKind::Restricted { ref path, hir_id } = vis.node {
visitor.visit_id(hir_id);
visitor.visit_path(path, hir_id)
}
Expand Down
67 changes: 21 additions & 46 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1151,10 +1151,9 @@ impl<'a> LoweringContext<'a> {

fn lower_ty_binding(&mut self, b: &TypeBinding,
itctx: ImplTraitContext<'_>) -> hir::TypeBinding {
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(b.id);
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(b.id);

hir::TypeBinding {
id: node_id,
hir_id,
ident: b.ident,
ty: self.lower_ty(&b.ty, itctx),
Expand Down Expand Up @@ -1982,14 +1981,13 @@ impl<'a> LoweringContext<'a> {
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();
let LoweredNodeId { node_id: _, hir_id } = this.next_id();

(
hir::GenericArgs {
args: hir_vec![GenericArg::Type(mk_tup(this, inputs, span))],
bindings: hir_vec![
hir::TypeBinding {
id: node_id,
hir_id,
ident: Ident::from_str(FN_OUTPUT_NAME),
ty: output
Expand All @@ -2008,7 +2006,7 @@ impl<'a> LoweringContext<'a> {
}

fn lower_local(&mut self, l: &Local) -> (hir::Local, SmallVec<[hir::ItemId; 1]>) {
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(l.id);
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(l.id);
let mut ids = SmallVec::<[hir::ItemId; 1]>::new();
if self.sess.features_untracked().impl_trait_in_bindings {
if let Some(ref ty) = l.ty {
Expand All @@ -2018,7 +2016,6 @@ impl<'a> LoweringContext<'a> {
}
let parent_def_id = DefId::local(self.current_hir_id_owner.last().unwrap().0);
(hir::Local {
id: node_id,
hir_id,
ty: l.ty
.as_ref()
Expand All @@ -2045,9 +2042,8 @@ impl<'a> LoweringContext<'a> {
}

fn lower_arg(&mut self, arg: &Arg) -> hir::Arg {
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(arg.id);
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(arg.id);
hir::Arg {
id: node_id,
hir_id,
pat: self.lower_pat(&arg.pat),
}
Expand Down Expand Up @@ -2327,13 +2323,12 @@ impl<'a> LoweringContext<'a> {
};

// "<Output = T>"
let LoweredNodeId { node_id, hir_id } = this.next_id();
let LoweredNodeId { node_id: _, hir_id } = this.next_id();
let future_params = P(hir::GenericArgs {
args: hir_vec![],
bindings: hir_vec![hir::TypeBinding {
ident: Ident::from_str(FN_OUTPUT_NAME),
ty: output_ty,
id: node_id,
hir_id,
span,
}],
Expand All @@ -2343,13 +2338,12 @@ impl<'a> LoweringContext<'a> {
let future_path =
this.std_path(span, &["future", "Future"], Some(future_params), false);

let LoweredNodeId { node_id, hir_id } = this.next_id();
let LoweredNodeId { node_id: _, hir_id } = this.next_id();
let mut bounds = vec![
hir::GenericBound::Trait(
hir::PolyTraitRef {
trait_ref: hir::TraitRef {
path: future_path,
ref_id: node_id,
hir_ref_id: hir_id,
},
bound_generic_params: hir_vec![],
Expand Down Expand Up @@ -2719,10 +2713,9 @@ impl<'a> LoweringContext<'a> {
hir::QPath::Resolved(None, path) => path.and_then(|path| path),
qpath => bug!("lower_trait_ref: unexpected QPath `{:?}`", qpath),
};
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(p.ref_id);
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(p.ref_id);
hir::TraitRef {
path,
ref_id: node_id,
hir_ref_id: hir_id,
}
}
Expand Down Expand Up @@ -2768,10 +2761,9 @@ impl<'a> LoweringContext<'a> {
}

fn lower_field(&mut self, f: &Field) -> hir::Field {
let LoweredNodeId { node_id, hir_id } = self.next_id();
let LoweredNodeId { node_id: _, hir_id } = self.next_id();

hir::Field {
id: node_id,
hir_id,
ident: f.ident,
expr: P(self.lower_expr(&f.expr)),
Expand Down Expand Up @@ -3123,12 +3115,11 @@ impl<'a> LoweringContext<'a> {
hir::VisibilityKind::Public => hir::VisibilityKind::Public,
hir::VisibilityKind::Crate(sugar) => hir::VisibilityKind::Crate(sugar),
hir::VisibilityKind::Inherited => hir::VisibilityKind::Inherited,
hir::VisibilityKind::Restricted { ref path, id: _, hir_id: _ } => {
hir::VisibilityKind::Restricted { ref path, hir_id: _ } => {
let id = this.next_id();
let path = this.renumber_segment_ids(path);
hir::VisibilityKind::Restricted {
path,
id: id.node_id,
hir_id: id.hir_id,
}
}
Expand Down Expand Up @@ -3230,12 +3221,11 @@ impl<'a> LoweringContext<'a> {
hir::VisibilityKind::Public => hir::VisibilityKind::Public,
hir::VisibilityKind::Crate(sugar) => hir::VisibilityKind::Crate(sugar),
hir::VisibilityKind::Inherited => hir::VisibilityKind::Inherited,
hir::VisibilityKind::Restricted { ref path, id: _, hir_id: _ } => {
hir::VisibilityKind::Restricted { ref path, hir_id: _ } => {
let id = this.next_id();
let path = this.renumber_segment_ids(path);
hir::VisibilityKind::Restricted {
path: path,
id: id.node_id,
hir_id: id.hir_id,
}
}
Expand Down Expand Up @@ -3353,7 +3343,6 @@ impl<'a> LoweringContext<'a> {
};

hir::TraitItem {
id: node_id,
hir_id,
ident: i.ident,
attrs: self.lower_attrs(&i.attrs),
Expand Down Expand Up @@ -3429,7 +3418,6 @@ impl<'a> LoweringContext<'a> {
};

hir::ImplItem {
id: node_id,
hir_id,
ident: i.ident,
attrs: self.lower_attrs(&i.attrs),
Expand Down Expand Up @@ -3813,9 +3801,8 @@ impl<'a> LoweringContext<'a> {

fn lower_anon_const(&mut self, c: &AnonConst) -> hir::AnonConst {
self.with_new_scopes(|this| {
let LoweredNodeId { node_id, hir_id } = this.lower_node_id(c.id);
let LoweredNodeId { node_id: _, hir_id } = this.lower_node_id(c.id);
hir::AnonConst {
id: node_id,
hir_id,
body: this.lower_body(None, |this| this.lower_expr(&c.value)),
}
Expand Down Expand Up @@ -4427,9 +4414,8 @@ impl<'a> LoweringContext<'a> {
ThinVec::new(),
))
};
let LoweredNodeId { node_id, hir_id } = self.next_id();
let LoweredNodeId { node_id: _, hir_id } = self.next_id();
let match_stmt = hir::Stmt {
id: node_id,
hir_id,
node: hir::StmtKind::Expr(match_expr),
span: head_sp,
Expand All @@ -4456,9 +4442,8 @@ impl<'a> LoweringContext<'a> {

let body_block = self.with_loop_scope(e.id, |this| this.lower_block(body, false));
let body_expr = P(self.expr_block(body_block, ThinVec::new()));
let LoweredNodeId { node_id, hir_id } = self.next_id();
let LoweredNodeId { node_id: _, hir_id } = self.next_id();
let body_stmt = hir::Stmt {
id: node_id,
hir_id,
node: hir::StmtKind::Expr(body_expr),
span: body.span,
Expand Down Expand Up @@ -4639,21 +4624,19 @@ impl<'a> LoweringContext<'a> {
let mut ids: SmallVec<[hir::Stmt; 1]> = item_ids
.into_iter()
.map(|item_id| {
let LoweredNodeId { node_id, hir_id } = self.next_id();
let LoweredNodeId { node_id: _, hir_id } = self.next_id();

hir::Stmt {
id: node_id,
hir_id,
node: hir::StmtKind::Item(item_id),
span: s.span,
}
})
.collect();
ids.push({
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(s.id);
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(s.id);

hir::Stmt {
id: node_id,
hir_id,
node: hir::StmtKind::Local(P(l)),
span: s.span,
Expand All @@ -4667,12 +4650,11 @@ impl<'a> LoweringContext<'a> {
return self.lower_item_id(it)
.into_iter()
.map(|item_id| {
let LoweredNodeId { node_id, hir_id } = id.take()
let LoweredNodeId { node_id: _, hir_id } = id.take()
.map(|id| self.lower_node_id(id))
.unwrap_or_else(|| self.next_id());

hir::Stmt {
id: node_id,
hir_id,
node: hir::StmtKind::Item(item_id),
span: s.span,
Expand All @@ -4681,20 +4663,18 @@ impl<'a> LoweringContext<'a> {
.collect();
}
StmtKind::Expr(ref e) => {
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(s.id);
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(s.id);

hir::Stmt {
id: node_id,
hir_id,
node: hir::StmtKind::Expr(P(self.lower_expr(e))),
span: s.span,
}
},
StmtKind::Semi(ref e) => {
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(s.id);
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(s.id);

hir::Stmt {
id: node_id,
hir_id,
node: hir::StmtKind::Semi(P(self.lower_expr(e))),
span: s.span,
Expand Down Expand Up @@ -4739,7 +4719,6 @@ impl<'a> LoweringContext<'a> {
ParamMode::Explicit,
explicit_owner,
)),
id: lowered_id.node_id,
hir_id: lowered_id.hir_id,
}
},
Expand Down Expand Up @@ -4809,10 +4788,9 @@ impl<'a> LoweringContext<'a> {
}

fn field(&mut self, ident: Ident, expr: P<hir::Expr>, span: Span) -> hir::Field {
let LoweredNodeId { node_id, hir_id } = self.next_id();
let LoweredNodeId { node_id: _, hir_id } = self.next_id();

hir::Field {
id: node_id,
hir_id,
ident,
span,
Expand Down Expand Up @@ -4912,22 +4890,20 @@ impl<'a> LoweringContext<'a> {
pat: P<hir::Pat>,
source: hir::LocalSource,
) -> hir::Stmt {
let LoweredNodeId { node_id, hir_id } = self.next_id();
let LoweredNodeId { node_id: _, hir_id } = self.next_id();

let local = hir::Local {
pat,
ty: None,
init: ex,
id: node_id,
hir_id,
span: sp,
attrs: ThinVec::new(),
source,
};

let LoweredNodeId { node_id, hir_id } = self.next_id();
let LoweredNodeId { node_id: _, hir_id } = self.next_id();
hir::Stmt {
id: node_id,
hir_id,
node: hir::StmtKind::Local(P(local)),
span: sp
Expand Down Expand Up @@ -5075,7 +5051,6 @@ impl<'a> LoweringContext<'a> {
bound_generic_params: hir::HirVec::new(),
trait_ref: hir::TraitRef {
path: path.and_then(|path| path),
ref_id: id.node_id,
hir_ref_id: id.hir_id,
},
span,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/hir/map/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {

fn visit_trait_item(&mut self, ti: &'hir TraitItem) {
debug_assert_eq!(ti.hir_id.owner,
self.definitions.opt_def_index(ti.id).unwrap());
self.definitions.opt_def_index(self.hir_to_node_id[&ti.hir_id]).unwrap());
self.with_dep_node_owner(ti.hir_id.owner, ti, |this| {
this.insert(ti.span, ti.hir_id, Node::TraitItem(ti));

Expand All @@ -398,7 +398,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {

fn visit_impl_item(&mut self, ii: &'hir ImplItem) {
debug_assert_eq!(ii.hir_id.owner,
self.definitions.opt_def_index(ii.id).unwrap());
self.definitions.opt_def_index(self.hir_to_node_id[&ii.hir_id]).unwrap());
self.with_dep_node_owner(ii.hir_id.owner, ii, |this| {
this.insert(ii.span, ii.hir_id, Node::ImplItem(ii));

Expand Down
6 changes: 3 additions & 3 deletions src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,15 +349,15 @@ impl<'hir> Map<'hir> {
}
}
Node::TraitItem(item) => {
let def_id = self.local_def_id(item.id);
let def_id = self.local_def_id_from_hir_id(item.hir_id);
match item.node {
TraitItemKind::Const(..) => Some(Def::AssociatedConst(def_id)),
TraitItemKind::Method(..) => Some(Def::Method(def_id)),
TraitItemKind::Type(..) => Some(Def::AssociatedTy(def_id)),
}
}
Node::ImplItem(item) => {
let def_id = self.local_def_id(item.id);
let def_id = self.local_def_id_from_hir_id(item.hir_id);
match item.node {
ImplItemKind::Const(..) => Some(Def::AssociatedConst(def_id)),
ImplItemKind::Method(..) => Some(Def::Method(def_id)),
Expand Down Expand Up @@ -387,7 +387,7 @@ impl<'hir> Map<'hir> {
Node::Block(_) |
Node::Crate => None,
Node::Local(local) => {
Some(Def::Local(local.id))
Some(Def::Local(self.hir_to_node_id(local.hir_id)))
}
Node::MacroDef(macro_def) => {
Some(Def::Macro(self.local_def_id_from_hir_id(macro_def.hir_id),
Expand Down
Loading

0 comments on commit c1d2d83

Please sign in to comment.