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 even more HIR nodes #58836

Merged
merged 8 commits into from
Mar 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc/hir/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
/// Checks any attribute.
fn check_attributes(&self, item: &hir::Item, target: Target) {
if target == Target::Fn || target == Target::Const {
self.tcx.codegen_fn_attrs(self.tcx.hir().local_def_id(item.id));
self.tcx.codegen_fn_attrs(self.tcx.hir().local_def_id_from_hir_id(item.hir_id));
} else if let Some(a) = item.attrs.iter().find(|a| a.check_name("target_feature")) {
self.tcx.sess.struct_span_err(a.span, "attribute should be applied to a function")
.span_label(item.span, "not a function")
Expand Down
83 changes: 37 additions & 46 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,8 @@ impl<'a> LoweringContext<'a> {

fn visit_trait_item(&mut self, item: &'lcx TraitItem) {
self.lctx.with_hir_id_owner(item.id, |lctx| {
let id = hir::TraitItemId { node_id: item.id };
let hir_item = lctx.lower_trait_item(item);
let id = hir::TraitItemId { hir_id: hir_item.hir_id };
lctx.trait_items.insert(id, hir_item);
lctx.modules.get_mut(&lctx.current_module).unwrap().trait_items.insert(id);
});
Expand All @@ -480,8 +480,8 @@ impl<'a> LoweringContext<'a> {

fn visit_impl_item(&mut self, item: &'lcx ImplItem) {
self.lctx.with_hir_id_owner(item.id, |lctx| {
let id = hir::ImplItemId { node_id: item.id };
let hir_item = lctx.lower_impl_item(item);
let id = hir::ImplItemId { hir_id: hir_item.hir_id };
lctx.impl_items.insert(id, hir_item);
lctx.modules.get_mut(&lctx.current_module).unwrap().impl_items.insert(id);
});
Expand Down Expand Up @@ -1414,7 +1414,6 @@ impl<'a> LoweringContext<'a> {

trace!("exist ty def index: {:#?}", exist_ty_def_index);
let exist_ty_item = hir::Item {
id: exist_ty_id.node_id,
hir_id: exist_ty_id.hir_id,
ident: keywords::Invalid.ident(),
attrs: Default::default(),
Expand Down Expand Up @@ -2675,35 +2674,33 @@ impl<'a> LoweringContext<'a> {
fn lower_variant_data(&mut self, vdata: &VariantData) -> hir::VariantData {
match *vdata {
VariantData::Struct(ref fields, id) => {
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(id);
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(id);

hir::VariantData::Struct(
fields
.iter()
.enumerate()
.map(|f| self.lower_struct_field(f))
.collect(),
node_id,
hir_id,
)
},
VariantData::Tuple(ref fields, id) => {
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(id);
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(id);

hir::VariantData::Tuple(
fields
.iter()
.enumerate()
.map(|f| self.lower_struct_field(f))
.collect(),
node_id,
hir_id,
)
},
VariantData::Unit(id) => {
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(id);
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(id);

hir::VariantData::Unit(node_id, hir_id)
hir::VariantData::Unit(hir_id)
},
}
}
Expand Down Expand Up @@ -2743,11 +2740,10 @@ impl<'a> LoweringContext<'a> {
}

fn lower_struct_field(&mut self, (index, f): (usize, &StructField)) -> hir::StructField {
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(f.id);
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(f.id);

hir::StructField {
span: f.span,
id: node_id,
hir_id,
ident: match f.ident {
Some(ident) => ident,
Expand Down Expand Up @@ -3129,7 +3125,6 @@ impl<'a> LoweringContext<'a> {
this.insert_item(
new_id.node_id,
hir::Item {
id: new_id.node_id,
hir_id: new_id.hir_id,
ident,
attrs: attrs.clone(),
Expand Down Expand Up @@ -3235,7 +3230,6 @@ impl<'a> LoweringContext<'a> {
this.insert_item(
new_id,
hir::Item {
id: new_id,
hir_id: new_hir_id,
ident,
attrs: attrs.clone(),
Expand Down Expand Up @@ -3369,7 +3363,7 @@ impl<'a> LoweringContext<'a> {
TraitItemKind::Macro(..) => unimplemented!(),
};
hir::TraitItemRef {
id: hir::TraitItemId { node_id: i.id },
id: hir::TraitItemId { hir_id: self.lower_node_id(i.id).hir_id },
ident: i.ident,
span: i.span,
defaultness: self.lower_defaultness(Defaultness::Default, has_default),
Expand Down Expand Up @@ -3433,7 +3427,7 @@ impl<'a> LoweringContext<'a> {

fn lower_impl_item_ref(&mut self, i: &ImplItem) -> hir::ImplItemRef {
hir::ImplItemRef {
id: hir::ImplItemId { node_id: i.id },
id: hir::ImplItemId { hir_id: self.lower_node_id(i.id).hir_id },
ident: i.ident,
span: i.span,
vis: self.lower_visibility(&i.vis, Some(i.id)),
Expand Down Expand Up @@ -3535,10 +3529,9 @@ impl<'a> LoweringContext<'a> {

let node = self.lower_item_kind(i.id, &mut ident, &attrs, &mut vis, &i.node);

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

Some(hir::Item {
id: node_id,
hir_id,
ident,
attrs,
Expand All @@ -3552,7 +3545,6 @@ impl<'a> LoweringContext<'a> {
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(i.id);
let def_id = self.resolver.definitions().local_def_id(node_id);
hir::ForeignItem {
id: node_id,
hir_id,
ident: i.ident,
attrs: self.lower_attrs(&i.attrs),
Expand Down Expand Up @@ -3746,12 +3738,11 @@ impl<'a> LoweringContext<'a> {
let fs = fields
.iter()
.map(|f| {
let LoweredNodeId { node_id, hir_id } = self.next_id();
let LoweredNodeId { node_id: _, hir_id } = self.next_id();

Spanned {
span: f.span,
node: hir::FieldPat {
id: node_id,
hir_id,
ident: f.node.ident,
pat: self.lower_pat(&f.node.pat),
Expand Down Expand Up @@ -3783,9 +3774,8 @@ impl<'a> LoweringContext<'a> {
PatKind::Mac(_) => panic!("Shouldn't exist here"),
};

let LoweredNodeId { node_id, hir_id } = self.lower_node_id(p.id);
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(p.id);
P(hir::Pat {
id: node_id,
hir_id,
node,
span: p.span,
Expand Down Expand Up @@ -4359,7 +4349,7 @@ impl<'a> LoweringContext<'a> {
let iter = self.str_to_ident("iter");

let next_ident = self.str_to_ident("__next");
let next_pat = self.pat_ident_binding_mode(
let (next_pat, next_pat_nid) = self.pat_ident_binding_mode(
desugared_span,
next_ident,
hir::BindingAnnotation::Mutable,
Expand All @@ -4368,9 +4358,9 @@ impl<'a> LoweringContext<'a> {
// `::std::option::Option::Some(val) => next = val`
let pat_arm = {
let val_ident = self.str_to_ident("val");
let val_pat = self.pat_ident(pat.span, val_ident);
let val_expr = P(self.expr_ident(pat.span, val_ident, val_pat.id));
let next_expr = P(self.expr_ident(pat.span, next_ident, next_pat.id));
let (val_pat, val_pat_nid) = self.pat_ident(pat.span, val_ident);
let val_expr = P(self.expr_ident(pat.span, val_ident, val_pat_nid));
let next_expr = P(self.expr_ident(pat.span, next_ident, next_pat_nid));
let assign = P(self.expr(
pat.span,
hir::ExprKind::Assign(next_expr, val_expr),
Expand All @@ -4389,15 +4379,15 @@ impl<'a> LoweringContext<'a> {
};

// `mut iter`
let iter_pat = self.pat_ident_binding_mode(
let (iter_pat, iter_pat_nid) = self.pat_ident_binding_mode(
desugared_span,
iter,
hir::BindingAnnotation::Mutable
);

// `match ::std::iter::Iterator::next(&mut iter) { ... }`
let match_expr = {
let iter = P(self.expr_ident(head_sp, iter, iter_pat.id));
let iter = P(self.expr_ident(head_sp, iter, iter_pat_nid));
let ref_mut_iter = self.expr_mut_addr_of(head_sp, iter);
let next_path = &["iter", "Iterator", "next"];
let next_path = P(self.expr_std_path(head_sp, next_path, None, ThinVec::new()));
Expand All @@ -4421,7 +4411,7 @@ impl<'a> LoweringContext<'a> {
span: head_sp,
};

let next_expr = P(self.expr_ident(head_sp, next_ident, next_pat.id));
let next_expr = P(self.expr_ident(head_sp, next_ident, next_pat_nid));

// `let mut __next`
let next_let = self.stmt_let_pat(
Expand Down Expand Up @@ -4548,11 +4538,11 @@ impl<'a> LoweringContext<'a> {
// `Ok(val) => #[allow(unreachable_code)] val,`
let ok_arm = {
let val_ident = self.str_to_ident("val");
let val_pat = self.pat_ident(e.span, val_ident);
let (val_pat, val_pat_nid) = self.pat_ident(e.span, val_ident);
let val_expr = P(self.expr_ident_with_attrs(
e.span,
val_ident,
val_pat.id,
val_pat_nid,
ThinVec::from(attrs.clone()),
));
let ok_pat = self.pat_ok(e.span, val_pat);
Expand All @@ -4564,12 +4554,12 @@ impl<'a> LoweringContext<'a> {
// return Try::from_error(From::from(err)),`
let err_arm = {
let err_ident = self.str_to_ident("err");
let err_local = self.pat_ident(e.span, err_ident);
let (err_local, err_local_nid) = self.pat_ident(e.span, err_ident);
let from_expr = {
let path = &["convert", "From", "from"];
let from = P(self.expr_std_path(
e.span, path, None, ThinVec::new()));
let err_expr = self.expr_ident(e.span, err_ident, err_local.id);
let err_expr = self.expr_ident(e.span, err_ident, err_local_nid);

self.expr_call(e.span, from, hir_vec![err_expr])
};
Expand Down Expand Up @@ -4917,15 +4907,15 @@ impl<'a> LoweringContext<'a> {
ident: Ident,
ex: P<hir::Expr>,
) -> (hir::Stmt, NodeId) {
let pat = if mutbl {
let (pat, pat_nid) = if mutbl {
self.pat_ident_binding_mode(sp, ident, hir::BindingAnnotation::Mutable)
} else {
self.pat_ident(sp, ident)
};
let pat_id = pat.id;

(
self.stmt_let_pat(sp, Some(ex), pat, hir::LocalSource::Normal),
pat_id,
pat_nid,
)
}

Expand Down Expand Up @@ -4983,7 +4973,7 @@ impl<'a> LoweringContext<'a> {
self.pat(span, pt)
}

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

Expand All @@ -4992,25 +4982,26 @@ impl<'a> LoweringContext<'a> {
span: Span,
ident: Ident,
bm: hir::BindingAnnotation,
) -> P<hir::Pat> {
) -> (P<hir::Pat>, NodeId) {
let LoweredNodeId { node_id, hir_id } = self.next_id();

P(hir::Pat {
id: node_id,
hir_id,
node: hir::PatKind::Binding(bm, node_id, hir_id, ident.with_span_pos(span), None),
span,
})
(
P(hir::Pat {
hir_id,
node: hir::PatKind::Binding(bm, node_id, hir_id, ident.with_span_pos(span), None),
span,
}),
node_id
)
}

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

fn pat(&mut self, span: Span, pat: hir::PatKind) -> P<hir::Pat> {
let LoweredNodeId { node_id, hir_id } = self.next_id();
let LoweredNodeId { node_id: _, hir_id } = self.next_id();
P(hir::Pat {
id: node_id,
hir_id,
node: pat,
span,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/map/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
fn visit_item(&mut self, i: &'hir Item) {
debug!("visit_item: {:?}", i);
debug_assert_eq!(i.hir_id.owner,
self.definitions.opt_def_index(i.id).unwrap());
self.definitions.opt_def_index(self.hir_to_node_id[&i.hir_id]).unwrap());
self.with_dep_node_owner(i.hir_id.owner, i, |this| {
this.insert(i.span, i.hir_id, Node::Item(i));
this.with_parent(i.hir_id, |this| {
Expand Down
16 changes: 8 additions & 8 deletions src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ impl<'hir> Map<'hir> {

match node {
Node::Item(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 {
ItemKind::Static(_, m, _) => Some(Def::Static(def_id(), m == MutMutable)),
Expand All @@ -341,7 +341,7 @@ impl<'hir> Map<'hir> {
}
}
Node::ForeignItem(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 {
ForeignItemKind::Fn(..) => Some(Def::Fn(def_id)),
ForeignItemKind::Static(_, m) => Some(Def::Static(def_id, m)),
Expand All @@ -366,11 +366,11 @@ impl<'hir> Map<'hir> {
}
}
Node::Variant(variant) => {
let def_id = self.local_def_id(variant.node.data.id());
let def_id = self.local_def_id_from_hir_id(variant.node.data.hir_id());
Some(Def::Variant(def_id))
}
Node::StructCtor(variant) => {
let def_id = self.local_def_id(variant.id());
let def_id = self.local_def_id_from_hir_id(variant.hir_id());
Some(Def::StructCtor(def_id, def::CtorKind::from_hir(variant)))
}
Node::AnonConst(_) |
Expand Down Expand Up @@ -427,15 +427,15 @@ impl<'hir> Map<'hir> {
}

pub fn trait_item(&self, id: TraitItemId) -> &'hir TraitItem {
self.read(id.node_id);
self.read_by_hir_id(id.hir_id);

// N.B., intentionally bypass `self.forest.krate()` so that we
// do not trigger a read of the whole krate here
self.forest.krate.trait_item(id)
}

pub fn impl_item(&self, id: ImplItemId) -> &'hir ImplItem {
self.read(id.node_id);
self.read_by_hir_id(id.hir_id);

// N.B., intentionally bypass `self.forest.krate()` so that we
// do not trigger a read of the whole krate here
Expand Down Expand Up @@ -618,11 +618,11 @@ impl<'hir> Map<'hir> {
}

for id in &module.trait_items {
visitor.visit_trait_item(self.expect_trait_item(id.node_id));
visitor.visit_trait_item(self.expect_trait_item_by_hir_id(id.hir_id));
}

for id in &module.impl_items {
visitor.visit_impl_item(self.expect_impl_item(id.node_id));
visitor.visit_impl_item(self.expect_impl_item_by_hir_id(id.hir_id));
}
}

Expand Down
Loading