Skip to content

Commit c886d47

Browse files
committed
doc: partially HirIdify visit_ast
1 parent 46e4f4a commit c886d47

File tree

1 file changed

+38
-37
lines changed

1 file changed

+38
-37
lines changed

src/librustdoc/visit_ast.rs

+38-37
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
6666
}
6767
}
6868

69-
fn stability(&self, id: ast::NodeId) -> Option<attr::Stability> {
70-
self.cx.tcx.hir().opt_local_def_id(id)
69+
fn stability(&self, id: hir::HirId) -> Option<attr::Stability> {
70+
self.cx.tcx.hir().opt_local_def_id_from_hir_id(id)
7171
.and_then(|def_id| self.cx.tcx.lookup_stability(def_id)).cloned()
7272
}
7373

74-
fn deprecation(&self, id: ast::NodeId) -> Option<attr::Deprecation> {
75-
self.cx.tcx.hir().opt_local_def_id(id)
74+
fn deprecation(&self, id: hir::HirId) -> Option<attr::Deprecation> {
75+
self.cx.tcx.hir().opt_local_def_id_from_hir_id(id)
7676
.and_then(|def_id| self.cx.tcx.lookup_deprecation(def_id))
7777
}
7878

@@ -83,7 +83,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
8383
krate.attrs.clone(),
8484
Spanned { span: syntax_pos::DUMMY_SP,
8585
node: hir::VisibilityKind::Public },
86-
ast::CRATE_NODE_ID,
86+
hir::CRATE_HIR_ID,
8787
&krate.module,
8888
None);
8989
// Attach the crate's exported macros to the top-level module:
@@ -105,8 +105,8 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
105105
struct_type,
106106
name,
107107
vis: item.vis.clone(),
108-
stab: self.stability(item.id),
109-
depr: self.deprecation(item.id),
108+
stab: self.stability(item.hir_id),
109+
depr: self.deprecation(item.hir_id),
110110
attrs: item.attrs.clone(),
111111
generics: generics.clone(),
112112
fields: sd.fields().iter().cloned().collect(),
@@ -124,8 +124,8 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
124124
struct_type,
125125
name,
126126
vis: item.vis.clone(),
127-
stab: self.stability(item.id),
128-
depr: self.deprecation(item.id),
127+
stab: self.stability(item.hir_id),
128+
depr: self.deprecation(item.hir_id),
129129
attrs: item.attrs.clone(),
130130
generics: generics.clone(),
131131
fields: sd.fields().iter().cloned().collect(),
@@ -142,14 +142,14 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
142142
variants: def.variants.iter().map(|v| Variant {
143143
name: v.node.ident.name,
144144
attrs: v.node.attrs.clone(),
145-
stab: self.stability(v.node.data.id()),
146-
depr: self.deprecation(v.node.data.id()),
145+
stab: self.stability(v.node.data.hir_id()),
146+
depr: self.deprecation(v.node.data.hir_id()),
147147
def: v.node.data.clone(),
148148
whence: v.span,
149149
}).collect(),
150150
vis: it.vis.clone(),
151-
stab: self.stability(it.id),
152-
depr: self.deprecation(it.id),
151+
stab: self.stability(it.hir_id),
152+
depr: self.deprecation(it.hir_id),
153153
generics: params.clone(),
154154
attrs: it.attrs.clone(),
155155
id: it.id,
@@ -207,16 +207,16 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
207207
helpers,
208208
attrs: item.attrs.clone(),
209209
whence: item.span,
210-
stab: self.stability(item.id),
211-
depr: self.deprecation(item.id),
210+
stab: self.stability(item.hir_id),
211+
depr: self.deprecation(item.hir_id),
212212
});
213213
}
214214
None => {
215215
om.fns.push(Function {
216216
id: item.id,
217217
vis: item.vis.clone(),
218-
stab: self.stability(item.id),
219-
depr: self.deprecation(item.id),
218+
stab: self.stability(item.hir_id),
219+
depr: self.deprecation(item.hir_id),
220220
attrs: item.attrs.clone(),
221221
decl: fd.clone(),
222222
name,
@@ -230,7 +230,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
230230
}
231231

232232
pub fn visit_mod_contents(&mut self, span: Span, attrs: hir::HirVec<ast::Attribute>,
233-
vis: hir::Visibility, id: ast::NodeId,
233+
vis: hir::Visibility, id: hir::HirId,
234234
m: &hir::Mod,
235235
name: Option<ast::Name>) -> Module {
236236
let mut om = Module::new(name);
@@ -240,7 +240,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
240240
om.vis = vis.clone();
241241
om.stab = self.stability(id);
242242
om.depr = self.deprecation(id);
243-
om.id = id;
243+
om.id = self.cx.tcx.hir().hir_to_node_id(id);
244244
// Keep track of if there were any private modules in the path.
245245
let orig_inside_public_path = self.inside_public_path;
246246
self.inside_public_path &= vis.node.is_pub();
@@ -460,7 +460,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
460460
om.mods.push(self.visit_mod_contents(item.span,
461461
item.attrs.clone(),
462462
item.vis.clone(),
463-
item.id,
463+
item.hir_id,
464464
m,
465465
Some(ident.name)));
466466
},
@@ -481,8 +481,8 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
481481
attrs: item.attrs.clone(),
482482
whence: item.span,
483483
vis: item.vis.clone(),
484-
stab: self.stability(item.id),
485-
depr: self.deprecation(item.id),
484+
stab: self.stability(item.hir_id),
485+
depr: self.deprecation(item.hir_id),
486486
};
487487
om.typedefs.push(t);
488488
},
@@ -494,8 +494,8 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
494494
attrs: item.attrs.clone(),
495495
whence: item.span,
496496
vis: item.vis.clone(),
497-
stab: self.stability(item.id),
498-
depr: self.deprecation(item.id),
497+
stab: self.stability(item.hir_id),
498+
depr: self.deprecation(item.hir_id),
499499
};
500500
om.existentials.push(t);
501501
},
@@ -509,8 +509,8 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
509509
attrs: item.attrs.clone(),
510510
whence: item.span,
511511
vis: item.vis.clone(),
512-
stab: self.stability(item.id),
513-
depr: self.deprecation(item.id),
512+
stab: self.stability(item.hir_id),
513+
depr: self.deprecation(item.hir_id),
514514
};
515515
om.statics.push(s);
516516
},
@@ -523,8 +523,8 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
523523
attrs: item.attrs.clone(),
524524
whence: item.span,
525525
vis: item.vis.clone(),
526-
stab: self.stability(item.id),
527-
depr: self.deprecation(item.id),
526+
stab: self.stability(item.hir_id),
527+
depr: self.deprecation(item.hir_id),
528528
};
529529
om.constants.push(s);
530530
},
@@ -543,8 +543,8 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
543543
attrs: item.attrs.clone(),
544544
whence: item.span,
545545
vis: item.vis.clone(),
546-
stab: self.stability(item.id),
547-
depr: self.deprecation(item.id),
546+
stab: self.stability(item.hir_id),
547+
depr: self.deprecation(item.hir_id),
548548
};
549549
om.traits.push(t);
550550
},
@@ -557,8 +557,8 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
557557
attrs: item.attrs.clone(),
558558
whence: item.span,
559559
vis: item.vis.clone(),
560-
stab: self.stability(item.id),
561-
depr: self.deprecation(item.id),
560+
stab: self.stability(item.hir_id),
561+
depr: self.deprecation(item.hir_id),
562562
};
563563
om.trait_aliases.push(t);
564564
},
@@ -588,8 +588,8 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
588588
id: item.id,
589589
whence: item.span,
590590
vis: item.vis.clone(),
591-
stab: self.stability(item.id),
592-
depr: self.deprecation(item.id),
591+
stab: self.stability(item.hir_id),
592+
depr: self.deprecation(item.hir_id),
593593
};
594594
om.impls.push(i);
595595
}
@@ -609,13 +609,14 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
609609
let matchers = tts.chunks(4).map(|arm| arm[0].span()).collect();
610610

611611
Macro {
612-
def_id: self.cx.tcx.hir().local_def_id(def.id),
612+
613+
def_id: self.cx.tcx.hir().local_def_id_from_hir_id(def.hir_id),
613614
attrs: def.attrs.clone(),
614615
name: renamed.unwrap_or(def.name),
615616
whence: def.span,
616617
matchers,
617-
stab: self.stability(def.id),
618-
depr: self.deprecation(def.id),
618+
stab: self.stability(def.hir_id),
619+
depr: self.deprecation(def.hir_id),
619620
imported_from: None,
620621
}
621622
}

0 commit comments

Comments
 (0)