Skip to content

Commit 0e8085a

Browse files
authored
Rollup merge of #109266 - petrochenkov:docice4, r=petrochenkov
rustdoc: Correctly merge import's and its target's docs in one more case Fixes #108334. Fixes #108378. Fixes #108658.
2 parents 96d5dd6 + 5e0fc04 commit 0e8085a

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/librustdoc/clean/mod.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ use std::hash::Hash;
3939
use std::mem;
4040
use thin_vec::ThinVec;
4141

42+
use crate::clean::inline::merge_attrs;
4243
use crate::core::{self, DocContext, ImplTraitParam};
4344
use crate::formats::item_type::ItemType;
4445
use crate::visit_ast::Module as DocModule;
@@ -2373,21 +2374,22 @@ fn clean_maybe_renamed_item<'tcx>(
23732374
_ => unreachable!("not yet converted"),
23742375
};
23752376

2376-
let mut extra_attrs = Vec::new();
2377+
let mut import_attrs = Vec::new();
2378+
let mut target_attrs = Vec::new();
23772379
if let Some(import_id) = import_id &&
23782380
let Some(hir::Node::Item(use_node)) = cx.tcx.hir().find_by_def_id(import_id)
23792381
{
23802382
let is_inline = inline::load_attrs(cx, import_id.to_def_id()).lists(sym::doc).get_word_attr(sym::inline).is_some();
23812383
// Then we get all the various imports' attributes.
2382-
get_all_import_attributes(use_node, cx.tcx, item.owner_id.def_id, &mut extra_attrs, is_inline);
2383-
add_without_unwanted_attributes(&mut extra_attrs, inline::load_attrs(cx, def_id), is_inline);
2384+
get_all_import_attributes(use_node, cx.tcx, item.owner_id.def_id, &mut import_attrs, is_inline);
2385+
add_without_unwanted_attributes(&mut target_attrs, inline::load_attrs(cx, def_id), is_inline);
23842386
} else {
23852387
// We only keep the item's attributes.
2386-
extra_attrs.extend_from_slice(inline::load_attrs(cx, def_id));
2388+
target_attrs.extend_from_slice(inline::load_attrs(cx, def_id));
23872389
}
23882390

2389-
let attrs = Attributes::from_ast(&extra_attrs);
2390-
let cfg = extra_attrs.cfg(cx.tcx, &cx.cache.hidden_cfg);
2391+
let import_parent = import_id.map(|import_id| cx.tcx.local_parent(import_id).to_def_id());
2392+
let (attrs, cfg) = merge_attrs(cx, import_parent, &target_attrs, Some(&import_attrs));
23912393

23922394
let mut item =
23932395
Item::from_def_id_and_attrs_and_parts(def_id, Some(name), kind, Box::new(attrs), cfg);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Import for `A` is inlined and doc comments on the import and `A` itself are merged.
2+
// After the merge they still have correct parent scopes to resolve both `[A]` and `[B]`.
3+
4+
// check-pass
5+
6+
#![allow(rustdoc::private_intra_doc_links)]
7+
8+
mod m {
9+
/// [B]
10+
pub struct A {}
11+
12+
pub struct B {}
13+
}
14+
15+
/// [A]
16+
pub use m::A;

0 commit comments

Comments
 (0)