diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index f9d6b4619cc77..b1d2872019ef6 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -191,12 +191,6 @@ impl StylePath { } } -fn write_srclink(cx: &Context<'_>, item: &clean::Item, buf: &mut Buffer) { - if let Some(l) = cx.src_href(item) { - write!(buf, "source", l) - } -} - #[derive(Debug, Eq, PartialEq, Hash)] struct ItemEntry { url: String, @@ -840,12 +834,13 @@ fn assoc_method( /// Note that it is possible for an unstable function to be const-stable. In that case, the span /// will include the const-stable version, but no stable version will be emitted, as a natural /// consequence of the above rules. -fn render_stability_since_raw( +fn render_stability_since_raw_with_extra( w: &mut Buffer, ver: Option, const_stability: Option, containing_ver: Option, containing_const_ver: Option, + extra_class: &str, ) -> bool { let stable_version = ver.filter(|inner| !inner.is_empty() && Some(*inner) != containing_ver); @@ -893,12 +888,30 @@ fn render_stability_since_raw( } if !stability.is_empty() { - write!(w, r#"{}"#, title, stability); + write!(w, r#"{stability}"#); } !stability.is_empty() } +#[inline] +fn render_stability_since_raw( + w: &mut Buffer, + ver: Option, + const_stability: Option, + containing_ver: Option, + containing_const_ver: Option, +) -> bool { + render_stability_since_raw_with_extra( + w, + ver, + const_stability, + containing_ver, + containing_const_ver, + "", + ) +} + fn render_assoc_item( w: &mut Buffer, item: &clean::Item, @@ -1681,23 +1694,29 @@ fn render_rightside( RenderMode::Normal => (item.const_stability(tcx), containing_item.const_stable_since(tcx)), RenderMode::ForDeref { .. } => (None, None), }; + let src_href = cx.src_href(item); + let has_src_ref = src_href.is_some(); let mut rightside = Buffer::new(); - let has_stability = render_stability_since_raw( + let has_stability = render_stability_since_raw_with_extra( &mut rightside, item.stable_since(tcx), const_stability, containing_item.stable_since(tcx), const_stable_since, + if has_src_ref { "" } else { " rightside" }, ); - let mut srclink = Buffer::empty_from(w); - write_srclink(cx, item, &mut srclink); - if has_stability && !srclink.is_empty() { - rightside.write_str(" · "); + if let Some(l) = src_href { + if has_stability { + write!(rightside, " · source", l) + } else { + write!(rightside, "source", l) + } } - rightside.push_buffer(srclink); - if !rightside.is_empty() { + if has_stability && has_src_ref { write!(w, "{}", rightside.into_inner()); + } else { + w.push_buffer(rightside); } } diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 6d0a825fec866..a5668b318dcdc 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -18,7 +18,7 @@ use std::rc::Rc; use super::{ collect_paths_for_type, document, ensure_trailing_slash, item_ty_to_section, notable_traits_decl, render_assoc_item, render_assoc_items, render_attributes_in_code, - render_attributes_in_pre, render_impl, render_stability_since_raw, write_srclink, + render_attributes_in_pre, render_impl, render_rightside, render_stability_since_raw, AssocItemLink, Context, ImplRenderingParameters, }; use crate::clean; @@ -709,14 +709,7 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean: write!(w, "
"); } write!(w, "
", id); - write!(w, "
"); - - let has_stability = render_stability_since(w, m, t, cx.tcx()); - if has_stability { - w.write_str(" · "); - } - write_srclink(cx, m, w); - write!(w, "
"); + render_rightside(w, cx, m, t, RenderMode::Normal); write!(w, "

"); render_assoc_item( w, @@ -1260,7 +1253,13 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean:: w.write_str(")"); } w.write_str(""); - render_stability_since(w, variant, it, cx.tcx()); + render_stability_since_raw( + w, + variant.stable_since(cx.tcx()), + variant.const_stability(cx.tcx()), + it.stable_since(cx.tcx()), + it.const_stable_since(cx.tcx()), + ); w.write_str("

