Skip to content

Commit 3ed1c87

Browse files
committed
rustdoc: fix attrs of locally reexported foreign items
1 parent f7321be commit 3ed1c87

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

src/librustdoc/clean/mod.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ use crate::visit_ast::Module as DocModule;
6666
pub(crate) fn clean_doc_module<'tcx>(doc: &DocModule<'tcx>, cx: &mut DocContext<'tcx>) -> Item {
6767
let mut items: Vec<Item> = vec![];
6868
let mut inserted = FxHashSet::default();
69-
items.extend(doc.foreigns.iter().map(|(item, renamed)| {
70-
let item = clean_maybe_renamed_foreign_item(cx, item, *renamed);
69+
items.extend(doc.foreigns.iter().map(|(item, renamed, import_id)| {
70+
let item = clean_maybe_renamed_foreign_item(cx, item, *renamed, *import_id);
7171
if let Some(name) = item.name
7272
&& (cx.render_options.document_hidden || !item.is_doc_hidden())
7373
{
@@ -3134,6 +3134,7 @@ fn clean_maybe_renamed_foreign_item<'tcx>(
31343134
cx: &mut DocContext<'tcx>,
31353135
item: &hir::ForeignItem<'tcx>,
31363136
renamed: Option<Symbol>,
3137+
import_id: Option<LocalDefId>,
31373138
) -> Item {
31383139
let def_id = item.owner_id.to_def_id();
31393140
cx.with_param_env(def_id, |cx| {
@@ -3149,11 +3150,13 @@ fn clean_maybe_renamed_foreign_item<'tcx>(
31493150
hir::ForeignItemKind::Type => ForeignTypeItem,
31503151
};
31513152

3152-
Item::from_def_id_and_parts(
3153-
item.owner_id.def_id.to_def_id(),
3154-
Some(renamed.unwrap_or(item.ident.name)),
3155-
kind,
3153+
generate_item_with_correct_attrs(
31563154
cx,
3155+
kind,
3156+
item.owner_id.def_id.to_def_id(),
3157+
item.ident.name,
3158+
import_id,
3159+
renamed,
31573160
)
31583161
})
31593162
}

src/librustdoc/visit_ast.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,18 @@ pub(crate) struct Module<'hir> {
3838
(LocalDefId, Option<Symbol>),
3939
(&'hir hir::Item<'hir>, Option<Symbol>, Option<LocalDefId>),
4040
>,
41-
/// Same as for `items`.
41+
42+
/// (def_id, renamed) -> (res, local_import_id)
43+
///
44+
/// `inlined_foreigns` only contains `extern` items
45+
/// that are cross-crate inlined.
46+
///
47+
/// Locally inlined `extern` items are
48+
/// stored in `foreigns` with the `import_id` set,
49+
/// analogous to how `items` is.
4250
pub(crate) inlined_foreigns: FxIndexMap<(DefId, Option<Symbol>), (Res, LocalDefId)>,
43-
pub(crate) foreigns: Vec<(&'hir hir::ForeignItem<'hir>, Option<Symbol>)>,
51+
/// (item, renamed, import_id)
52+
pub(crate) foreigns: Vec<(&'hir hir::ForeignItem<'hir>, Option<Symbol>, Option<LocalDefId>)>,
4453
}
4554

4655
impl Module<'_> {
@@ -327,7 +336,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
327336
}
328337
Node::ForeignItem(it) if !glob => {
329338
let prev = mem::replace(&mut self.inlining, true);
330-
self.visit_foreign_item_inner(it, renamed);
339+
self.visit_foreign_item_inner(it, renamed, Some(def_id));
331340
self.inlining = prev;
332341
true
333342
}
@@ -432,7 +441,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
432441
hir::ItemKind::ForeignMod { items, .. } => {
433442
for item in items {
434443
let item = tcx.hir_foreign_item(item.id);
435-
self.visit_foreign_item_inner(item, None);
444+
self.visit_foreign_item_inner(item, None, None);
436445
}
437446
}
438447
// If we're inlining, skip private items.
@@ -527,10 +536,11 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
527536
&mut self,
528537
item: &'tcx hir::ForeignItem<'_>,
529538
renamed: Option<Symbol>,
539+
import_id: Option<LocalDefId>,
530540
) {
531541
// If inlining we only want to include public functions.
532542
if !self.inlining || self.cx.tcx.visibility(item.owner_id).is_public() {
533-
self.modules.last_mut().unwrap().foreigns.push((item, renamed));
543+
self.modules.last_mut().unwrap().foreigns.push((item, renamed, import_id));
534544
}
535545
}
536546

0 commit comments

Comments
 (0)