From ff48ccfeabc4fa6d46b24b97cd56ab9bb3b949db Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 12 Sep 2018 22:18:00 +0200 Subject: [PATCH 1/6] Improve stability messages display a bit --- src/librustdoc/html/static/rustdoc.css | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index 91ff03a327df4..8640f5da1332c 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -458,17 +458,6 @@ h4 > code, h3 > code, .invisible > code { margin-bottom: 15px; } -.content .impl-items .method, .content .impl-items > .type, .impl-items > .associatedconstant { - margin-left: 20px; -} -.content .impl-items .docblock, .content .impl-items .stability { - margin-bottom: .6em; -} - -.content .impl-items > .stability { - margin-left: 40px; -} - .content .docblock > .impl-items { margin-left: 20px; margin-top: -34px; @@ -506,7 +495,20 @@ h4 > code, h3 > code, .invisible > code { top: -9px; left: -13px; } -.methods > .stability { + +.content .impl-items .method, .content .impl-items > .type, .impl-items > .associatedconstant { + margin-left: 20px; +} + +.content .impl-items .docblock, .content .impl-items .stability { + margin-bottom: .6em; +} + +.content .impl-items > .stability { + margin-left: 40px; +} + +.methods > .stability, .content .impl-items > .stability { margin-top: -8px; } From edec5807ac5ba90cbc0c61a5ec7b80f29e1eea33 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 12 Sep 2018 23:31:21 +0200 Subject: [PATCH 2/6] Hide items if they use default docs --- src/librustdoc/html/render.rs | 61 ++++++++++++++++---------- src/librustdoc/html/static/main.js | 30 +++++++++++++ src/librustdoc/html/static/rustdoc.css | 5 +++ src/librustdoc/html/static/storage.js | 16 +++++-- 4 files changed, 85 insertions(+), 27 deletions(-) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index dda0f37c3f95b..bb95696c5130e 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -2259,8 +2259,8 @@ fn document(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item) -> fmt::Re if let Some(ref name) = item.name { info!("Documenting {}", name); } - document_stability(w, cx, item)?; - document_full(w, item, cx, "")?; + document_stability(w, cx, item, false)?; + document_full(w, item, cx, "", false)?; Ok(()) } @@ -2269,15 +2269,19 @@ fn render_markdown(w: &mut fmt::Formatter, cx: &Context, md_text: &str, links: Vec<(String, String)>, - prefix: &str) + prefix: &str, + is_hidden: bool) -> fmt::Result { let mut ids = cx.id_map.borrow_mut(); - write!(w, "
{}{}
", - prefix, Markdown(md_text, &links, RefCell::new(&mut ids), cx.codes)) + write!(w, "
{}{}
", + if is_hidden { " hidden" } else { "" }, + prefix, + Markdown(md_text, &links, RefCell::new(&mut ids), + cx.codes)) } fn document_short(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item, link: AssocItemLink, - prefix: &str) -> fmt::Result { + prefix: &str, is_hidden: bool) -> fmt::Result { if let Some(s) = item.doc_value() { let markdown = if s.contains('\n') { format!("{} [Read more]({})", @@ -2285,28 +2289,33 @@ fn document_short(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item, link } else { plain_summary_line(Some(s)).to_string() }; - render_markdown(w, cx, &markdown, item.links(), prefix)?; + render_markdown(w, cx, &markdown, item.links(), prefix, is_hidden)?; } else if !prefix.is_empty() { - write!(w, "
{}
", prefix)?; + write!(w, "
{}
", + if is_hidden { " hidden" } else { "" }, + prefix)?; } Ok(()) } fn document_full(w: &mut fmt::Formatter, item: &clean::Item, - cx: &Context, prefix: &str) -> fmt::Result { + cx: &Context, prefix: &str, is_hidden: bool) -> fmt::Result { if let Some(s) = cx.shared.maybe_collapsed_doc_value(item) { debug!("Doc block: =====\n{}\n=====", s); - render_markdown(w, cx, &*s, item.links(), prefix)?; + render_markdown(w, cx, &*s, item.links(), prefix, is_hidden)?; } else if !prefix.is_empty() { - write!(w, "
{}
", prefix)?; + write!(w, "
{}
", + if is_hidden { " hidden" } else { "" }, + prefix)?; } Ok(()) } -fn document_stability(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item) -> fmt::Result { +fn document_stability(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item, + is_hidden: bool) -> fmt::Result { let stabilities = short_stability(item, cx, true); if !stabilities.is_empty() { - write!(w, "
")?; + write!(w, "
", if is_hidden { " hidden" } else { "" })?; for stability in stabilities { write!(w, "{}", stability)?; } @@ -3872,6 +3881,11 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi RenderMode::ForDeref { mut_: deref_mut_ } => should_render_item(&item, deref_mut_), }; + let (mut is_hidden, extra_class) = if item.doc_value().is_some() { + (false, "") + } else { + (true, " hidden") + }; match item.inner { clean::MethodItem(clean::Method { ref decl, .. }) | clean::TyMethodItem(clean::TyMethod{ ref decl, .. }) => { @@ -3896,12 +3910,13 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi render_stability_since_raw(w, item.stable_since(), outer_version)?; } write!(w, "")?; + is_hidden = false; } } clean::TypedefItem(ref tydef, _) => { let id = cx.derive_id(format!("{}.{}", ItemType::AssociatedType, name)); let ns_id = cx.derive_id(format!("{}.{}", name, item_type.name_space())); - write!(w, "

", id, item_type)?; + write!(w, "

", id, item_type, extra_class)?; write!(w, "

\n")?; @@ -3909,7 +3924,7 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi clean::AssociatedConstItem(ref ty, ref default) => { let id = cx.derive_id(format!("{}.{}", item_type, name)); let ns_id = cx.derive_id(format!("{}.{}", name, item_type.name_space())); - write!(w, "

", id, item_type)?; + write!(w, "

", id, item_type, extra_class)?; write!(w, "] Hide undocumented items" } else { addClass(this, "collapsed"); onEach(this.parentNode.getElementsByClassName("x"), function(x) { @@ -2085,7 +2095,7 @@ } }, true); this.innerHTML = "[" + labelForToggleButton(true) + - "] Show hidden default items"; + "] Show hidden undocumented items"; } }; e.insertBefore(newToggle, e.firstChild); diff --git a/src/test/rustdoc/assoc-consts.rs b/src/test/rustdoc/assoc-consts.rs index 9ace871491824..d4f8e614ad072 100644 --- a/src/test/rustdoc/assoc-consts.rs +++ b/src/test/rustdoc/assoc-consts.rs @@ -99,7 +99,7 @@ impl Qux for Bar { /// Docs for QUX1 in impl. const QUX1: i8 = 5; // @has - '//*[@id="associatedconstant.QUX_DEFAULT0"]' 'const QUX_DEFAULT0: u16' - // @has - '//*[@class="docblock hidden"]' "Docs for QUX_DEFAULT12 in trait." + // @has - '//*[@class="docblock"]' "Docs for QUX_DEFAULT12 in trait." const QUX_DEFAULT0: u16 = 6; // @has - '//*[@id="associatedconstant.QUX_DEFAULT1"]' 'const QUX_DEFAULT1: i16' // @has - '//*[@class="docblock"]' "Docs for QUX_DEFAULT1 in impl." diff --git a/src/test/rustdoc/manual_impl.rs b/src/test/rustdoc/manual_impl.rs index 54a8a76483341..ea46dae4f8324 100644 --- a/src/test/rustdoc/manual_impl.rs +++ b/src/test/rustdoc/manual_impl.rs @@ -74,7 +74,7 @@ impl T for S2 { // @has manual_impl/struct.S3.html '//*[@class="trait"]' 'T' // @has - '//*[@class="docblock"]' 'Docs associated with the S3 trait implementation.' // @has - '//*[@class="docblock"]' 'Docs associated with the S3 trait b_method implementation.' -// @has - '//*[@class="docblock"]' 'Docs associated with the trait a_method definition.' +// @has - '//*[@class="docblock hidden"]' 'Docs associated with the trait a_method definition.' pub struct S3(usize); /// Docs associated with the S3 trait implementation. From ca65b4304e2a3179c206a4d61dc623e790fc117d Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 1 Nov 2018 23:57:17 +0100 Subject: [PATCH 6/6] Don't show associated const items by default --- src/librustdoc/clean/mod.rs | 1 - src/test/rustdoc/assoc-consts.rs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index f7f2a45255e64..80a4759ec088d 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -556,7 +556,6 @@ impl ItemEnum { pub fn is_associated(&self) -> bool { match *self { ItemEnum::TypedefItem(_, _) | - ItemEnum::AssociatedConstItem(_, _) | ItemEnum::AssociatedTypeItem(_, _) => true, _ => false, } diff --git a/src/test/rustdoc/assoc-consts.rs b/src/test/rustdoc/assoc-consts.rs index d4f8e614ad072..9ace871491824 100644 --- a/src/test/rustdoc/assoc-consts.rs +++ b/src/test/rustdoc/assoc-consts.rs @@ -99,7 +99,7 @@ impl Qux for Bar { /// Docs for QUX1 in impl. const QUX1: i8 = 5; // @has - '//*[@id="associatedconstant.QUX_DEFAULT0"]' 'const QUX_DEFAULT0: u16' - // @has - '//*[@class="docblock"]' "Docs for QUX_DEFAULT12 in trait." + // @has - '//*[@class="docblock hidden"]' "Docs for QUX_DEFAULT12 in trait." const QUX_DEFAULT0: u16 = 6; // @has - '//*[@id="associatedconstant.QUX_DEFAULT1"]' 'const QUX_DEFAULT1: i16' // @has - '//*[@class="docblock"]' "Docs for QUX_DEFAULT1 in impl."