Skip to content

Commit 37954df

Browse files
committed
doc: some HirIdification
1 parent b711079 commit 37954df

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
@@ -166,15 +166,6 @@ impl<'tcx> DocContext<'tcx> {
166166

167167
/// Like the function of the same name on the HIR map, but skips calling it on fake DefIds.
168168
/// (This avoids a slice-index-out-of-bounds panic.)
169-
pub fn as_local_node_id(&self, def_id: DefId) -> Option<ast::NodeId> {
170-
if self.all_fake_def_ids.borrow().contains(&def_id) {
171-
None
172-
} else {
173-
self.tcx.hir().as_local_node_id(def_id)
174-
}
175-
}
176-
177-
// FIXME(@ljedrz): remove the NodeId variant
178169
pub fn as_local_hir_id(&self, def_id: DefId) -> Option<HirId> {
179170
if self.all_fake_def_ids.borrow().contains(&def_id) {
180171
None

src/librustdoc/passes/collect_intra_doc_links.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub fn collect_intra_doc_links(krate: Crate, cx: &DocContext<'_>) -> Crate {
3838

3939
struct LinkCollector<'a, 'tcx> {
4040
cx: &'a DocContext<'tcx>,
41-
mod_ids: Vec<ast::NodeId>,
41+
mod_ids: Vec<hir::HirId>,
4242
}
4343

4444
impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
@@ -55,7 +55,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
5555
path_str: &str,
5656
ns: Namespace,
5757
current_item: &Option<String>,
58-
parent_id: Option<ast::NodeId>)
58+
parent_id: Option<hir::HirId>)
5959
-> Result<(Def, Option<String>), ()>
6060
{
6161
let cx = self.cx;
@@ -64,8 +64,9 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
6464
// path.
6565
if let Some(id) = parent_id.or(self.mod_ids.last().cloned()) {
6666
// FIXME: `with_scope` requires the `NodeId` of a module.
67+
let node_id = cx.tcx.hir().hir_to_node_id(id);
6768
let result = cx.enter_resolver(|resolver| {
68-
resolver.with_scope(id, |resolver| {
69+
resolver.with_scope(node_id, |resolver| {
6970
resolver.resolve_str_path_error(DUMMY_SP, &path_str, ns == ValueNS)
7071
})
7172
});
@@ -127,7 +128,8 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
127128
}
128129

129130
// FIXME: `with_scope` requires the `NodeId` of a module.
130-
let ty = cx.enter_resolver(|resolver| resolver.with_scope(id, |resolver| {
131+
let node_id = cx.tcx.hir().hir_to_node_id(id);
132+
let ty = cx.enter_resolver(|resolver| resolver.with_scope(node_id, |resolver| {
131133
resolver.resolve_str_path_error(DUMMY_SP, &path, false)
132134
}))?;
133135
match ty.def {
@@ -215,11 +217,11 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
215217
};
216218

217219
// FIXME: get the resolver to work with non-local resolve scopes.
218-
let parent_node = self.cx.as_local_node_id(item.def_id).and_then(|node_id| {
220+
let parent_node = self.cx.as_local_hir_id(item.def_id).and_then(|hir_id| {
219221
// FIXME: this fails hard for impls in non-module scope, but is necessary for the
220222
// current `resolve()` implementation.
221-
match self.cx.tcx.hir().get_module_parent_node(node_id) {
222-
id if id != node_id => Some(id),
223+
match self.cx.tcx.hir().get_module_parent_node(hir_id) {
224+
id if id != hir_id => Some(id),
223225
_ => None,
224226
}
225227
});
@@ -238,9 +240,9 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
238240
}
239241
} else {
240242
match parent_node.or(self.mod_ids.last().cloned()) {
241-
Some(parent) if parent != ast::CRATE_NODE_ID => {
243+
Some(parent) if parent != hir::CRATE_HIR_ID => {
242244
// FIXME: can we pull the parent module's name from elsewhere?
243-
Some(self.cx.tcx.hir().name(parent).to_string())
245+
Some(self.cx.tcx.hir().name_by_hir_id(parent).to_string())
244246
}
245247
_ => None,
246248
}
@@ -257,7 +259,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
257259
};
258260

259261
if item.is_mod() && item.attrs.inner_docs {
260-
self.mod_ids.push(self.cx.tcx.hir().hir_to_node_id(item_hir_id.unwrap()));
262+
self.mod_ids.push(item_hir_id.unwrap());
261263
}
262264

263265
let cx = self.cx;
@@ -391,7 +393,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
391393
}
392394

393395
if item.is_mod() && !item.attrs.inner_docs {
394-
self.mod_ids.push(self.cx.tcx.hir().hir_to_node_id(item_hir_id.unwrap()));
396+
self.mod_ids.push(item_hir_id.unwrap());
395397
}
396398

397399
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> {
3131
pub module: Module,
3232
pub attrs: hir::HirVec<ast::Attribute>,
3333
pub cx: &'a core::DocContext<'tcx>,
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> RustdocVisitor<'a, 'tcx> {
4444
) -> RustdocVisitor<'a, 'tcx> {
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(),
@@ -271,13 +271,13 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
271271
om: &mut Module,
272272
please_inline: bool) -> bool {
273273

274-
fn inherits_doc_hidden(cx: &core::DocContext<'_>, mut node: ast::NodeId) -> bool {
274+
fn inherits_doc_hidden(cx: &core::DocContext<'_>, mut node: hir::HirId) -> bool {
275275
while let Some(id) = cx.tcx.hir().get_enclosing_scope(node) {
276276
node = id;
277-
if cx.tcx.hir().attrs(node).lists("doc").has_word("hidden") {
277+
if cx.tcx.hir().attrs_by_hir_id(node).lists("doc").has_word("hidden") {
278278
return true;
279279
}
280-
if node == ast::CRATE_NODE_ID {
280+
if node == hir::CRATE_HIR_ID {
281281
break;
282282
}
283283
}
@@ -326,21 +326,21 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
326326
return false
327327
}
328328

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

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

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

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

343-
let ret = match tcx.hir().get(def_node_id) {
343+
let ret = match tcx.hir().get_by_hir_id(def_hir_id) {
344344
Node::Item(&hir::Item { node: hir::ItemKind::Mod(ref m), .. }) if glob => {
345345
let prev = mem::replace(&mut self.inlining, true);
346346
for i in &m.item_ids {
@@ -373,7 +373,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
373373
}
374374
_ => false,
375375
};
376-
self.view_item_stack.remove(&def_node_id);
376+
self.view_item_stack.remove(&def_hir_id);
377377
ret
378378
}
379379

0 commit comments

Comments
 (0)