From 0f4d7b6de8f9a9d13d9a5d479cbfa74064fd689d Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 21 Sep 2022 22:20:40 +0200 Subject: [PATCH 01/12] OpTy: fix a method taking self rather than &self --- compiler/rustc_const_eval/src/interpret/place.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_const_eval/src/interpret/place.rs b/compiler/rustc_const_eval/src/interpret/place.rs index b328892906df2..bc1aa43b73a99 100644 --- a/compiler/rustc_const_eval/src/interpret/place.rs +++ b/compiler/rustc_const_eval/src/interpret/place.rs @@ -280,7 +280,7 @@ impl<'tcx, Prov: Provenance> PlaceTy<'tcx, Prov> { #[inline(always)] #[cfg_attr(debug_assertions, track_caller)] // only in debug builds due to perf (see #98980) - pub fn assert_mem_place(self) -> MPlaceTy<'tcx, Prov> { + pub fn assert_mem_place(&self) -> MPlaceTy<'tcx, Prov> { self.try_as_mplace().unwrap() } } From 7a718f3be217a17e00de317fba6d1d60facfd613 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Wed, 21 Sep 2022 15:26:15 -0700 Subject: [PATCH 02/12] 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(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index e985e6c43ade9..1d37c4f60d013 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 { From f66769fe8d71d9d5d15f845e6ef918f2e417598f Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Wed, 21 Sep 2022 15:43:38 -0700 Subject: [PATCH 03/12] 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(-) diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js index 6e9660ddcc96a..5fbe540c32045 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 797b931afc643..1c5d33e212754 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 baf9651c40de3..ebfffbce71561 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"

From 8b4c0d90dc403cb9727e80d73c27d4f3de574d60 Mon Sep 17 00:00:00 2001
From: Michael Howell 
Date: Wed, 21 Sep 2022 16:44:33 -0700
Subject: [PATCH 04/12] 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(-)

diff --git a/src/test/rustdoc-gui/source-anchor-scroll.goml b/src/test/rustdoc-gui/source-anchor-scroll.goml
index 4e51c8dcac0af..47e40aa8e3b1c 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"})
 

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

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

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 b96af06b8d7c6..a7cd1f6d0652b 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.

From 876c7076c8592ac2ca7bc243340646321b224c38 Mon Sep 17 00:00:00 2001
From: Michael Howell 
Date: Wed, 21 Sep 2022 20:47:33 -0700
Subject: [PATCH 06/12] 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(-)

diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css
index e985e6c43ade9..a442c09bfb7c3 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;
 }
 

From 2d7f9877153623c841517f8c6578edafd19c4daa Mon Sep 17 00:00:00 2001
From: Takayuki Maeda 
Date: Thu, 22 Sep 2022 16:11:51 +0900
Subject: [PATCH 07/12] use appropriate variable names

---
 compiler/rustc_passes/src/check_attr.rs | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs
