diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 8fe116bd9c873..34d3597486d4d 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -159,15 +159,6 @@ impl<'a, 'tcx, 'rcx> DocContext<'a, 'tcx, 'rcx> { /// Like the function of the same name on the HIR map, but skips calling it on fake DefIds. /// (This avoids a slice-index-out-of-bounds panic.) - pub fn as_local_node_id(&self, def_id: DefId) -> Option { - if self.all_fake_def_ids.borrow().contains(&def_id) { - None - } else { - self.tcx.hir().as_local_node_id(def_id) - } - } - - // FIXME(@ljedrz): remove the NodeId variant pub fn as_local_hir_id(&self, def_id: DefId) -> Option { if self.all_fake_def_ids.borrow().contains(&def_id) { None diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index c346714ab485a..6a9ffe3eff5aa 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -49,7 +49,7 @@ enum PathKind { struct LinkCollector<'a, 'tcx: 'a, 'rcx: 'a> { cx: &'a DocContext<'a, 'tcx, 'rcx>, - mod_ids: Vec, + mod_ids: Vec, is_nightly_build: bool, } @@ -69,7 +69,7 @@ impl<'a, 'tcx, 'rcx> LinkCollector<'a, 'tcx, 'rcx> { path_str: &str, is_val: bool, current_item: &Option, - parent_id: Option) + parent_id: Option) -> Result<(Def, Option), ()> { let cx = self.cx; @@ -78,8 +78,9 @@ impl<'a, 'tcx, 'rcx> LinkCollector<'a, 'tcx, 'rcx> { // path. if let Some(id) = parent_id.or(self.mod_ids.last().cloned()) { // FIXME: `with_scope` requires the `NodeId` of a module. + let node_id = cx.tcx.hir().hir_to_node_id(id); let result = cx.resolver.borrow_mut() - .with_scope(id, + .with_scope(node_id, |resolver| { resolver.resolve_str_path_error(DUMMY_SP, &path_str, is_val) @@ -142,8 +143,9 @@ impl<'a, 'tcx, 'rcx> LinkCollector<'a, 'tcx, 'rcx> { } // FIXME: `with_scope` requires the `NodeId` of a module. + let node_id = cx.tcx.hir().hir_to_node_id(id); let ty = cx.resolver.borrow_mut() - .with_scope(id, + .with_scope(node_id, |resolver| { resolver.resolve_str_path_error(DUMMY_SP, &path, false) })?; @@ -232,11 +234,11 @@ impl<'a, 'tcx, 'rcx> DocFolder for LinkCollector<'a, 'tcx, 'rcx> { }; // FIXME: get the resolver to work with non-local resolve scopes. - let parent_node = self.cx.as_local_node_id(item.def_id).and_then(|node_id| { + let parent_node = self.cx.as_local_hir_id(item.def_id).and_then(|hir_id| { // FIXME: this fails hard for impls in non-module scope, but is necessary for the // current `resolve()` implementation. - match self.cx.tcx.hir().get_module_parent_node(node_id) { - id if id != node_id => Some(id), + match self.cx.tcx.hir().get_module_parent_node(hir_id) { + id if id != hir_id => Some(id), _ => None, } }); @@ -255,9 +257,9 @@ impl<'a, 'tcx, 'rcx> DocFolder for LinkCollector<'a, 'tcx, 'rcx> { } } else { match parent_node.or(self.mod_ids.last().cloned()) { - Some(parent) if parent != ast::CRATE_NODE_ID => { + Some(parent) if parent != hir::CRATE_HIR_ID => { // FIXME: can we pull the parent module's name from elsewhere? - Some(self.cx.tcx.hir().name(parent).to_string()) + Some(self.cx.tcx.hir().name_by_hir_id(parent).to_string()) } _ => None, } @@ -274,7 +276,7 @@ impl<'a, 'tcx, 'rcx> DocFolder for LinkCollector<'a, 'tcx, 'rcx> { }; if item.is_mod() && item.attrs.inner_docs { - self.mod_ids.push(self.cx.tcx.hir().hir_to_node_id(item_hir_id.unwrap())); + self.mod_ids.push(item_hir_id.unwrap()); } let cx = self.cx; @@ -421,7 +423,7 @@ impl<'a, 'tcx, 'rcx> DocFolder for LinkCollector<'a, 'tcx, 'rcx> { } if item.is_mod() && !item.attrs.inner_docs { - self.mod_ids.push(self.cx.tcx.hir().hir_to_node_id(item_hir_id.unwrap())); + self.mod_ids.push(item_hir_id.unwrap()); } if item.is_mod() { diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index c1bd1d83a5b00..60150f6f49471 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -31,7 +31,7 @@ pub struct RustdocVisitor<'a, 'tcx: 'a, 'rcx: 'a> { pub module: Module, pub attrs: hir::HirVec, pub cx: &'a core::DocContext<'a, 'tcx, 'rcx>, - view_item_stack: FxHashSet, + view_item_stack: FxHashSet, inlining: bool, /// Are the current module and all of its parents public? inside_public_path: bool, @@ -44,7 +44,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { ) -> RustdocVisitor<'a, 'tcx, 'rcx> { // If the root is re-exported, terminate all recursion. let mut stack = FxHashSet::default(); - stack.insert(ast::CRATE_NODE_ID); + stack.insert(hir::CRATE_HIR_ID); RustdocVisitor { module: Module::new(None), attrs: hir::HirVec::new(), @@ -269,13 +269,13 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { om: &mut Module, please_inline: bool) -> bool { - fn inherits_doc_hidden(cx: &core::DocContext<'_, '_, '_>, mut node: ast::NodeId) -> bool { + fn inherits_doc_hidden(cx: &core::DocContext<'_, '_, '_>, mut node: hir::HirId) -> bool { while let Some(id) = cx.tcx.hir().get_enclosing_scope(node) { node = id; - if cx.tcx.hir().attrs(node).lists("doc").has_word("hidden") { + if cx.tcx.hir().attrs_by_hir_id(node).lists("doc").has_word("hidden") { return true; } - if node == ast::CRATE_NODE_ID { + if node == hir::CRATE_HIR_ID { break; } } @@ -324,21 +324,21 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { return false } - let def_node_id = match tcx.hir().as_local_node_id(def_did) { + let def_hir_id = match tcx.hir().as_local_hir_id(def_did) { Some(n) => n, None => return false }; let is_private = !self.cx.renderinfo.borrow().access_levels.is_public(def_did); - let is_hidden = inherits_doc_hidden(self.cx, def_node_id); + let is_hidden = inherits_doc_hidden(self.cx, def_hir_id); // Only inline if requested or if the item would otherwise be stripped. if (!please_inline && !is_private && !is_hidden) || is_no_inline { return false } - if !self.view_item_stack.insert(def_node_id) { return false } + if !self.view_item_stack.insert(def_hir_id) { return false } - let ret = match tcx.hir().get(def_node_id) { + let ret = match tcx.hir().get_by_hir_id(def_hir_id) { Node::Item(&hir::Item { node: hir::ItemKind::Mod(ref m), .. }) if glob => { let prev = mem::replace(&mut self.inlining, true); for i in &m.item_ids { @@ -371,7 +371,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { } _ => false, }; - self.view_item_stack.remove(&def_node_id); + self.view_item_stack.remove(&def_hir_id); ret }