Skip to content

Commit 7888406

Browse files
committed
Fix wrong names when inlining
1 parent 8c94f8b commit 7888406

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

src/librustdoc/clean/mod.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -1922,13 +1922,17 @@ impl Clean<BareFunctionDecl> for hir::BareFnTy<'_> {
19221922
}
19231923
}
19241924

1925-
impl Clean<Item> for hir::Item<'_> {
1925+
impl Clean<Item> for (&hir::Item<'_>, Option<Ident>) {
19261926
fn clean(&self, cx: &DocContext<'_>) -> Item {
19271927
use hir::ItemKind;
19281928

1929-
let def_id = cx.tcx.hir().local_def_id(self.hir_id).to_def_id();
1930-
let name = cx.tcx.hir().name(self.hir_id);
1931-
let kind = match self.kind {
1929+
let (item, renamed) = self;
1930+
let def_id = cx.tcx.hir().local_def_id(item.hir_id).to_def_id();
1931+
let name = match renamed {
1932+
Some(ident) => ident.name,
1933+
None => cx.tcx.hir().name(item.hir_id),
1934+
};
1935+
let kind = match item.kind {
19321936
ItemKind::Static(ty, mutability, body_id) => StaticItem(Static {
19331937
type_: ty.clean(cx),
19341938
mutability,

src/librustdoc/doctree.rs

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

55
use rustc_ast as ast;
66
use rustc_span::hygiene::MacroKind;
7-
use rustc_span::{self, Span, Symbol};
7+
use rustc_span::{self, symbol::Ident, Span, Symbol};
88

99
use rustc_hir as hir;
1010
use rustc_hir::def_id::CrateNum;
@@ -20,7 +20,8 @@ crate struct Module<'hir> {
2020
crate fns: Vec<Function<'hir>>,
2121
crate mods: Vec<Module<'hir>>,
2222
crate id: hir::HirId,
23-
crate items: Vec<&'hir hir::Item<'hir>>,
23+
// (item, renamed)
24+
crate items: Vec<(&'hir hir::Item<'hir>, Option<Ident>)>,
2425
crate traits: Vec<Trait<'hir>>,
2526
crate impls: Vec<Impl<'hir>>,
2627
crate foreigns: Vec<ForeignItem<'hir>>,

src/librustdoc/visit_ast.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -370,21 +370,21 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
370370
Some(ident.name),
371371
));
372372
}
373-
hir::ItemKind::Enum(..) => om.items.push(item),
374-
hir::ItemKind::Struct(..) => om.items.push(item),
375-
hir::ItemKind::Union(..) => om.items.push(item),
376373
hir::ItemKind::Fn(ref sig, ref gen, body) => {
377374
self.visit_fn(om, item, ident.name, &sig.decl, sig.header, gen, body)
378375
}
379-
hir::ItemKind::TyAlias(..)
376+
hir::ItemKind::Enum(..)
377+
| hir::ItemKind::Struct(..)
378+
| hir::ItemKind::Union(..)
379+
| hir::ItemKind::TyAlias(..)
380380
| hir::ItemKind::OpaqueTy(..)
381381
| hir::ItemKind::Static(..)
382-
| hir::ItemKind::TraitAlias(..) => om.items.push(item),
382+
| hir::ItemKind::TraitAlias(..) => om.items.push((item, renamed)),
383383
hir::ItemKind::Const(..) => {
384384
// Underscore constants do not correspond to a nameable item and
385385
// so are never useful in documentation.
386386
if ident.name != kw::Underscore {
387-
om.items.push(item);
387+
om.items.push((item, renamed));
388388
}
389389
}
390390
hir::ItemKind::Trait(is_auto, unsafety, ref generics, ref bounds, ref item_ids) => {

0 commit comments

Comments
 (0)