index b3f15ba7cbf25..f112f1274b8c7 100644
--- a/compiler/rustc_passes/src/check_attr.rs
+++ b/compiler/rustc_passes/src/check_attr.rs
@@ -35,8 +35,8 @@ pub(crate) fn target_from_impl_item<'tcx>(
     match impl_item.kind {
         hir::ImplItemKind::Const(..) => Target::AssocConst,
         hir::ImplItemKind::Fn(..) => {
-            let parent_hir_id = tcx.hir().get_parent_item(impl_item.hir_id());
-            let containing_item = tcx.hir().expect_item(parent_hir_id);
+            let parent_def_id = tcx.hir().get_parent_item(impl_item.hir_id());
+            let containing_item = tcx.hir().expect_item(parent_def_id);
             let containing_impl_is_for_trait = match &containing_item.kind {
                 hir::ItemKind::Impl(impl_) => impl_.of_trait.is_some(),
                 _ => bug!("parent of an ImplItem must be an Impl"),
@@ -640,8 +640,8 @@ impl CheckAttrVisitor<'_> {
         let span = meta.span();
         if let Some(location) = match target {
             Target::AssocTy => {
-                let parent_hir_id = self.tcx.hir().get_parent_item(hir_id);
-                let containing_item = self.tcx.hir().expect_item(parent_hir_id);
+                let parent_def_id = self.tcx.hir().get_parent_item(hir_id);
+                let containing_item = self.tcx.hir().expect_item(parent_def_id);
                 if Target::from_item(containing_item) == Target::Impl {
                     Some("type alias in implementation block")
                 } else {
@@ -649,8 +649,8 @@ impl CheckAttrVisitor<'_> {
                 }
             }
             Target::AssocConst => {
-                let parent_hir_id = self.tcx.hir().get_parent_item(hir_id);
-                let containing_item = self.tcx.hir().expect_item(parent_hir_id);
+                let parent_def_id = self.tcx.hir().get_parent_item(hir_id);
+                let containing_item = self.tcx.hir().expect_item(parent_def_id);
                 // We can't link to trait impl's consts.
                 let err = "associated constant in trait implementation block";
                 match containing_item.kind {

From 13438ee29c7835969765f273df34312586d31731 Mon Sep 17 00:00:00 2001
From: Oli Scherer 
Date: Thu, 22 Sep 2022 08:20:13 +0000
Subject: [PATCH 08/12] Const unification is already infallible, remove the
 error handling logic

---
 compiler/rustc_infer/src/infer/combine.rs    | 37 ++++++--------------
 compiler/rustc_middle/src/infer/unify_key.rs |  2 +-
 2 files changed, 12 insertions(+), 27 deletions(-)

diff --git a/compiler/rustc_infer/src/infer/combine.rs b/compiler/rustc_infer/src/infer/combine.rs
index c406df9e41116..682ad02da8635 100644
--- a/compiler/rustc_infer/src/infer/combine.rs
+++ b/compiler/rustc_infer/src/infer/combine.rs
@@ -147,11 +147,7 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {
                 ty::ConstKind::Infer(InferConst::Var(a_vid)),
                 ty::ConstKind::Infer(InferConst::Var(b_vid)),
             ) => {
-                self.inner
-                    .borrow_mut()
-                    .const_unification_table()
-                    .unify_var_var(a_vid, b_vid)
-                    .map_err(|e| const_unification_error(a_is_expected, e))?;
+                self.inner.borrow_mut().const_unification_table().union(a_vid, b_vid);
                 return Ok(a);
             }
 
@@ -246,21 +242,17 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {
         let value = ConstInferUnifier { infcx: self, span, param_env, for_universe, target_vid }
             .relate(ct, ct)?;
 
-        self.inner
-            .borrow_mut()
-            .const_unification_table()
-            .unify_var_value(
-                target_vid,
-                ConstVarValue {
-                    origin: ConstVariableOrigin {
-                        kind: ConstVariableOriginKind::ConstInference,
-                        span: DUMMY_SP,
-                    },
-                    val: ConstVariableValue::Known { value },
+        self.inner.borrow_mut().const_unification_table().union_value(
+            target_vid,
+            ConstVarValue {
+                origin: ConstVariableOrigin {
+                    kind: ConstVariableOriginKind::ConstInference,
+                    span: DUMMY_SP,
                 },
-            )
-            .map(|()| value)
-            .map_err(|e| const_unification_error(vid_is_expected, e))
+                val: ConstVariableValue::Known { value },
+            },
+        );
+        Ok(value)
     }
 
     fn unify_integral_variable(
@@ -768,13 +760,6 @@ pub trait ConstEquateRelation<'tcx>: TypeRelation<'tcx> {
     fn const_equate_obligation(&mut self, a: ty::Const<'tcx>, b: ty::Const<'tcx>);
 }
 
-pub fn const_unification_error<'tcx>(
-    a_is_expected: bool,
-    (a, b): (ty::Const<'tcx>, ty::Const<'tcx>),
-) -> TypeError<'tcx> {
-    TypeError::ConstMismatch(ExpectedFound::new(a_is_expected, a, b))
-}
-
 fn int_unification_error<'tcx>(
     a_is_expected: bool,
     v: (ty::IntVarValue, ty::IntVarValue),
diff --git a/compiler/rustc_middle/src/infer/unify_key.rs b/compiler/rustc_middle/src/infer/unify_key.rs
index f2627885d030d..41d8c7ffdb945 100644
--- a/compiler/rustc_middle/src/infer/unify_key.rs
+++ b/compiler/rustc_middle/src/infer/unify_key.rs
@@ -129,7 +129,7 @@ impl<'tcx> UnifyKey for ty::ConstVid<'tcx> {
 }
 
 impl<'tcx> UnifyValue for ConstVarValue<'tcx> {
-    type Error = (ty::Const<'tcx>, ty::Const<'tcx>);
+    type Error = NoError;
 
     fn unify_values(&value1: &Self, &value2: &Self) -> Result {
         Ok(match (value1.val, value2.val) {

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

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

diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs
index 7e5e4df43d291..621f83824d966 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);

From e8594257f691a1e4e960f1dbb5dd92146fe9d978 Mon Sep 17 00:00:00 2001
From: b-naber 
Date: Thu, 22 Sep 2022 12:49:04 +0200
Subject: [PATCH 10/12] use valtrees for comparison

---
 compiler/rustc_middle/src/ty/fast_reject.rs | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/compiler/rustc_middle/src/ty/fast_reject.rs b/compiler/rustc_middle/src/ty/fast_reject.rs
index 8d019a3bad8cc..41bb3c7140172 100644
--- a/compiler/rustc_middle/src/ty/fast_reject.rs
+++ b/compiler/rustc_middle/src/ty/fast_reject.rs
@@ -384,14 +384,7 @@ impl DeepRejectCtxt {
             // they might unify with any value.
             ty::ConstKind::Unevaluated(_) | ty::ConstKind::Error(_) => true,
             ty::ConstKind::Value(obl) => match k {
-                ty::ConstKind::Value(imp) => {
-                    // FIXME(valtrees): Once we have valtrees, we can just
-                    // compare them directly here.
-                    match (obl.try_to_scalar_int(), imp.try_to_scalar_int()) {
-                        (Some(obl), Some(imp)) => obl == imp,
-                        _ => true,
-                    }
-                }
+                ty::ConstKind::Value(imp) => obl == imp,
                 _ => true,
             },
 

From 5a5138df5940119744ba80b1d3ed29b1024b973d Mon Sep 17 00:00:00 2001
From: onestacked 
Date: Thu, 22 Sep 2022 18:21:34 +0200
Subject: [PATCH 11/12] Constify {FormResidual, Try} for ControlFlow

---
 library/core/src/ops/control_flow.rs | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/library/core/src/ops/control_flow.rs b/library/core/src/ops/control_flow.rs
index b1f5559dcfc17..fd567a8c68492 100644
--- a/library/core/src/ops/control_flow.rs
+++ b/library/core/src/ops/control_flow.rs
@@ -95,7 +95,8 @@ pub enum ControlFlow {
 }
 
 #[unstable(feature = "try_trait_v2", issue = "84277")]
-impl ops::Try for ControlFlow {
+#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
+impl const ops::Try for ControlFlow {
     type Output = C;
     type Residual = ControlFlow;
 
@@ -114,7 +115,8 @@ impl ops::Try for ControlFlow {
 }
 
 #[unstable(feature = "try_trait_v2", issue = "84277")]
-impl ops::FromResidual for ControlFlow {
+#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
+impl const ops::FromResidual for ControlFlow {
     #[inline]
     fn from_residual(residual: ControlFlow) -> Self {
         match residual {

From 8abf4870ce38a790c1f75ed17fab8fa7b1334861 Mon Sep 17 00:00:00 2001
From: Michael Howell 
Date: Thu, 22 Sep 2022 11:09:29 -0700
Subject: [PATCH 12/12] 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(-)

diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css
index f21179ec558f0..efb8a2369e870 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;