Skip to content

Commit 16b3081

Browse files
committed
doc: some HirIdification
1 parent 3b97954 commit 16b3081

File tree

3 files changed

+23
-30
lines changed

3 files changed

+23
-30
lines changed

src/librustdoc/core.rs

-9
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,6 @@ impl<'a, 'tcx, 'rcx> DocContext<'a, 'tcx, 'rcx> {
159159

160160
/// Like the function of the same name on the HIR map, but skips calling it on fake DefIds.
161161
/// (This avoids a slice-index-out-of-bounds panic.)
162-
pub fn as_local_node_id(&self, def_id: DefId) -> Option<ast::NodeId> {
163-
if self.all_fake_def_ids.borrow().contains(&def_id) {
164-
None
165-
} else {
166-
self.tcx.hir().as_local_node_id(def_id)
167-
}
168-
}
169-
170-
// FIXME(@ljedrz): remove the NodeId variant
171162
pub fn as_local_hir_id(&self, def_id: DefId) -> Option<HirId> {
172163
if self.all_fake_def_ids.borrow().contains(&def_id) {
173164
None

src/librustdoc/passes/collect_intra_doc_links.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ enum PathKind {
4949

5050
struct LinkCollector<'a, 'tcx: 'a, 'rcx: 'a> {
5151
cx: &'a DocContext<'a, 'tcx, 'rcx>,
52-
mod_ids: Vec<ast::NodeId>,
52+
mod_ids: Vec<hir::HirId>,
5353
is_nightly_build: bool,
5454
}
5555

@@ -69,7 +69,7 @@ impl<'a, 'tcx, 'rcx> LinkCollector<'a, 'tcx, 'rcx> {
6969
path_str: &str,
7070
is_val: bool,
7171
current_item: &Option<String>,
72-
parent_id: Option<ast::NodeId>)
72+
parent_id: Option<hir::HirId>)
7373
-> Result<(Def, Option<String>), ()>
7474
{
7575
let cx = self.cx;
@@ -78,8 +78,9 @@ impl<'a, 'tcx, 'rcx> LinkCollector<'a, 'tcx, 'rcx> {
7878
// path.
7979
if let Some(id) = parent_id.or(self.mod_ids.last().cloned()) {
8080
// FIXME: `with_scope` requires the `NodeId` of a module.
81+
let node_id = cx.tcx.hir().hir_to_node_id(id);
8182
let result = cx.resolver.borrow_mut()
82-
.with_scope(id,
83+
.with_scope(node_id,
8384
|resolver| {
8485
resolver.resolve_str_path_error(DUMMY_SP,
8586
&path_str, is_val)
@@ -142,8 +143,9 @@ impl<'a, 'tcx, 'rcx> LinkCollector<'a, 'tcx, 'rcx> {
142143
}
143144

144145
// FIXME: `with_scope` requires the `NodeId` of a module.
146+
let node_id = cx.tcx.hir().hir_to_node_id(id);
145147
let ty = cx.resolver.borrow_mut()
146-
.with_scope(id,
148+
.with_scope(node_id,
147149
|resolver| {
148150
resolver.resolve_str_path_error(DUMMY_SP, &path, false)
149151
})?;
@@ -232,11 +234,11 @@ impl<'a, 'tcx, 'rcx> DocFolder for LinkCollector<'a, 'tcx, 'rcx> {
232234
};
233235

234236
// FIXME: get the resolver to work with non-local resolve scopes.
235-
let parent_node = self.cx.as_local_node_id(item.def_id).and_then(|node_id| {
237+
let parent_node = self.cx.as_local_hir_id(item.def_id).and_then(|hir_id| {
236238
// FIXME: this fails hard for impls in non-module scope, but is necessary for the
237239
// current `resolve()` implementation.
238-
match self.cx.tcx.hir().get_module_parent_node(node_id) {
239-
id if id != node_id => Some(id),
240+
match self.cx.tcx.hir().get_module_parent_node(hir_id) {
241+
id if id != hir_id => Some(id),
240242
_ => None,
241243
}
242244
});
@@ -255,9 +257,9 @@ impl<'a, 'tcx, 'rcx> DocFolder for LinkCollector<'a, 'tcx, 'rcx> {
255257
}
256258
} else {
257259
match parent_node.or(self.mod_ids.last().cloned()) {
258-
Some(parent) if parent != ast::CRATE_NODE_ID => {
260+
Some(parent) if parent != hir::CRATE_HIR_ID => {
259261
// FIXME: can we pull the parent module's name from elsewhere?
260-
Some(self.cx.tcx.hir().name(parent).to_string())
262+
Some(self.cx.tcx.hir().name_by_hir_id(parent).to_string())
261263
}
262264
_ => None,
263265
}
@@ -274,7 +276,7 @@ impl<'a, 'tcx, 'rcx> DocFolder for LinkCollector<'a, 'tcx, 'rcx> {
274276
};
275277

276278
if item.is_mod() && item.attrs.inner_docs {
277-
self.mod_ids.push(self.cx.tcx.hir().hir_to_node_id(item_hir_id.unwrap()));
279+
self.mod_ids.push(item_hir_id.unwrap());
278280
}
279281

280282
let cx = self.cx;
@@ -421,7 +423,7 @@ impl<'a, 'tcx, 'rcx> DocFolder for LinkCollector<'a, 'tcx, 'rcx> {
421423
}
422424

423425
if item.is_mod() && !item.attrs.inner_docs {
424-
self.mod_ids.push(self.cx.tcx.hir().hir_to_node_id(item_hir_id.unwrap()));
426+
self.mod_ids.push(item_hir_id.unwrap());
425427
}
426428

427429
if item.is_mod() {

src/librustdoc/visit_ast.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub struct RustdocVisitor<'a, 'tcx: 'a, 'rcx: 'a> {
3131
pub module: Module,
3232
pub attrs: hir::HirVec<ast::Attribute>,
3333
pub cx: &'a core::DocContext<'a, 'tcx, 'rcx>,
34-
view_item_stack: FxHashSet<ast::NodeId>,
34+
view_item_stack: FxHashSet<hir::HirId>,
3535
inlining: bool,
3636
/// Are the current module and all of its parents public?
3737
inside_public_path: bool,
@@ -44,7 +44,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
4444
) -> RustdocVisitor<'a, 'tcx, 'rcx> {
4545
// If the root is re-exported, terminate all recursion.
4646
let mut stack = FxHashSet::default();
47-
stack.insert(ast::CRATE_NODE_ID);
47+
stack.insert(hir::CRATE_HIR_ID);
4848
RustdocVisitor {
4949
module: Module::new(None),
5050
attrs: hir::HirVec::new(),
@@ -269,13 +269,13 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
269269
om: &mut Module,
270270
please_inline: bool) -> bool {
271271

272-
fn inherits_doc_hidden(cx: &core::DocContext<'_, '_, '_>, mut node: ast::NodeId) -> bool {
272+
fn inherits_doc_hidden(cx: &core::DocContext<'_, '_, '_>, mut node: hir::HirId) -> bool {
273273
while let Some(id) = cx.tcx.hir().get_enclosing_scope(node) {
274274
node = id;
275-
if cx.tcx.hir().attrs(node).lists("doc").has_word("hidden") {
275+
if cx.tcx.hir().attrs_by_hir_id(node).lists("doc").has_word("hidden") {
276276
return true;
277277
}
278-
if node == ast::CRATE_NODE_ID {
278+
if node == hir::CRATE_HIR_ID {
279279
break;
280280
}
281281
}
@@ -324,21 +324,21 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
324324
return false
325325
}
326326

327-
let def_node_id = match tcx.hir().as_local_node_id(def_did) {
327+
let def_hir_id = match tcx.hir().as_local_hir_id(def_did) {
328328
Some(n) => n, None => return false
329329
};
330330

331331
let is_private = !self.cx.renderinfo.borrow().access_levels.is_public(def_did);
332-
let is_hidden = inherits_doc_hidden(self.cx, def_node_id);
332+
let is_hidden = inherits_doc_hidden(self.cx, def_hir_id);
333333

334334
// Only inline if requested or if the item would otherwise be stripped.
335335
if (!please_inline && !is_private && !is_hidden) || is_no_inline {
336336
return false
337337
}
338338

339-
if !self.view_item_stack.insert(def_node_id) { return false }
339+
if !self.view_item_stack.insert(def_hir_id) { return false }
340340

341-
let ret = match tcx.hir().get(def_node_id) {
341+
let ret = match tcx.hir().get_by_hir_id(def_hir_id) {
342342
Node::Item(&hir::Item { node: hir::ItemKind::Mod(ref m), .. }) if glob => {
343343
let prev = mem::replace(&mut self.inlining, true);
344344
for i in &m.item_ids {
@@ -371,7 +371,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
371371
}
372372
_ => false,
373373
};
374-
self.view_item_stack.remove(&def_node_id);
374+
self.view_item_stack.remove(&def_hir_id);
375375
ret
376376
}
377377

0 commit comments

Comments
 (0)