From 8da262139af11628512d1d9bce059310461a1fa8 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Thu, 14 Mar 2024 12:15:05 +0100 Subject: [PATCH 1/7] print ghosts --- src/librustdoc/html/render/print_item.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index d588f219739fe..4f74ae096fbaa 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -517,6 +517,11 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items: } _ => "", }; + let hidden_emoji = if myitem.is_doc_hidden() { + " ðŸ‘» " + } else { + "" + }; w.write_str(ITEM_TABLE_ROW_OPEN); let docs = @@ -531,6 +536,7 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items: "
\ {name}\ {visibility_emoji}\ + {hidden_emoji}\ {unsafety_flag}\ {stab_tags}\
\ From 343c77c102608e7b9090789ea365a21d0156d191 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Thu, 14 Mar 2024 12:39:27 +0100 Subject: [PATCH 2/7] Refactor visibility_print_with_space to directly take an item --- src/librustdoc/clean/inline.rs | 16 ++++++-- src/librustdoc/clean/mod.rs | 3 +- src/librustdoc/clean/types.rs | 2 +- src/librustdoc/clean/utils.rs | 5 ++- src/librustdoc/html/format.rs | 12 +++--- src/librustdoc/html/render/mod.rs | 7 ++-- src/librustdoc/html/render/print_item.rs | 48 ++++++++---------------- 7 files changed, 42 insertions(+), 51 deletions(-) diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 77a78f57e950c..6f86c6450d969 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -62,6 +62,9 @@ pub(crate) fn try_inline( attrs_without_docs.as_ref().map(|(attrs, def_id)| (&attrs[..], *def_id)); let import_def_id = attrs.and_then(|(_, def_id)| def_id); + + let (attrs, cfg) = merge_attrs(cx, load_attrs(cx, did), attrs); + let kind = match res { Res::Def(DefKind::Trait, did) => { record_extern_fqn(cx, did, ItemType::Trait); @@ -131,7 +134,7 @@ pub(crate) fn try_inline( cx.with_param_env(did, |cx| clean::ConstantItem(build_const(cx, did))) } Res::Def(DefKind::Macro(kind), did) => { - let mac = build_macro(cx, did, name, import_def_id, kind); + let mac = build_macro(cx, did, name, import_def_id, kind, attrs.is_doc_hidden()); let type_kind = match kind { MacroKind::Bang => ItemType::Macro, @@ -144,7 +147,6 @@ pub(crate) fn try_inline( _ => return None, }; - let (attrs, cfg) = merge_attrs(cx, load_attrs(cx, did), attrs); cx.inlined.insert(did.into()); let mut item = clean::Item::from_def_id_and_attrs_and_parts(did, Some(name), kind, Box::new(attrs), cfg); @@ -751,6 +753,7 @@ fn build_macro( name: Symbol, import_def_id: Option, macro_kind: MacroKind, + is_doc_hidden: bool, ) -> clean::ItemKind { match CStore::from_tcx(cx.tcx).load_macro_untracked(def_id, cx.tcx) { LoadedMacro::MacroDef(item_def, _) => match macro_kind { @@ -758,7 +761,14 @@ fn build_macro( if let ast::ItemKind::MacroDef(ref def) = item_def.kind { let vis = cx.tcx.visibility(import_def_id.unwrap_or(def_id)); clean::MacroItem(clean::Macro { - source: utils::display_macro_source(cx, name, def, def_id, vis), + source: utils::display_macro_source( + cx, + name, + def, + def_id, + vis, + is_doc_hidden, + ), }) } else { unreachable!() diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index b32d3ad562d03..ec4c6d991f1ad 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -2796,7 +2796,8 @@ fn clean_maybe_renamed_item<'tcx>( ItemKind::Macro(ref macro_def, MacroKind::Bang) => { let ty_vis = cx.tcx.visibility(def_id); MacroItem(Macro { - source: display_macro_source(cx, name, macro_def, def_id, ty_vis), + // FIXME this shouldn't be false + source: display_macro_source(cx, name, macro_def, def_id, ty_vis, false), }) } ItemKind::Macro(_, macro_kind) => clean_proc_macro(item, &mut name, macro_kind, cx), diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index c35baeb4cf587..a51f6360df2a4 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -1161,7 +1161,7 @@ impl Attributes { false } - fn is_doc_hidden(&self) -> bool { + pub(crate) fn is_doc_hidden(&self) -> bool { self.has_doc_flag(sym::hidden) } diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index 57916ff0ff781..5464aa63ea806 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -625,6 +625,7 @@ pub(super) fn display_macro_source( def: &ast::MacroDef, def_id: DefId, vis: ty::Visibility, + is_doc_hidden: bool, ) -> String { // Extract the spans of all matchers. They represent the "interface" of the macro. let matchers = def.body.tokens.chunks(4).map(|arm| &arm[0]); @@ -635,7 +636,7 @@ pub(super) fn display_macro_source( if matchers.len() <= 1 { format!( "{vis}macro {name}{matchers} {{\n ...\n}}", - vis = visibility_to_src_with_space(Some(vis), cx.tcx, def_id), + vis = visibility_to_src_with_space(Some(vis), cx.tcx, def_id, is_doc_hidden), matchers = matchers .map(|matcher| render_macro_matcher(cx.tcx, matcher)) .collect::(), @@ -643,7 +644,7 @@ pub(super) fn display_macro_source( } else { format!( "{vis}macro {name} {{\n{arms}}}", - vis = visibility_to_src_with_space(Some(vis), cx.tcx, def_id), + vis = visibility_to_src_with_space(Some(vis), cx.tcx, def_id, is_doc_hidden), arms = render_macro_arms(cx.tcx, matchers, ","), ) } diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index afd5eb42d019d..1973c2a6021ce 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -29,8 +29,7 @@ use rustc_target::spec::abi::Abi; use itertools::Itertools; use crate::clean::{ - self, types::ExternalLocation, utils::find_nearest_parent_module, ExternalCrate, ItemId, - PrimitiveType, + self, types::ExternalLocation, utils::find_nearest_parent_module, ExternalCrate, PrimitiveType, }; use crate::formats::cache::Cache; use crate::formats::item_type::ItemType; @@ -1506,20 +1505,18 @@ impl clean::FnDecl { } pub(crate) fn visibility_print_with_space<'a, 'tcx: 'a>( - visibility: Option>, - item_did: ItemId, + item: &clean::Item, cx: &'a Context<'tcx>, ) -> impl Display + 'a + Captures<'tcx> { use std::fmt::Write as _; - - let to_print: Cow<'static, str> = match visibility { + let to_print: Cow<'static, str> = match item.visibility(cx.tcx()) { None => "".into(), Some(ty::Visibility::Public) => "pub ".into(), Some(ty::Visibility::Restricted(vis_did)) => { // FIXME(camelid): This may not work correctly if `item_did` is a module. // However, rustdoc currently never displays a module's // visibility, so it shouldn't matter. - let parent_module = find_nearest_parent_module(cx.tcx(), item_did.expect_def_id()); + let parent_module = find_nearest_parent_module(cx.tcx(), item.item_id.expect_def_id()); if vis_did.is_crate_root() { "pub(crate) ".into() @@ -1557,6 +1554,7 @@ pub(crate) fn visibility_to_src_with_space<'a, 'tcx: 'a>( visibility: Option>, tcx: TyCtxt<'tcx>, item_did: DefId, + _is_doc_hidden: bool, ) -> impl Display + 'a + Captures<'tcx> { let to_print: Cow<'static, str> = match visibility { None => "".into(), diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index fe83095f944ab..54d51ca009b29 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -883,7 +883,7 @@ fn assoc_const( w, "{indent}{vis}const {name}{generics}: {ty}", indent = " ".repeat(indent), - vis = visibility_print_with_space(it.visibility(tcx), it.item_id, cx), + vis = visibility_print_with_space(it, cx), href = assoc_href_attr(it, link, cx), name = it.name.as_ref().unwrap(), generics = generics.print(cx), @@ -912,12 +912,11 @@ fn assoc_type( indent: usize, cx: &Context<'_>, ) { - let tcx = cx.tcx(); write!( w, "{indent}{vis}type {name}{generics}", indent = " ".repeat(indent), - vis = visibility_print_with_space(it.visibility(tcx), it.item_id, cx), + vis = visibility_print_with_space(it, cx), href = assoc_href_attr(it, link, cx), name = it.name.as_ref().unwrap(), generics = generics.print(cx), @@ -945,7 +944,7 @@ fn assoc_method( let tcx = cx.tcx(); let header = meth.fn_header(tcx).expect("Trying to get header from a non-function item"); let name = meth.name.as_ref().unwrap(); - let vis = visibility_print_with_space(meth.visibility(tcx), meth.item_id, cx).to_string(); + let vis = visibility_print_with_space(meth, cx).to_string(); let defaultness = print_default_space(meth.is_default()); // FIXME: Once https://github.com/rust-lang/rust/issues/67792 is implemented, we can remove // this condition. diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 4f74ae096fbaa..d2a03d5840278 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -445,14 +445,14 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items: Some(src) => write!( w, "
{}extern crate {} as {};", - visibility_print_with_space(myitem.visibility(tcx), myitem.item_id, cx), + visibility_print_with_space(myitem, cx), anchor(myitem.item_id.expect_def_id(), src, cx), myitem.name.unwrap(), ), None => write!( w, "
{}extern crate {};", - visibility_print_with_space(myitem.visibility(tcx), myitem.item_id, cx), + visibility_print_with_space(myitem, cx), anchor(myitem.item_id.expect_def_id(), myitem.name.unwrap(), cx), ), } @@ -491,7 +491,7 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items: {vis}{imp}\
\ {stab_tags_before}{stab_tags}{stab_tags_after}", - vis = visibility_print_with_space(myitem.visibility(tcx), myitem.item_id, cx), + vis = visibility_print_with_space(myitem, cx), imp = import.print(cx), ); w.write_str(ITEM_TABLE_ROW_CLOSE); @@ -631,7 +631,7 @@ fn item_function(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, f: &cle let unsafety = header.unsafety.print_with_space(); let abi = print_abi_with_space(header.abi).to_string(); let asyncness = header.asyncness.print_with_space(); - let visibility = visibility_print_with_space(it.visibility(tcx), it.item_id, cx).to_string(); + let visibility = visibility_print_with_space(it, cx).to_string(); let name = it.name.unwrap(); let generics_len = format!("{:#}", f.generics.print(cx)).len(); @@ -688,7 +688,7 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean: w, "{attrs}{vis}{unsafety}{is_auto}trait {name}{generics}{bounds}", attrs = render_attributes_in_pre(it, "", cx), - vis = visibility_print_with_space(it.visibility(tcx), it.item_id, cx), + vis = visibility_print_with_space(it, cx), unsafety = t.unsafety(tcx).print_with_space(), is_auto = if t.is_auto(tcx) { "auto " } else { "" }, name = it.name.unwrap(), @@ -1243,7 +1243,7 @@ fn item_type_alias(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &c w, "{attrs}{vis}type {name}{generics}{where_clause} = {type_};", attrs = render_attributes_in_pre(it, "", cx), - vis = visibility_print_with_space(it.visibility(cx.tcx()), it.item_id, cx), + vis = visibility_print_with_space(it, cx), name = it.name.unwrap(), generics = t.generics.print(cx), where_clause = print_where_clause(&t.generics, cx, 0, Ending::Newline), @@ -1522,14 +1522,13 @@ fn print_tuple_struct_fields<'a, 'cx: 'a>( } fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean::Enum) { - let tcx = cx.tcx(); let count_variants = e.variants().count(); wrap_item(w, |w| { render_attributes_in_code(w, it, cx); write!( w, "{}enum {}{}", - visibility_print_with_space(it.visibility(tcx), it.item_id, cx), + visibility_print_with_space(it, cx), it.name.unwrap(), e.generics.print(cx), ); @@ -1860,7 +1859,7 @@ fn item_constant(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, c: &cle write!( w, "{vis}const {name}{generics}: {typ}{where_clause}", - vis = visibility_print_with_space(it.visibility(tcx), it.item_id, cx), + vis = visibility_print_with_space(it, cx), name = it.name.unwrap(), generics = c.generics.print(cx), typ = c.type_.print(cx), @@ -1964,7 +1963,7 @@ fn item_static(w: &mut impl fmt::Write, cx: &mut Context<'_>, it: &clean::Item, write!( buffer, "{vis}static {mutability}{name}: {typ}", - vis = visibility_print_with_space(it.visibility(cx.tcx()), it.item_id, cx), + vis = visibility_print_with_space(it, cx), mutability = s.mutability.print_with_space(), name = it.name.unwrap(), typ = s.type_.print(cx) @@ -1982,7 +1981,7 @@ fn item_foreign_type(w: &mut impl fmt::Write, cx: &mut Context<'_>, it: &clean:: write!( buffer, " {}type {};\n}}", - visibility_print_with_space(it.visibility(cx.tcx()), it.item_id, cx), + visibility_print_with_space(it, cx), it.name.unwrap(), ) .unwrap(); @@ -2139,13 +2138,7 @@ fn render_union<'a, 'cx: 'a>( cx: &'a Context<'cx>, ) -> impl fmt::Display + 'a + Captures<'cx> { display_fn(move |mut f| { - let tcx = cx.tcx(); - write!( - f, - "{}union {}", - visibility_print_with_space(it.visibility(tcx), it.item_id, cx), - it.name.unwrap(), - )?; + write!(f, "{}union {}", visibility_print_with_space(it, cx), it.name.unwrap(),)?; let where_displayed = g .map(|g| { @@ -2175,7 +2168,7 @@ fn render_union<'a, 'cx: 'a>( write!( f, " {}{}: {},\n", - visibility_print_with_space(field.visibility(tcx), field.item_id, cx), + visibility_print_with_space(field, cx), field.name.unwrap(), ty.print(cx) )?; @@ -2203,11 +2196,10 @@ fn render_struct( structhead: bool, cx: &Context<'_>, ) { - let tcx = cx.tcx(); write!( w, "{}{}{}", - visibility_print_with_space(it.visibility(tcx), it.item_id, cx), + visibility_print_with_space(it, cx), if structhead { "struct " } else { "" }, it.name.unwrap() ); @@ -2236,7 +2228,6 @@ fn render_struct_fields( has_stripped_entries: bool, cx: &Context<'_>, ) { - let tcx = cx.tcx(); match ty { None => { let where_displayed = @@ -2260,7 +2251,7 @@ fn render_struct_fields( write!( w, "\n{tab} {vis}{name}: {ty},", - vis = visibility_print_with_space(field.visibility(tcx), field.item_id, cx), + vis = visibility_print_with_space(field, cx), name = field.name.unwrap(), ty = ty.print(cx), ); @@ -2296,16 +2287,7 @@ fn render_struct_fields( match *field.kind { clean::StrippedItem(box clean::StructFieldItem(..)) => write!(w, "_"), clean::StructFieldItem(ref ty) => { - write!( - w, - "{}{}", - visibility_print_with_space( - field.visibility(tcx), - field.item_id, - cx - ), - ty.print(cx), - ) + write!(w, "{}{}", visibility_print_with_space(field, cx), ty.print(cx),) } _ => unreachable!(), } From 102015645d37579145c0ba955f22ece95d98c3bd Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Thu, 14 Mar 2024 13:53:03 +0100 Subject: [PATCH 3/7] print doc(hidden) --- src/librustdoc/html/format.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 1973c2a6021ce..745001e035e77 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -1509,7 +1509,9 @@ pub(crate) fn visibility_print_with_space<'a, 'tcx: 'a>( cx: &'a Context<'tcx>, ) -> impl Display + 'a + Captures<'tcx> { use std::fmt::Write as _; - let to_print: Cow<'static, str> = match item.visibility(cx.tcx()) { + + let hidden: &'static str = if item.is_doc_hidden() { "#[doc(hidden)] " } else { "" }; + let vis: Cow<'static, str> = match item.visibility(cx.tcx()) { None => "".into(), Some(ty::Visibility::Public) => "pub ".into(), Some(ty::Visibility::Restricted(vis_did)) => { @@ -1544,7 +1546,10 @@ pub(crate) fn visibility_print_with_space<'a, 'tcx: 'a>( } } }; - display_fn(move |f| f.write_str(&to_print)) + display_fn(move |f| { + f.write_str(&hidden)?; + f.write_str(&vis) + }) } /// This function is the same as print_with_space, except that it renders no links. @@ -1554,9 +1559,10 @@ pub(crate) fn visibility_to_src_with_space<'a, 'tcx: 'a>( visibility: Option>, tcx: TyCtxt<'tcx>, item_did: DefId, - _is_doc_hidden: bool, + is_doc_hidden: bool, ) -> impl Display + 'a + Captures<'tcx> { - let to_print: Cow<'static, str> = match visibility { + let hidden: &'static str = if is_doc_hidden { "#[doc(hidden)] " } else { "" }; + let vis: Cow<'static, str> = match visibility { None => "".into(), Some(ty::Visibility::Public) => "pub ".into(), Some(ty::Visibility::Restricted(vis_did)) => { @@ -1580,7 +1586,10 @@ pub(crate) fn visibility_to_src_with_space<'a, 'tcx: 'a>( } } }; - display_fn(move |f| f.write_str(&to_print)) + display_fn(move |f| { + f.write_str(&hidden)?; + f.write_str(&vis) + }) } pub(crate) trait PrintWithSpace { From bd03fad8ee6554fbc57758d65015361f766468dd Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Thu, 14 Mar 2024 14:30:38 +0100 Subject: [PATCH 4/7] Make compact --- src/librustdoc/html/render/print_item.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index d2a03d5840278..0af3f3bc99342 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -511,17 +511,18 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items: _ => "", }; - let visibility_emoji = match myitem.visibility(tcx) { + let visibility_and_hidden = match myitem.visibility(tcx) { Some(ty::Visibility::Restricted(_)) => { - " ðŸ”’ " + if myitem.is_doc_hidden() { + " ðŸ”’ " + } else { + // Don't separate with a space when there are two of them + " ðŸ”’👻 " + } } + _ if myitem.is_doc_hidden() => " ðŸ‘» ", _ => "", }; - let hidden_emoji = if myitem.is_doc_hidden() { - " ðŸ‘» " - } else { - "" - }; w.write_str(ITEM_TABLE_ROW_OPEN); let docs = @@ -535,14 +536,13 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items: w, "
\ {name}\ - {visibility_emoji}\ - {hidden_emoji}\ + {visibility_and_hidden}\ {unsafety_flag}\ {stab_tags}\
\ {docs_before}{docs}{docs_after}", name = myitem.name.unwrap(), - visibility_emoji = visibility_emoji, + visibility_and_hidden = visibility_and_hidden, stab_tags = extra_info_tags(myitem, item, tcx), class = myitem.type_(), unsafety_flag = unsafety_flag, From 26028209e808377d52ea36618b2cf2d75e0bcd6c Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Thu, 14 Mar 2024 14:40:54 +0100 Subject: [PATCH 5/7] tests --- tests/rustdoc/display-hidden-items.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/rustdoc/display-hidden-items.rs b/tests/rustdoc/display-hidden-items.rs index 76124554767f2..901ca17d4d2c3 100644 --- a/tests/rustdoc/display-hidden-items.rs +++ b/tests/rustdoc/display-hidden-items.rs @@ -5,19 +5,22 @@ #![crate_name = "foo"] // @has 'foo/index.html' -// @has - '//*[@id="reexport.hidden_reexport"]/code' 'pub use hidden::inside_hidden as hidden_reexport;' +// @has - '//*[@class="item-name"]/span[@title="Hidden item"]' '👻' + +// @has - '//*[@id="reexport.hidden_reexport"]/code' '#[doc(hidden)] pub use hidden::inside_hidden as hidden_reexport;' #[doc(hidden)] pub use hidden::inside_hidden as hidden_reexport; // @has - '//*[@class="item-name"]/a[@class="trait"]' 'TraitHidden' // @has 'foo/trait.TraitHidden.html' +// @has - '//code' '#[doc(hidden)] pub trait TraitHidden' #[doc(hidden)] pub trait TraitHidden {} // @has 'foo/index.html' '//*[@class="item-name"]/a[@class="trait"]' 'Trait' pub trait Trait { // @has 'foo/trait.Trait.html' - // @has - '//*[@id="associatedconstant.BAR"]/*[@class="code-header"]' 'const BAR: u32 = 0u32' + // @has - '//*[@id="associatedconstant.BAR"]/*[@class="code-header"]' '#[doc(hidden)] const BAR: u32 = 0u32' #[doc(hidden)] const BAR: u32 = 0; @@ -41,14 +44,15 @@ impl Struct { } impl Trait for Struct { - // @has - '//*[@id="associatedconstant.BAR"]/*[@class="code-header"]' 'const BAR: u32 = 0u32' - // @has - '//*[@id="method.foo"]/*[@class="code-header"]' 'fn foo()' + // @has - '//*[@id="associatedconstant.BAR"]/*[@class="code-header"]' '#[doc(hidden)] const BAR: u32 = 0u32' + // @has - '//*[@id="method.foo"]/*[@class="code-header"]' '#[doc(hidden)] fn foo()' } // @has - '//*[@id="impl-TraitHidden-for-Struct"]/*[@class="code-header"]' 'impl TraitHidden for Struct' impl TraitHidden for Struct {} // @has 'foo/index.html' '//*[@class="item-name"]/a[@class="enum"]' 'HiddenEnum' // @has 'foo/enum.HiddenEnum.html' +// @has - '//code' '#[doc(hidden)] pub enum HiddenEnum' #[doc(hidden)] pub enum HiddenEnum { A, From 580e5b855d58d2076460b7a16c87e622b7d68960 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Thu, 14 Mar 2024 15:07:30 +0100 Subject: [PATCH 6/7] inline --- src/librustdoc/html/format.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 745001e035e77..312765d3e6d03 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -1509,8 +1509,6 @@ pub(crate) fn visibility_print_with_space<'a, 'tcx: 'a>( cx: &'a Context<'tcx>, ) -> impl Display + 'a + Captures<'tcx> { use std::fmt::Write as _; - - let hidden: &'static str = if item.is_doc_hidden() { "#[doc(hidden)] " } else { "" }; let vis: Cow<'static, str> = match item.visibility(cx.tcx()) { None => "".into(), Some(ty::Visibility::Public) => "pub ".into(), @@ -1546,8 +1544,13 @@ pub(crate) fn visibility_print_with_space<'a, 'tcx: 'a>( } } }; + + let is_doc_hidden = item.is_doc_hidden(); display_fn(move |f| { - f.write_str(&hidden)?; + if is_doc_hidden { + f.write_str("#[doc(hidden)] ")?; + } + f.write_str(&vis) }) } @@ -1561,7 +1564,6 @@ pub(crate) fn visibility_to_src_with_space<'a, 'tcx: 'a>( item_did: DefId, is_doc_hidden: bool, ) -> impl Display + 'a + Captures<'tcx> { - let hidden: &'static str = if is_doc_hidden { "#[doc(hidden)] " } else { "" }; let vis: Cow<'static, str> = match visibility { None => "".into(), Some(ty::Visibility::Public) => "pub ".into(), @@ -1587,7 +1589,9 @@ pub(crate) fn visibility_to_src_with_space<'a, 'tcx: 'a>( } }; display_fn(move |f| { - f.write_str(&hidden)?; + if is_doc_hidden { + f.write_str("#[doc(hidden)] ")?; + } f.write_str(&vis) }) } From 9718144599d633c95efe6459566a4f86087467ee Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Thu, 14 Mar 2024 15:08:16 +0100 Subject: [PATCH 7/7] fix polarity --- src/librustdoc/html/render/print_item.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 0af3f3bc99342..5d4f1acc4b188 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -514,10 +514,10 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items: let visibility_and_hidden = match myitem.visibility(tcx) { Some(ty::Visibility::Restricted(_)) => { if myitem.is_doc_hidden() { - " ðŸ”’ " - } else { // Don't separate with a space when there are two of them " ðŸ”’👻 " + } else { + " ðŸ”’ " } } _ if myitem.is_doc_hidden() => " ðŸ‘» ",