Skip to content

Commit 0ee34e1

Browse files
In case a foreign item has doc(hidden) attribute, we simply merged its attributes
with the re-export's, making it being removed once in the `strip_hidden` pass. The solution was to use the same as for local reexported items: merge attributes, but not some of them (like `doc(hidden)`).
1 parent 20ed971 commit 0ee34e1

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/librustdoc/clean/inline.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ pub(crate) fn try_inline(
6363

6464
let import_def_id = attrs.and_then(|(_, def_id)| def_id);
6565

66-
let (attrs, cfg) = merge_attrs(cx, load_attrs(cx, did), attrs);
67-
6866
let kind = match res {
6967
Res::Def(DefKind::Trait, did) => {
7068
record_extern_fqn(cx, did, ItemType::Trait);
@@ -134,7 +132,11 @@ pub(crate) fn try_inline(
134132
cx.with_param_env(did, |cx| clean::ConstantItem(build_const(cx, did)))
135133
}
136134
Res::Def(DefKind::Macro(kind), did) => {
137-
let mac = build_macro(cx, did, name, import_def_id, kind, attrs.is_doc_hidden());
135+
let is_doc_hidden = cx.tcx.is_doc_hidden(did)
136+
|| attrs_without_docs
137+
.map(|(attrs, _)| attrs)
138+
.is_some_and(|attrs| utils::attrs_have_doc_flag(attrs.iter(), sym::hidden));
139+
let mac = build_macro(cx, did, name, import_def_id, kind, is_doc_hidden);
138140

139141
let type_kind = match kind {
140142
MacroKind::Bang => ItemType::Macro,
@@ -148,8 +150,14 @@ pub(crate) fn try_inline(
148150
};
149151

150152
cx.inlined.insert(did.into());
151-
let mut item =
152-
clean::Item::from_def_id_and_attrs_and_parts(did, Some(name), kind, Box::new(attrs), cfg);
153+
let mut item = crate::clean::generate_item_with_correct_attrs(
154+
cx,
155+
kind,
156+
did,
157+
name,
158+
import_def_id.and_then(|def_id| def_id.as_local()),
159+
None,
160+
);
153161
// The visibility needs to reflect the one from the reexport and not from the "source" DefId.
154162
item.inline_stmt_id = import_def_id;
155163
ret.push(item);
@@ -179,6 +187,7 @@ pub(crate) fn try_inline_glob(
179187
.iter()
180188
.filter(|child| !child.reexport_chain.is_empty())
181189
.filter_map(|child| child.res.opt_def_id())
190+
.filter(|def_id| !cx.tcx.is_doc_hidden(def_id))
182191
.collect();
183192
let attrs = cx.tcx.hir().attrs(import.hir_id());
184193
let mut items = build_module_items(

src/librustdoc/clean/utils.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,14 @@ pub(crate) fn find_nearest_parent_module(tcx: TyCtxt<'_>, def_id: DefId) -> Opti
581581
/// This function exists because it runs on `hir::Attributes` whereas the other is a
582582
/// `clean::Attributes` method.
583583
pub(crate) fn has_doc_flag(tcx: TyCtxt<'_>, did: DefId, flag: Symbol) -> bool {
584-
tcx.get_attrs(did, sym::doc)
584+
attrs_have_doc_flag(tcx.get_attrs(did, sym::doc), flag)
585+
}
586+
587+
pub(crate) fn attrs_have_doc_flag<'a>(
588+
mut attrs: impl Iterator<Item = &'a ast::Attribute>,
589+
flag: Symbol,
590+
) -> bool {
591+
attrs
585592
.any(|attr| attr.meta_item_list().is_some_and(|l| rustc_attr::list_contains_name(&l, flag)))
586593
}
587594

0 commit comments

Comments
 (0)