Skip to content

Commit

Permalink
hir: remove NodeId from ForeignItem
Browse files Browse the repository at this point in the history
  • Loading branch information
ljedrz committed Mar 2, 2019
1 parent ae45f17 commit 3c25193
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 22 deletions.
1 change: 0 additions & 1 deletion src/librustc/hir/lowering.rs
Expand Up @@ -3551,7 +3551,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
2 changes: 1 addition & 1 deletion src/librustc/hir/map/mod.rs
Expand Up @@ -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 Down
1 change: 0 additions & 1 deletion src/librustc/hir/mod.rs
Expand Up @@ -2378,7 +2378,6 @@ pub struct ForeignItem {
pub ident: Ident,
pub attrs: HirVec<Attribute>,
pub node: ForeignItemKind,
pub id: NodeId,
pub hir_id: HirId,
pub span: Span,
pub vis: Visibility,
Expand Down
1 change: 0 additions & 1 deletion src/librustc/ich/impls_hir.rs
Expand Up @@ -931,7 +931,6 @@ impl_stable_hash_for!(struct hir::ForeignItem {
ident -> (ident.name),
attrs,
node,
id,
hir_id,
span,
vis
Expand Down
14 changes: 7 additions & 7 deletions src/librustc_lint/types.rs
Expand Up @@ -762,8 +762,8 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
}
}

fn check_foreign_fn(&mut self, id: ast::NodeId, decl: &hir::FnDecl) {
let def_id = self.cx.tcx.hir().local_def_id(id);
fn check_foreign_fn(&mut self, id: hir::HirId, decl: &hir::FnDecl) {
let def_id = self.cx.tcx.hir().local_def_id_from_hir_id(id);
let sig = self.cx.tcx.fn_sig(def_id);
let sig = self.cx.tcx.erase_late_bound_regions(&sig);
let inputs = if sig.c_variadic {
Expand All @@ -786,8 +786,8 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
}
}

fn check_foreign_static(&mut self, id: ast::NodeId, span: Span) {
let def_id = self.cx.tcx.hir().local_def_id(id);
fn check_foreign_static(&mut self, id: hir::HirId, span: Span) {
let def_id = self.cx.tcx.hir().local_def_id_from_hir_id(id);
let ty = self.cx.tcx.type_of(def_id);
self.check_type_for_ffi_and_report_errors(span, ty);
}
Expand All @@ -809,14 +809,14 @@ impl LintPass for ImproperCTypes {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImproperCTypes {
fn check_foreign_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::ForeignItem) {
let mut vis = ImproperCTypesVisitor { cx };
let abi = cx.tcx.hir().get_foreign_abi(it.id);
let abi = cx.tcx.hir().get_foreign_abi_by_hir_id(it.hir_id);
if abi != Abi::RustIntrinsic && abi != Abi::PlatformIntrinsic {
match it.node {
hir::ForeignItemKind::Fn(ref decl, _, _) => {
vis.check_foreign_fn(it.id, decl);
vis.check_foreign_fn(it.hir_id, decl);
}
hir::ForeignItemKind::Static(ref ty, _) => {
vis.check_foreign_static(it.id, ty.span);
vis.check_foreign_static(it.hir_id, ty.span);
}
hir::ForeignItemKind::Type => ()
}
Expand Down
9 changes: 6 additions & 3 deletions src/librustc_metadata/encoder.rs
Expand Up @@ -1161,7 +1161,8 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
hir::ItemKind::ForeignMod(ref fm) => {
self.lazy_seq(fm.items
.iter()
.map(|foreign_item| tcx.hir().local_def_id(foreign_item.id).index))
.map(|foreign_item| tcx.hir().local_def_id_from_hir_id(
foreign_item.hir_id).index))
}
hir::ItemKind::Enum(..) => {
let def = self.tcx.adt_def(def_id);
Expand Down Expand Up @@ -1607,9 +1608,11 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
hir::ForeignItemKind::Type => EntryKind::ForeignType,
};

let node_id = self.tcx.hir().hir_to_node_id(nitem.hir_id);

Entry {
kind,
visibility: self.lazy(&ty::Visibility::from_hir(&nitem.vis, nitem.id, tcx)),
visibility: self.lazy(&ty::Visibility::from_hir(&nitem.vis, node_id, tcx)),
span: self.lazy(&nitem.span),
attributes: self.encode_attributes(&nitem.attrs),
children: LazySeq::empty(),
Expand Down Expand Up @@ -1655,7 +1658,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for EncodeVisitor<'a, 'b, 'tcx> {
}
fn visit_foreign_item(&mut self, ni: &'tcx hir::ForeignItem) {
intravisit::walk_foreign_item(self, ni);
let def_id = self.index.tcx.hir().local_def_id(ni.id);
let def_id = self.index.tcx.hir().local_def_id_from_hir_id(ni.hir_id);
self.index.record(def_id,
IsolatedEncoder::encode_info_for_foreign_item,
(def_id, ni));
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_metadata/foreign_modules.rs
Expand Up @@ -25,7 +25,7 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for Collector<'a, 'tcx> {
};

let foreign_items = fm.items.iter()
.map(|it| self.tcx.hir().local_def_id(it.id))
.map(|it| self.tcx.hir().local_def_id_from_hir_id(it.hir_id))
.collect();
self.modules.push(ForeignModule {
foreign_items,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/intrinsic.rs
Expand Up @@ -22,7 +22,7 @@ fn equate_intrinsic_type<'a, 'tcx>(
inputs: Vec<Ty<'tcx>>,
output: Ty<'tcx>,
) {
let def_id = tcx.hir().local_def_id(it.id);
let def_id = tcx.hir().local_def_id_from_hir_id(it.hir_id);

match it.node {
hir::ForeignItemKind::Fn(..) => {}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/mod.rs
Expand Up @@ -1407,7 +1407,7 @@ pub fn check_item_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, it: &'tcx hir::Ite
}
} else {
for item in &m.items {
let generics = tcx.generics_of(tcx.hir().local_def_id(item.id));
let generics = tcx.generics_of(tcx.hir().local_def_id_from_hir_id(item.hir_id));
if generics.params.len() - generics.own_counts().lifetimes != 0 {
let mut err = struct_span_err!(
tcx.sess,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/collect.rs
Expand Up @@ -409,7 +409,7 @@ fn convert_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item_id: ast::NodeId) {
| hir::ItemKind::GlobalAsm(_) => {}
hir::ItemKind::ForeignMod(ref foreign_mod) => {
for item in &foreign_mod.items {
let def_id = tcx.hir().local_def_id(item.id);
let def_id = tcx.hir().local_def_id_from_hir_id(item.hir_id);
tcx.generics_of(def_id);
tcx.type_of(def_id);
tcx.predicates_of(def_id);
Expand Down
8 changes: 5 additions & 3 deletions src/librustdoc/clean/mod.rs
Expand Up @@ -3821,14 +3821,16 @@ impl Clean<Item> for hir::ForeignItem {
}
};

let local_did = cx.tcx.hir().local_def_id_from_hir_id(self.hir_id);

Item {
name: Some(self.ident.clean(cx)),
attrs: self.attrs.clean(cx),
source: self.span.clean(cx),
def_id: cx.tcx.hir().local_def_id(self.id),
def_id: local_did,
visibility: self.vis.clean(cx),
stability: get_stability(cx, cx.tcx.hir().local_def_id(self.id)),
deprecation: get_deprecation(cx, cx.tcx.hir().local_def_id(self.id)),
stability: get_stability(cx, local_did),
deprecation: get_deprecation(cx, local_did),
inner,
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/visit_ast.rs
Expand Up @@ -357,7 +357,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
Node::ForeignItem(it) if !glob => {
// Generate a fresh `extern {}` block if we want to inline a foreign item.
om.foreigns.push(hir::ForeignMod {
abi: tcx.hir().get_foreign_abi(it.id),
abi: tcx.hir().get_foreign_abi_by_hir_id(it.hir_id),
items: vec![hir::ForeignItem {
ident: renamed.unwrap_or(it.ident),
.. it.clone()
Expand Down

0 comments on commit 3c25193

Please sign in to comment.