Skip to content

Commit 88c6cf8

Browse files
committed
Pass around Symbols instead of Idents in doctree
The span was unused.
1 parent 18aa5ee commit 88c6cf8

File tree

3 files changed

+19
-22
lines changed

3 files changed

+19
-22
lines changed

src/librustdoc/clean/mod.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -1989,16 +1989,13 @@ impl Clean<BareFunctionDecl> for hir::BareFnTy<'_> {
19891989
}
19901990
}
19911991

1992-
impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Ident>) {
1992+
impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Symbol>) {
19931993
fn clean(&self, cx: &DocContext<'_>) -> Vec<Item> {
19941994
use hir::ItemKind;
19951995

19961996
let (item, renamed) = self;
19971997
let def_id = cx.tcx.hir().local_def_id(item.hir_id).to_def_id();
1998-
let mut name = match renamed {
1999-
Some(ident) => ident.name,
2000-
None => cx.tcx.hir().name(item.hir_id),
2001-
};
1998+
let mut name = renamed.unwrap_or_else(|| cx.tcx.hir().name(item.hir_id));
20021999
cx.with_param_env(def_id, || {
20032000
let kind = match item.kind {
20042001
ItemKind::Static(ty, mutability, body_id) => StaticItem(Static {
@@ -2291,7 +2288,7 @@ impl Clean<Vec<Item>> for doctree::Import<'_> {
22912288
}
22922289
}
22932290

2294-
impl Clean<Item> for (&hir::ForeignItem<'_>, Option<Ident>) {
2291+
impl Clean<Item> for (&hir::ForeignItem<'_>, Option<Symbol>) {
22952292
fn clean(&self, cx: &DocContext<'_>) -> Item {
22962293
let (item, renamed) = self;
22972294
cx.with_param_env(cx.tcx.hir().local_def_id(item.hir_id).to_def_id(), || {
@@ -2325,18 +2322,18 @@ impl Clean<Item> for (&hir::ForeignItem<'_>, Option<Ident>) {
23252322

23262323
Item::from_hir_id_and_parts(
23272324
item.hir_id,
2328-
Some(renamed.unwrap_or(item.ident).name),
2325+
Some(renamed.unwrap_or(item.ident.name)),
23292326
kind,
23302327
cx,
23312328
)
23322329
})
23332330
}
23342331
}
23352332

2336-
impl Clean<Item> for (&hir::MacroDef<'_>, Option<Ident>) {
2333+
impl Clean<Item> for (&hir::MacroDef<'_>, Option<Symbol>) {
23372334
fn clean(&self, cx: &DocContext<'_>) -> Item {
23382335
let (item, renamed) = self;
2339-
let name = renamed.unwrap_or(item.ident).name;
2336+
let name = renamed.unwrap_or(item.ident.name);
23402337
let tts = item.ast.body.inner_tokens().trees().collect::<Vec<_>>();
23412338
// Extract the spans of all matchers. They represent the "interface" of the macro.
23422339
let matchers = tts.chunks(4).map(|arm| arm[0].span()).collect::<Vec<_>>();

src/librustdoc/doctree.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
crate use self::StructType::*;
44

55
use rustc_ast as ast;
6-
use rustc_span::{self, symbol::Ident, Span, Symbol};
6+
use rustc_span::{self, Span, Symbol};
77

88
use rustc_hir as hir;
99

@@ -16,9 +16,9 @@ crate struct Module<'hir> {
1616
crate mods: Vec<Module<'hir>>,
1717
crate id: hir::HirId,
1818
// (item, renamed)
19-
crate items: Vec<(&'hir hir::Item<'hir>, Option<Ident>)>,
20-
crate foreigns: Vec<(&'hir hir::ForeignItem<'hir>, Option<Ident>)>,
21-
crate macros: Vec<(&'hir hir::MacroDef<'hir>, Option<Ident>)>,
19+
crate items: Vec<(&'hir hir::Item<'hir>, Option<Symbol>)>,
20+
crate foreigns: Vec<(&'hir hir::ForeignItem<'hir>, Option<Symbol>)>,
21+
crate macros: Vec<(&'hir hir::MacroDef<'hir>, Option<Symbol>)>,
2222
crate is_crate: bool,
2323
}
2424

src/librustdoc/visit_ast.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_hir::Node;
1010
use rustc_middle::middle::privacy::AccessLevel;
1111
use rustc_middle::ty::TyCtxt;
1212
use rustc_span::source_map::Spanned;
13-
use rustc_span::symbol::{kw, sym, Ident, Symbol};
13+
use rustc_span::symbol::{kw, sym, Symbol};
1414
use rustc_span::{self, Span};
1515

1616
use std::mem;
@@ -116,7 +116,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
116116
&mut self,
117117
id: hir::HirId,
118118
res: Res,
119-
renamed: Option<Ident>,
119+
renamed: Option<Symbol>,
120120
glob: bool,
121121
om: &mut Module<'tcx>,
122122
please_inline: bool,
@@ -226,11 +226,11 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
226226
fn visit_item(
227227
&mut self,
228228
item: &'tcx hir::Item<'_>,
229-
renamed: Option<Ident>,
229+
renamed: Option<Symbol>,
230230
om: &mut Module<'tcx>,
231231
) {
232232
debug!("visiting item {:?}", item);
233-
let ident = renamed.unwrap_or(item.ident);
233+
let name = renamed.unwrap_or(item.ident.name);
234234

235235
if item.vis.node.is_pub() {
236236
let def_id = self.cx.tcx.hir().local_def_id(item.hir_id);
@@ -266,7 +266,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
266266
}
267267
_ => false,
268268
});
269-
let ident = if is_glob { None } else { Some(ident) };
269+
let ident = if is_glob { None } else { Some(name) };
270270
if self.maybe_inline_local(
271271
item.hir_id,
272272
path.res,
@@ -280,7 +280,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
280280
}
281281

282282
om.imports.push(Import {
283-
name: ident.name,
283+
name,
284284
id: item.hir_id,
285285
vis: &item.vis,
286286
attrs: &item.attrs,
@@ -296,7 +296,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
296296
&item.vis,
297297
item.hir_id,
298298
m,
299-
Some(ident.name),
299+
Some(name),
300300
));
301301
}
302302
hir::ItemKind::Fn(..)
@@ -312,7 +312,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
312312
hir::ItemKind::Const(..) => {
313313
// Underscore constants do not correspond to a nameable item and
314314
// so are never useful in documentation.
315-
if ident.name != kw::Underscore {
315+
if name != kw::Underscore {
316316
om.items.push((item, renamed));
317317
}
318318
}
@@ -329,7 +329,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
329329
fn visit_foreign_item(
330330
&mut self,
331331
item: &'tcx hir::ForeignItem<'_>,
332-
renamed: Option<Ident>,
332+
renamed: Option<Symbol>,
333333
om: &mut Module<'tcx>,
334334
) {
335335
// If inlining we only want to include public functions.

0 commit comments

Comments
 (0)