"); use crate::clean::Variant; @@ -1591,21 +1590,6 @@ where w.write_str(""); } -fn render_stability_since( - w: &mut Buffer, - item: &clean::Item, - containing_item: &clean::Item, - tcx: TyCtxt<'_>, -) -> bool { - render_stability_since_raw( - w, - item.stable_since(tcx), - item.const_stability(tcx), - containing_item.stable_since(tcx), - containing_item.const_stable_since(tcx), - ) -} - fn compare_impl<'a, 'b>(lhs: &'a &&Impl, rhs: &'b &&Impl, cx: &Context<'_>) -> Ordering { let lhss = format!("{}", lhs.inner_impl().print(false, cx)); let rhss = format!("{}", rhs.inner_impl().print(false, cx)); diff --git a/src/librustdoc/html/static/css/themes/ayu.css b/src/librustdoc/html/static/css/themes/ayu.css index e7ccd402dd024..f6614e8976030 100644 --- a/src/librustdoc/html/static/css/themes/ayu.css +++ b/src/librustdoc/html/static/css/themes/ayu.css @@ -199,7 +199,7 @@ details.rustdoc-toggle > summary::before { background: none; } -.rightside, +.rightside:not(a), .out-of-band { color: grey; } diff --git a/src/librustdoc/html/static/css/themes/dark.css b/src/librustdoc/html/static/css/themes/dark.css index 1fcda22b6f4fa..d5cd47c3e19d5 100644 --- a/src/librustdoc/html/static/css/themes/dark.css +++ b/src/librustdoc/html/static/css/themes/dark.css @@ -165,7 +165,7 @@ details.rustdoc-toggle > summary::before { background: none; } -.rightside, +.rightside:not(a), .out-of-band { color: grey; } diff --git a/src/librustdoc/html/static/css/themes/light.css b/src/librustdoc/html/static/css/themes/light.css index 7139c199729ae..cff70268144f3 100644 --- a/src/librustdoc/html/static/css/themes/light.css +++ b/src/librustdoc/html/static/css/themes/light.css @@ -148,7 +148,7 @@ details.rustdoc-toggle > summary::before { .stab { background: #FFF5D6; border-color: #FFC600; } .stab.portability > code { background: none; } -.rightside, +.rightside:not(a), .out-of-band { color: grey; } diff --git a/src/test/rustdoc-gui/anchors.goml b/src/test/rustdoc-gui/anchors.goml index 84b8bbd1b327f..3ad62c721b4b8 100644 --- a/src/test/rustdoc-gui/anchors.goml +++ b/src/test/rustdoc-gui/anchors.goml @@ -1,6 +1,5 @@ // This test is to ensure that the anchors (`§`) have the expected color and position. -goto: file://|DOC_PATH|/test_docs/struct.HeavilyDocumentedStruct.html -show-text: true +goto: file://|DOC_PATH|/staged_api/struct.Foo.html // This is needed to ensure that the text color is computed. show-text: true @@ -13,10 +12,31 @@ reload: assert-css: ("#toggle-all-docs", {"color": "rgb(0, 0, 0)"}) assert-css: (".fqn .in-band a:nth-of-type(1)", {"color": "rgb(0, 0, 0)"}) assert-css: (".fqn .in-band a:nth-of-type(2)", {"color": "rgb(173, 55, 138)"}) -assert-css: (".srclink", {"color": "rgb(56, 115, 173)"}) +assert-css: ( + ".rightside .srclink", + {"color": "rgb(56, 115, 173)", "text-decoration": "none solid rgb(56, 115, 173)"}, + ALL, +) +compare-elements-css: (".rightside .srclink", ".rightside.srclink", ["color", "text-decoration"]) +compare-elements-css: (".main-heading .srclink", ".rightside.srclink", ["color", "text-decoration"]) move-cursor-to: ".main-heading .srclink" -assert-css: (".srclink", {"text-decoration": "underline solid rgb(56, 115, 173)"}) +assert-css: ( + ".main-heading .srclink", + {"color": "rgb(56, 115, 173)", "text-decoration": "underline solid rgb(56, 115, 173)"}, +) +move-cursor-to: ".impl-items .rightside .srclink" +assert-css: ( + ".impl-items .rightside .srclink", + {"color": "rgb(56, 115, 173)", "text-decoration": "none solid rgb(56, 115, 173)"}, +) +move-cursor-to: ".impl-items .rightside.srclink" +assert-css: ( + ".impl-items .rightside.srclink", + {"color": "rgb(56, 115, 173)", "text-decoration": "none solid rgb(56, 115, 173)"}, +) + +goto: file://|DOC_PATH|/test_docs/struct.HeavilyDocumentedStruct.html assert-css: ("#top-doc-prose-title", {"color": "rgb(0, 0, 0)"}) @@ -32,3 +52,103 @@ move-cursor-to: "#impl-HeavilyDocumentedStruct" assert-css: ("#impl-HeavilyDocumentedStruct a.anchor", {"color": "rgb(0, 0, 0)"}) assert-css: ("#title-for-struct-impl-item-doc", {"margin-left": "0px"}) + +// +// We do the same checks with the dark theme now. +// +local-storage: {"rustdoc-theme": "dark", "rustdoc-use-system-theme": "false"} +goto: file://|DOC_PATH|/staged_api/struct.Foo.html + +assert-css: ("#toggle-all-docs", {"color": "rgb(221, 221, 221)"}) +assert-css: (".fqn .in-band a:nth-of-type(1)", {"color": "rgb(221, 221, 221)"}) +assert-css: (".fqn .in-band a:nth-of-type(2)", {"color": "rgb(45, 191, 184)"}) +assert-css: ( + ".rightside .srclink", + {"color": "rgb(210, 153, 29)", "text-decoration": "none solid rgb(210, 153, 29)"}, + ALL, +) +compare-elements-css: (".rightside .srclink", ".rightside.srclink", ["color", "text-decoration"]) +compare-elements-css: (".main-heading .srclink", ".rightside.srclink", ["color", "text-decoration"]) + +move-cursor-to: ".main-heading .srclink" +assert-css: ( + ".main-heading .srclink", + {"color": "rgb(210, 153, 29)", "text-decoration": "underline solid rgb(210, 153, 29)"}, +) +move-cursor-to: ".impl-items .rightside .srclink" +assert-css: ( + ".impl-items .rightside .srclink", + {"color": "rgb(210, 153, 29)", "text-decoration": "none solid rgb(210, 153, 29)"}, +) +move-cursor-to: ".impl-items .rightside.srclink" +assert-css: ( + ".impl-items .rightside.srclink", + {"color": "rgb(210, 153, 29)", "text-decoration": "none solid rgb(210, 153, 29)"}, +) + +goto: file://|DOC_PATH|/test_docs/struct.HeavilyDocumentedStruct.html + +assert-css: ("#top-doc-prose-title", {"color": "rgb(221, 221, 221)"}) + +assert-css: (".sidebar a", {"color": "rgb(253, 191, 53)"}) +assert-css: (".in-band a", {"color": "rgb(221, 221, 221)"}) + +// We move the cursor over the "Implementations" title so the anchor is displayed. +move-cursor-to: "h2#implementations" +assert-css: ("h2#implementations a.anchor", {"color": "rgb(221, 221, 221)"}) + +// Same thing with the impl block title. +move-cursor-to: "#impl-HeavilyDocumentedStruct" +assert-css: ("#impl-HeavilyDocumentedStruct a.anchor", {"color": "rgb(221, 221, 221)"}) + +assert-css: ("#title-for-struct-impl-item-doc", {"margin-left": "0px"}) + +// +// We do the same checks with the ayu theme now. +// +local-storage: {"rustdoc-theme": "ayu", "rustdoc-use-system-theme": "false"} +goto: file://|DOC_PATH|/staged_api/struct.Foo.html + +assert-css: ("#toggle-all-docs", {"color": "rgb(197, 197, 197)"}) +assert-css: (".fqn .in-band a:nth-of-type(1)", {"color": "rgb(255, 255, 255)"}) +assert-css: (".fqn .in-band a:nth-of-type(2)", {"color": "rgb(255, 160, 165)"}) +assert-css: ( + ".rightside .srclink", + {"color": "rgb(57, 175, 215)", "text-decoration": "none solid rgb(57, 175, 215)"}, + ALL, +) +compare-elements-css: (".rightside .srclink", ".rightside.srclink", ["color", "text-decoration"]) +compare-elements-css: (".main-heading .srclink", ".rightside.srclink", ["color", "text-decoration"]) + +move-cursor-to: ".main-heading .srclink" +assert-css: ( + ".main-heading .srclink", + {"color": "rgb(57, 175, 215)", "text-decoration": "underline solid rgb(57, 175, 215)"}, +) +move-cursor-to: ".impl-items .rightside .srclink" +assert-css: ( + ".impl-items .rightside .srclink", + {"color": "rgb(57, 175, 215)", "text-decoration": "none solid rgb(57, 175, 215)"}, +) +move-cursor-to: ".impl-items .rightside.srclink" +assert-css: ( + ".impl-items .rightside.srclink", + {"color": "rgb(57, 175, 215)", "text-decoration": "none solid rgb(57, 175, 215)"}, +) + +goto: file://|DOC_PATH|/test_docs/struct.HeavilyDocumentedStruct.html + +assert-css: ("#top-doc-prose-title", {"color": "rgb(255, 255, 255)"}) + +assert-css: (".sidebar a", {"color": "rgb(83, 177, 219)"}) +assert-css: (".in-band a", {"color": "rgb(255, 255, 255)"}) + +// We move the cursor over the "Implementations" title so the anchor is displayed. +move-cursor-to: "h2#implementations" +assert-css: ("h2#implementations a.anchor", {"color": "rgb(197, 197, 197)"}) + +// Same thing with the impl block title. +move-cursor-to: "#impl-HeavilyDocumentedStruct" +assert-css: ("#impl-HeavilyDocumentedStruct a.anchor", {"color": "rgb(197, 197, 197)"}) + +assert-css: ("#title-for-struct-impl-item-doc", {"margin-left": "0px"}) diff --git a/src/test/rustdoc-gui/headings.goml b/src/test/rustdoc-gui/headings.goml index 8c2c3df1588f5..ed07e777b1880 100644 --- a/src/test/rustdoc-gui/headings.goml +++ b/src/test/rustdoc-gui/headings.goml @@ -247,12 +247,12 @@ assert-css: ( local-storage: {"rustdoc-theme": "light"} goto: file://|DOC_PATH|/staged_api/struct.Foo.html -assert-css: (".since", {"color": "rgb(128, 128, 128)"}) +assert-css: (".since", {"color": "rgb(128, 128, 128)"}, ALL) local-storage: {"rustdoc-theme": "dark"} reload: -assert-css: (".since", {"color": "rgb(128, 128, 128)"}) +assert-css: (".since", {"color": "rgb(128, 128, 128)"}, ALL) local-storage: {"rustdoc-theme": "ayu"} reload: -assert-css: (".since", {"color": "rgb(128, 128, 128)"}) +assert-css: (".since", {"color": "rgb(128, 128, 128)"}, ALL) diff --git a/src/test/rustdoc-gui/src/staged_api/Cargo.toml b/src/test/rustdoc-gui/src/staged_api/Cargo.toml index 117c4134e3419..b231be6eee902 100644 --- a/src/test/rustdoc-gui/src/staged_api/Cargo.toml +++ b/src/test/rustdoc-gui/src/staged_api/Cargo.toml @@ -7,5 +7,6 @@ edition = "2021" path = "lib.rs" [features] -default = ["some_feature"] +default = ["some_feature", "some_other_feature"] some_feature = [] +some_other_feature = [] diff --git a/src/test/rustdoc-gui/src/staged_api/lib.rs b/src/test/rustdoc-gui/src/staged_api/lib.rs index 0cb460f03f701..5934593a8999b 100644 --- a/src/test/rustdoc-gui/src/staged_api/lib.rs +++ b/src/test/rustdoc-gui/src/staged_api/lib.rs @@ -7,4 +7,6 @@ pub struct Foo {} impl Foo { #[stable(feature = "some_feature", since = "1.3.5")] pub fn bar() {} + #[stable(feature = "some_other_feature", since = "1.3.6")] + pub fn yo() {} } diff --git a/src/test/rustdoc/anchors.no_const_anchor.html b/src/test/rustdoc/anchors.no_const_anchor.html index 98f47e53038a9..4da1ffead2a4c 100644 --- a/src/test/rustdoc/anchors.no_const_anchor.html +++ b/src/test/rustdoc/anchors.no_const_anchor.html @@ -1 +1 @@ - + \ No newline at end of file diff --git a/src/test/rustdoc/anchors.no_const_anchor2.html b/src/test/rustdoc/anchors.no_const_anchor2.html index 6d37e8e5eee5e..c002519760242 100644 --- a/src/test/rustdoc/anchors.no_const_anchor2.html +++ b/src/test/rustdoc/anchors.no_const_anchor2.html @@ -1 +1 @@ - + \ No newline at end of file diff --git a/src/test/rustdoc/anchors.no_method_anchor.html b/src/test/rustdoc/anchors.no_method_anchor.html index f46d3090ed370..521fdcb7877a7 100644 --- a/src/test/rustdoc/anchors.no_method_anchor.html +++ b/src/test/rustdoc/anchors.no_method_anchor.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/src/test/rustdoc/anchors.no_trait_method_anchor.html b/src/test/rustdoc/anchors.no_trait_method_anchor.html index 445a7bb560aca..6b78c7c811a06 100644 --- a/src/test/rustdoc/anchors.no_trait_method_anchor.html +++ b/src/test/rustdoc/anchors.no_trait_method_anchor.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/src/test/rustdoc/anchors.no_tymethod_anchor.html b/src/test/rustdoc/anchors.no_tymethod_anchor.html index bb0771b10035d..c08f4427cf697 100644 --- a/src/test/rustdoc/anchors.no_tymethod_anchor.html +++ b/src/test/rustdoc/anchors.no_tymethod_anchor.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/src/test/rustdoc/anchors.no_type_anchor.html b/src/test/rustdoc/anchors.no_type_anchor.html index d317eb5005017..ba8e65443ec81 100644 --- a/src/test/rustdoc/anchors.no_type_anchor.html +++ b/src/test/rustdoc/anchors.no_type_anchor.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/src/test/rustdoc/ensure-src-link.rs b/src/test/rustdoc/ensure-src-link.rs index 9f8b0277e76b0..c65387080f11b 100644 --- a/src/test/rustdoc/ensure-src-link.rs +++ b/src/test/rustdoc/ensure-src-link.rs @@ -2,5 +2,5 @@ // This test ensures that the [src] link is present on traits items. -// @has foo/trait.Iterator.html '//*[@id="method.zip"]//a[@class="srclink"]' "source" +// @has foo/trait.Iterator.html '//*[@id="method.zip"]//a[@class="srclink rightside"]' "source" pub use std::iter::Iterator; diff --git a/src/test/rustdoc/src-links-auto-impls.rs b/src/test/rustdoc/src-links-auto-impls.rs index 69be9aa8d5f10..313a4b1189334 100644 --- a/src/test/rustdoc/src-links-auto-impls.rs +++ b/src/test/rustdoc/src-links-auto-impls.rs @@ -6,7 +6,7 @@ // @has - '//*[@id="impl-Sync-for-Unsized"]/h3[@class="code-header in-band"]' 'impl Sync for Unsized' // @!has - '//*[@id="impl-Sync-for-Unsized"]//a[@class="srclink"]' 'source' // @has - '//*[@id="impl-Any-for-Unsized"]/h3[@class="code-header in-band"]' 'impl Any for T' -// @has - '//*[@id="impl-Any-for-Unsized"]//a[@class="srclink"]' 'source' +// @has - '//*[@id="impl-Any-for-Unsized"]//a[@class="srclink rightside"]' 'source' pub struct Unsized { data: [u8], } diff --git a/src/test/rustdoc/version-separator-without-source.rs b/src/test/rustdoc/version-separator-without-source.rs index ae866deba1ef0..04ea46a7f3a01 100644 --- a/src/test/rustdoc/version-separator-without-source.rs +++ b/src/test/rustdoc/version-separator-without-source.rs @@ -16,7 +16,7 @@ pub fn foo() {} pub struct Bar; impl Bar { - // @has - '//*[@id="method.bar"]/*[@class="rightside"]' '2.0' + // @has - '//*[@id="method.bar"]/*[@class="since rightside"]' '2.0' // @!has - '//*[@id="method.bar"]/*[@class="rightside"]' '2.0 ·' #[stable(feature = "foobar", since = "2.0")] pub fn bar() {}