From 7a718f3be217a17e00de317fba6d1d60facfd613 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Wed, 21 Sep 2022 15:26:15 -0700 Subject: rustdoc: use block flex for line-number CSS `display: inline-flex` was used as part of e961d397cab900c55f8d8c104648852e2b63664e, the original commit that added these line numbers. Does anyone know why it was done this way? --- src/librustdoc/html/static/css/rustdoc.css | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'src') diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index e985e6c43ad..1d37c4f60d0 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -577,13 +577,9 @@ h2.location a { } .rustdoc .example-wrap { - display: inline-flex; + display: flex; margin-bottom: 10px; -} - -.example-wrap { position: relative; - width: 100%; } .example-wrap > pre.line-number { -- cgit 1.4.1-3-g733a5 From f66769fe8d71d9d5d15f845e6ef918f2e417598f Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Wed, 21 Sep 2022 15:43:38 -0700 Subject: rustdoc: dynamically show-hide line numbers on code examples --- src/librustdoc/html/static/js/main.js | 41 ++++++++++++++++------ src/librustdoc/html/static/js/settings.js | 7 ++++ .../docblock-code-block-line-number.goml | 17 +++++++++ 3 files changed, 54 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js index 6e9660ddcc9..5fbe540c320 100644 --- a/src/librustdoc/html/static/js/main.js +++ b/src/librustdoc/html/static/js/main.js @@ -697,20 +697,39 @@ function loadCss(cssFileName) { } }()); + window.rustdoc_add_line_numbers_to_examples = () => { + onEachLazy(document.getElementsByClassName("rust-example-rendered"), x => { + const parent = x.parentNode; + const line_numbers = parent.querySelectorAll(".line-number"); + if (line_numbers.length > 0) { + return; + } + const count = x.textContent.split("\n").length; + const elems = []; + for (let i = 0; i < count; ++i) { + elems.push(i + 1); + } + const node = document.createElement("pre"); + addClass(node, "line-number"); + node.innerHTML = elems.join("\n"); + parent.insertBefore(node, x); + }); + }; + + window.rustdoc_remove_line_numbers_from_examples = () => { + onEachLazy(document.getElementsByClassName("rust-example-rendered"), x => { + const parent = x.parentNode; + const line_numbers = parent.querySelectorAll(".line-number"); + for (const node of line_numbers) { + parent.removeChild(node); + } + }); + }; + (function() { // To avoid checking on "rustdoc-line-numbers" value on every loop... if (getSettingValue("line-numbers") === "true") { - onEachLazy(document.getElementsByClassName("rust-example-rendered"), x => { - const count = x.textContent.split("\n").length; - const elems = []; - for (let i = 0; i < count; ++i) { - elems.push(i + 1); - } - const node = document.createElement("pre"); - addClass(node, "line-number"); - node.innerHTML = elems.join("\n"); - x.parentNode.insertBefore(node, x); - }); + window.rustdoc_add_line_numbers_to_examples(); } }()); diff --git a/src/librustdoc/html/static/js/settings.js b/src/librustdoc/html/static/js/settings.js index 797b931afc6..1c5d33e2127 100644 --- a/src/librustdoc/html/static/js/settings.js +++ b/src/librustdoc/html/static/js/settings.js @@ -19,6 +19,13 @@ updateSystemTheme(); updateLightAndDark(); break; + case "line-numbers": + if (value === true) { + window.rustdoc_add_line_numbers_to_examples(); + } else { + window.rustdoc_remove_line_numbers_from_examples(); + } + break; } } diff --git a/src/test/rustdoc-gui/docblock-code-block-line-number.goml b/src/test/rustdoc-gui/docblock-code-block-line-number.goml index baf9651c40d..ebfffbce715 100644 --- a/src/test/rustdoc-gui/docblock-code-block-line-number.goml +++ b/src/test/rustdoc-gui/docblock-code-block-line-number.goml @@ -20,3 +20,20 @@ assert-css: ("pre.line-number", { }) // The first code block has two lines so let's check its `
` elements lists both of them.
 assert-text: ("pre.line-number", "1\n2")
+
+// Now, try changing the setting dynamically. We'll turn it off, using the settings menu,
+// and make sure it goes away.
+
+// First, open the settings menu.
+click: "#settings-menu"
+wait-for: "#settings"
+assert-css: ("#settings", {"display": "block"})
+
+// Then, click the toggle button.
+click: "input#line-numbers + .slider"
+wait-for: 100 // wait-for-false does not exist
+assert-false: "pre.line-number"
+
+// Finally, turn it on again.
+click: "input#line-numbers + .slider"
+wait-for: "pre.line-number"
-- 
cgit 1.4.1-3-g733a5


From 8b4c0d90dc403cb9727e80d73c27d4f3de574d60 Mon Sep 17 00:00:00 2001
From: Michael Howell 
Date: Wed, 21 Sep 2022 16:44:33 -0700
Subject: rustdoc: adjust test to cope with slightly different scrolling
 behaviour

---
 src/test/rustdoc-gui/source-anchor-scroll.goml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'src')

diff --git a/src/test/rustdoc-gui/source-anchor-scroll.goml b/src/test/rustdoc-gui/source-anchor-scroll.goml
index 4e51c8dcac0..47e40aa8e3b 100644
--- a/src/test/rustdoc-gui/source-anchor-scroll.goml
+++ b/src/test/rustdoc-gui/source-anchor-scroll.goml
@@ -10,7 +10,7 @@ assert-property: ("html", {"scrollTop": "0"})
 click: '//a[text() = "barbar"]'
 assert-property: ("html", {"scrollTop": "125"})
 click: '//a[text() = "bar"]'
-assert-property: ("html", {"scrollTop": "166"})
+assert-property: ("html", {"scrollTop": "156"})
 click: '//a[text() = "sub_fn"]'
 assert-property: ("html", {"scrollTop": "53"})
 
-- 
cgit 1.4.1-3-g733a5


From 51c752a375b280c9d78a8a75987497ee08d16385 Mon Sep 17 00:00:00 2001
From: Steve Heindel 
Date: Wed, 21 Sep 2022 19:45:57 -0400
Subject: Add note to clippy::non_expressive_names doc

---
 src/tools/clippy/clippy_lints/src/non_expressive_names.rs | 4 ++++
 1 file changed, 4 insertions(+)

(limited to 'src')

diff --git a/src/tools/clippy/clippy_lints/src/non_expressive_names.rs b/src/tools/clippy/clippy_lints/src/non_expressive_names.rs
index b96af06b8d7..a7cd1f6d065 100644
--- a/src/tools/clippy/clippy_lints/src/non_expressive_names.rs
+++ b/src/tools/clippy/clippy_lints/src/non_expressive_names.rs
@@ -15,6 +15,10 @@ declare_clippy_lint! {
     /// ### What it does
     /// Checks for names that are very similar and thus confusing.
     ///
+    /// Note: this lint looks for similar names throughout each
+    /// scope. To allow it, you need to allow it on the scope
+    /// level, not on the name that is reported.
+    ///
     /// ### Why is this bad?
     /// It's hard to distinguish between names that differ only
     /// by a single character.
-- 
cgit 1.4.1-3-g733a5


From 876c7076c8592ac2ca7bc243340646321b224c38 Mon Sep 17 00:00:00 2001
From: Michael Howell 
Date: Wed, 21 Sep 2022 20:47:33 -0700
Subject: rustdoc: remove no-op CSS `.content .item-info { position: relative
 }`

This rule was added to help position the marker line in
110e7270ab7b0700ce714b8b1c7e509195dea2c4, which was a `position: absolute`
pseudo-element that relied on its parent to put it in the right spot.

The arrow was removed in 73d0f7c7b68784f1db0a1f53855c20d118a7e8b0, so the
`relative` position is no longer necessary.
---
 src/librustdoc/html/static/css/rustdoc.css | 1 -
 1 file changed, 1 deletion(-)

(limited to 'src')

diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css
index e985e6c43ad..a442c09bfb7 100644
--- a/src/librustdoc/html/static/css/rustdoc.css
+++ b/src/librustdoc/html/static/css/rustdoc.css
@@ -749,7 +749,6 @@ pre, .rustdoc.source .example-wrap {
 }
 
 .content .item-info {
-	position: relative;
 	margin-left: 24px;
 }
 
-- 
cgit 1.4.1-3-g733a5


From d3f97a331c40f3f64b161aed29f7ef04e607764c Mon Sep 17 00:00:00 2001
From: Guillaume Gomez 
Date: Thu, 22 Sep 2022 13:08:44 +0200
Subject: Improve some AllTypes fields name

---
 src/librustdoc/html/render/mod.rs | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

(limited to 'src')

diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs
index 7e5e4df43d2..621f83824d9 100644
--- a/src/librustdoc/html/render/mod.rs
+++ b/src/librustdoc/html/render/mod.rs
@@ -239,8 +239,8 @@ struct AllTypes {
     opaque_tys: FxHashSet,
     statics: FxHashSet,
     constants: FxHashSet,
-    attributes: FxHashSet,
-    derives: FxHashSet,
+    attribute_macros: FxHashSet,
+    derive_macros: FxHashSet,
     trait_aliases: FxHashSet,
 }
 
@@ -259,8 +259,8 @@ impl AllTypes {
             opaque_tys: new_set(100),
             statics: new_set(100),
             constants: new_set(100),
-            attributes: new_set(100),
-            derives: new_set(100),
+            attribute_macros: new_set(100),
+            derive_macros: new_set(100),
             trait_aliases: new_set(100),
         }
     }
@@ -283,8 +283,10 @@ impl AllTypes {
                 ItemType::OpaqueTy => self.opaque_tys.insert(ItemEntry::new(new_url, name)),
                 ItemType::Static => self.statics.insert(ItemEntry::new(new_url, name)),
                 ItemType::Constant => self.constants.insert(ItemEntry::new(new_url, name)),
-                ItemType::ProcAttribute => self.attributes.insert(ItemEntry::new(new_url, name)),
-                ItemType::ProcDerive => self.derives.insert(ItemEntry::new(new_url, name)),
+                ItemType::ProcAttribute => {
+                    self.attribute_macros.insert(ItemEntry::new(new_url, name))
+                }
+                ItemType::ProcDerive => self.derive_macros.insert(ItemEntry::new(new_url, name)),
                 ItemType::TraitAlias => self.trait_aliases.insert(ItemEntry::new(new_url, name)),
                 _ => true,
             };
@@ -327,10 +329,10 @@ impl AllTypes {
         if !self.constants.is_empty() {
             sections.insert(ItemSection::Constants);
         }
-        if !self.attributes.is_empty() {
+        if !self.attribute_macros.is_empty() {
             sections.insert(ItemSection::AttributeMacros);
         }
-        if !self.derives.is_empty() {
+        if !self.derive_macros.is_empty() {
             sections.insert(ItemSection::DeriveMacros);
         }
         if !self.trait_aliases.is_empty() {
@@ -373,8 +375,8 @@ impl AllTypes {
         print_entries(f, &self.primitives, ItemSection::PrimitiveTypes);
         print_entries(f, &self.traits, ItemSection::Traits);
         print_entries(f, &self.macros, ItemSection::Macros);
-        print_entries(f, &self.attributes, ItemSection::AttributeMacros);
-        print_entries(f, &self.derives, ItemSection::DeriveMacros);
+        print_entries(f, &self.attribute_macros, ItemSection::AttributeMacros);
+        print_entries(f, &self.derive_macros, ItemSection::DeriveMacros);
         print_entries(f, &self.functions, ItemSection::Functions);
         print_entries(f, &self.typedefs, ItemSection::TypeDefinitions);
         print_entries(f, &self.trait_aliases, ItemSection::TraitAliases);
-- 
cgit 1.4.1-3-g733a5


From 8abf4870ce38a790c1f75ed17fab8fa7b1334861 Mon Sep 17 00:00:00 2001
From: Michael Howell 
Date: Thu, 22 Sep 2022 11:09:29 -0700
Subject: rustdoc: remove no-op CSS `.location:empty { border: none }`

This rule was added in 2bb2a2975f25e8ba7a372898e7e112f1cec5db01 to remove a
border placed around the location when it's empty. That rule was removed in
6a5f8b1aef1417d7dc85b5d0a229d2db1930eb7c, so this rule does nothing.
---
 src/librustdoc/html/static/css/rustdoc.css | 4 ----
 1 file changed, 4 deletions(-)

(limited to 'src')

diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css
index f21179ec558..efb8a2369e8 100644
--- a/src/librustdoc/html/static/css/rustdoc.css
+++ b/src/librustdoc/html/static/css/rustdoc.css
@@ -522,10 +522,6 @@ img {
 	width: 100px;
 }
 
-.location:empty {
-	border: none;
-}
-
 .block ul, .block li {
 	padding: 0;
 	margin: 0;
-- 
cgit 1.4.1-3-g733a5