",
- document_non_exhaustive_header(it),
- document_non_exhaustive(it)
+ &format!("Variants{}", document_non_exhaustive_header(it)),
+ "variants",
+ Some("variants"),
+ format!("{}
", document_non_exhaustive(it)),
);
+
let should_show_enum_discriminant = should_show_enum_discriminant(cx, enum_def_id, variants);
for (index, variant) in variants.iter_enumerated() {
if variant.is_stripped() {
@@ -1930,16 +1924,12 @@ fn item_fields(
.peekable();
if let None | Some(CtorKind::Fn) = ctor_kind {
if fields.peek().is_some() {
- write!(
- w,
- "
\
- {}{}§\
-
\
- {}",
+ let title = format!(
+ "{}{}",
if ctor_kind.is_none() { "Fields" } else { "Tuple Fields" },
document_non_exhaustive_header(it),
- document_non_exhaustive(it)
);
+ write_section_heading(w, &title, "fields", Some("fields"), document_non_exhaustive(it));
for (index, (field, ty)) in fields.enumerate() {
let field_name =
field.name.map_or_else(|| index.to_string(), |sym| sym.as_str().to_string());
diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css
index cd53fcb8b7c16..9c593aa85d987 100644
--- a/src/librustdoc/html/static/css/rustdoc.css
+++ b/src/librustdoc/html/static/css/rustdoc.css
@@ -849,11 +849,30 @@ nav.sub {
h2.section-header > .anchor {
padding-right: 6px;
}
+a.doc-anchor {
+ color: var(--main-color);
+ display: none;
+ position: absolute;
+ left: -17px;
+ /* We add this padding so that when the cursor moves from the heading's text to the anchor,
+ the anchor doesn't disappear. */
+ padding-right: 5px;
+ /* And this padding is used to make the anchor larger and easier to click on. */
+ padding-left: 3px;
+}
+*:hover > .doc-anchor {
+ display: block;
+}
+/* If the first element of the top doc block is a heading, we don't want to ever display its anchor
+because of the `[-]` element which would overlap with it. */
+.top-doc > .docblock > *:first-child > .doc-anchor {
+ display: none !important;
+}
.main-heading a:hover,
.example-wrap .rust a:hover,
.all-items a:hover,
-.docblock a:not(.test-arrow):not(.scrape-help):not(.tooltip):hover,
+.docblock a:not(.test-arrow):not(.scrape-help):not(.tooltip):hover:not(.doc-anchor),
.docblock-short a:not(.test-arrow):not(.scrape-help):not(.tooltip):hover,
.item-info a {
text-decoration: underline;
diff --git a/tests/rustdoc-gui/docblock-details.goml b/tests/rustdoc-gui/docblock-details.goml
index 8e6d2ba824f73..4b8f5b54fac5d 100644
--- a/tests/rustdoc-gui/docblock-details.goml
+++ b/tests/rustdoc-gui/docblock-details.goml
@@ -6,7 +6,7 @@ reload:
// We first check that the headers in the `.top-doc` doc block still have their
// bottom border.
-assert-text: (".top-doc .docblock > h3", "Hello")
+assert-text: (".top-doc .docblock > h3", "§Hello")
assert-css: (
".top-doc .docblock > h3",
{"border-bottom": "1px solid #d2d2d2"},
diff --git a/tests/rustdoc-gui/headers-color.goml b/tests/rustdoc-gui/headers-color.goml
index 19185818f407e..80d11c9c849cf 100644
--- a/tests/rustdoc-gui/headers-color.goml
+++ b/tests/rustdoc-gui/headers-color.goml
@@ -1,4 +1,4 @@
-// This test check for headers text and background colors for the different themes.
+// This test check for headings text and background colors for the different themes.
define-function: (
"check-colors",
@@ -45,7 +45,7 @@ call-function: (
"color": "#c5c5c5",
"code_header_color": "#e6e1cf",
"focus_background_color": "rgba(255, 236, 164, 0.06)",
- "headings_color": "#39afd7",
+ "headings_color": "#c5c5c5",
},
)
call-function: (
@@ -55,7 +55,7 @@ call-function: (
"color": "#ddd",
"code_header_color": "#ddd",
"focus_background_color": "#494a3d",
- "headings_color": "#d2991d",
+ "headings_color": "#ddd",
},
)
call-function: (
@@ -65,6 +65,6 @@ call-function: (
"color": "black",
"code_header_color": "black",
"focus_background_color": "#fdffd3",
- "headings_color": "#3873ad",
+ "headings_color": "black",
},
)
diff --git a/tests/rustdoc-gui/headings-anchor.goml b/tests/rustdoc-gui/headings-anchor.goml
new file mode 100644
index 0000000000000..f568caa3b07fe
--- /dev/null
+++ b/tests/rustdoc-gui/headings-anchor.goml
@@ -0,0 +1,32 @@
+// Test to ensure that the headings anchor behave as expected.
+go-to: "file://" + |DOC_PATH| + "/test_docs/struct.HeavilyDocumentedStruct.html"
+show-text: true
+
+define-function: (
+ "check-heading-anchor",
+ (heading_id),
+ block {
+ // The anchor should not be displayed by default.
+ assert-css: ("#" + |heading_id| + " .doc-anchor", { "display": "none" })
+ // We ensure that hovering the heading makes the anchor visible.
+ move-cursor-to: "#" + |heading_id|
+ assert-css: ("#" + |heading_id| + ":hover .doc-anchor", { "display": "block" })
+ // We then ensure that moving from the heading to the anchor doesn't make the anchor
+ // disappear.
+ move-cursor-to: "#" + |heading_id| + " .doc-anchor"
+ assert-css: ("#" + |heading_id| + " .doc-anchor:hover", {
+ "display": "block",
+ // We also ensure that there is no underline decoration.
+ "text-decoration-line": "none",
+ })
+ }
+)
+
+move-cursor-to: "#top-doc-prose-title"
+// If the top documentation block first element is a heading, we should never display its anchor
+// to prevent it from overlapping with the `[-]` element.
+assert-css: ("#top-doc-prose-title:hover .doc-anchor", { "display": "none" })
+
+call-function: ("check-heading-anchor", ("top-doc-prose-sub-heading"))
+call-function: ("check-heading-anchor", ("top-doc-prose-sub-sub-heading"))
+call-function: ("check-heading-anchor", ("you-know-the-drill"))
diff --git a/tests/rustdoc/disambiguate-anchors-header-29449.rs b/tests/rustdoc/disambiguate-anchors-header-29449.rs
index 38a4954fc1395..1388af7df4b2e 100644
--- a/tests/rustdoc/disambiguate-anchors-header-29449.rs
+++ b/tests/rustdoc/disambiguate-anchors-header-29449.rs
@@ -5,18 +5,23 @@
pub struct Foo;
impl Foo {
- // @has - '//*[@id="examples"]//a' 'Examples'
- // @has - '//*[@id="panics"]//a' 'Panics'
+ // @has - '//*[@id="examples"]' 'Examples'
+ // @has - '//*[@id="examples"]/a[@href="#examples"]' '§'
+ // @has - '//*[@id="panics"]' 'Panics'
+ // @has - '//*[@id="panics"]/a[@href="#panics"]' '§'
/// # Examples
/// # Panics
pub fn bar() {}
- // @has - '//*[@id="examples-1"]//a' 'Examples'
+ // @has - '//*[@id="examples-1"]' 'Examples'
+ // @has - '//*[@id="examples-1"]/a[@href="#examples-1"]' '§'
/// # Examples
pub fn bar_1() {}
- // @has - '//*[@id="examples-2"]//a' 'Examples'
- // @has - '//*[@id="panics-1"]//a' 'Panics'
+ // @has - '//*[@id="examples-2"]' 'Examples'
+ // @has - '//*[@id="examples-2"]/a[@href="#examples-2"]' '§'
+ // @has - '//*[@id="panics-1"]' 'Panics'
+ // @has - '//*[@id="panics-1"]/a[@href="#panics-1"]' '§'
/// # Examples
/// # Panics
pub fn bar_2() {}
diff --git a/tests/rustdoc/links-in-headings.rs b/tests/rustdoc/links-in-headings.rs
new file mode 100644
index 0000000000000..c5bee1a79750c
--- /dev/null
+++ b/tests/rustdoc/links-in-headings.rs
@@ -0,0 +1,14 @@
+#![crate_name = "foo"]
+
+//! # Heading with [a link](https://a.com) inside
+//!
+//! And even with
+//!
+//! ## [multiple](https://b.com) [links](https://c.com)
+//!
+//! !
+
+// @has 'foo/index.html'
+// @has - '//h2/a[@href="https://a.com"]' 'a link'
+// @has - '//h3/a[@href="https://b.com"]' 'multiple'
+// @has - '//h3/a[@href="https://c.com"]' 'links'
diff --git a/tests/rustdoc/remove-url-from-headings.rs b/tests/rustdoc/remove-url-from-headings.rs
index 599c429a6e1de..8f4770286192e 100644
--- a/tests/rustdoc/remove-url-from-headings.rs
+++ b/tests/rustdoc/remove-url-from-headings.rs
@@ -1,9 +1,12 @@
+// It actually checks that the link is kept in the headings as expected now.
+
#![crate_name = "foo"]
// @has foo/fn.foo.html
-// @!has - '//a[@href="http://a.a"]' ''
-// @has - '//a[@href="#implementing-stuff-somewhere"]' 'Implementing stuff somewhere'
-// @has - '//a[@href="#another-one-urg"]' 'Another one urg'
+// @has - '//a[@href="http://a.a"]' 'stuff'
+// @has - '//*[@id="implementing-stuff-somewhere"]' 'Implementing stuff somewhere'
+// @has - '//a[@href="http://b.b"]' 'one'
+// @has - '//*[@id="another-one-urg"]' 'Another one urg'
/// fooo
///
@@ -13,5 +16,5 @@
///
/// # Another [one][two] urg
///
-/// [two]: http://a.a
+/// [two]: http://b.b
pub fn foo() {}
diff --git a/tests/rustdoc/short-docblock.rs b/tests/rustdoc/short-docblock.rs
index 791d3547c9fec..151a42a9c9ee5 100644
--- a/tests/rustdoc/short-docblock.rs
+++ b/tests/rustdoc/short-docblock.rs
@@ -2,8 +2,9 @@
// @has foo/index.html '//*[@class="desc docblock-short"]' 'fooo'
// @!has foo/index.html '//*[@class="desc docblock-short"]/h1' 'fooo'
-// @has foo/fn.foo.html '//h2[@id="fooo"]/a[@href="#fooo"]' 'fooo'
+// @has foo/fn.foo.html '//h2[@id="fooo"]' 'fooo'
+// @has foo/fn.foo.html '//h2[@id="fooo"]/a[@href="#fooo"]' '§'
/// # fooo
///
/// foo
@@ -11,8 +12,9 @@ pub fn foo() {}
// @has foo/index.html '//*[@class="desc docblock-short"]' 'mooood'
// @!has foo/index.html '//*[@class="desc docblock-short"]/h2' 'mooood'
-// @has foo/foo/index.html '//h3[@id="mooood"]/a[@href="#mooood"]' 'mooood'
+// @has foo/foo/index.html '//h3[@id="mooood"]' 'mooood'
+// @has foo/foo/index.html '//h3[@id="mooood"]/a[@href="#mooood"]' '§'
/// ## mooood
///
/// foo mod