From 1fe3ce476c0c36485b90d0bd5dc8cb27f57be1c6 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Mon, 26 Sep 2022 09:20:20 -0700 Subject: [PATCH 1/7] rustdoc: remove unneeded CSS `td, th { padding 0 }` This was added in 510107815fe888319028c5e96001cdee70e7a931, to fix the display of the module items and search results tables (see the discussion in https://github.com/rust-lang/rust/pull/86725). Those aren't tables any more. The only remaining table is in docblock, which has its own padding declarations. --- src/librustdoc/html/static/css/rustdoc.css | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 28dc4bf30108e..5257ab600c50a 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -299,11 +299,6 @@ summary { /* Fix some style changes due to normalize.css 8 */ -td, -th { - padding: 0; -} - table { border-collapse: collapse; } From 99904445b8d8e37f27ae7ababd5f3fb48b0d8813 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Mon, 26 Sep 2022 09:54:44 -0700 Subject: [PATCH 2/7] rustdoc: merge `table { border-collapse } into `.docblock table` This was added in 510107815fe888319028c5e96001cdee70e7a931, to fix the display of the module items and search results tables (see the discussion in https://github.com/rust-lang/rust/pull/86725). Those aren't tables any more. The only remaining table is in docblock, which needs this attribute to look right. --- src/librustdoc/html/static/css/rustdoc.css | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 5257ab600c50a..679aea411d192 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -299,10 +299,6 @@ summary { /* Fix some style changes due to normalize.css 8 */ -table { - border-collapse: collapse; -} - button, input, optgroup, @@ -690,6 +686,7 @@ pre, .rustdoc.source .example-wrap { width: calc(100% - 2px); overflow-x: auto; display: block; + border-collapse: collapse; } .docblock table td { From 4fad063cbac1cbdbe831da23c0722487cebc81f3 Mon Sep 17 00:00:00 2001 From: Matthew Esposito Date: Mon, 26 Sep 2022 12:50:45 -0400 Subject: [PATCH 3/7] Document that Display entails ToString --- library/core/src/fmt/mod.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs index 905212eb372b1..372439f14ec83 100644 --- a/library/core/src/fmt/mod.rs +++ b/library/core/src/fmt/mod.rs @@ -709,12 +709,19 @@ pub use macros::Debug; /// Format trait for an empty format, `{}`. /// +/// Implementing this trait for a type will automatically implement the +/// [`ToString`][tostring] trait for the type, allowing the usage +/// of the [`.to_string()`][tostring_function] method. Prefer implementing +/// the `Display` trait for a type, rather than [`ToString`][tostring]. +/// /// `Display` is similar to [`Debug`], but `Display` is for user-facing /// output, and so cannot be derived. /// /// For more information on formatters, see [the module-level documentation][module]. /// /// [module]: ../../std/fmt/index.html +/// [tostring]: ../../std/string/trait.ToString.html +/// [tostring_function]: ../../std/string/trait.ToString.html#tymethod.to_string /// /// # Examples /// From aac7429c17aa558fbd9fb0be093e7bd9ccc73972 Mon Sep 17 00:00:00 2001 From: Nixon Enraght-Moony Date: Mon, 26 Sep 2022 18:06:48 +0100 Subject: [PATCH 4/7] Rustdoc-Json: List impls for primitives Closes #101695 --- src/librustdoc/json/conversions.rs | 7 +++- src/librustdoc/json/mod.rs | 7 ++-- src/rustdoc-json-types/lib.rs | 10 ++++-- .../primitives/primitive_impls.rs | 34 +++++++++++++++++++ .../{ => primitives}/primitive_overloading.rs | 0 .../primitive_type.rs} | 0 .../use_primitive.rs} | 2 +- src/tools/jsondoclint/src/item_kind.rs | 3 +- src/tools/jsondoclint/src/validator.rs | 10 +++--- 9 files changed, 60 insertions(+), 13 deletions(-) create mode 100644 src/test/rustdoc-json/primitives/primitive_impls.rs rename src/test/rustdoc-json/{ => primitives}/primitive_overloading.rs (100%) rename src/test/rustdoc-json/{primitives.rs => primitives/primitive_type.rs} (100%) rename src/test/rustdoc-json/{primitive.rs => primitives/use_primitive.rs} (88%) diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs index 49a31f5f1da1f..4170412caef87 100644 --- a/src/librustdoc/json/conversions.rs +++ b/src/librustdoc/json/conversions.rs @@ -272,7 +272,12 @@ fn from_clean_item(item: clean::Item, tcx: TyCtxt<'_>) -> ItemEnum { ConstantItem(c) => ItemEnum::Constant(c.into_tcx(tcx)), MacroItem(m) => ItemEnum::Macro(m.source), ProcMacroItem(m) => ItemEnum::ProcMacro(m.into_tcx(tcx)), - PrimitiveItem(p) => ItemEnum::PrimitiveType(p.as_sym().to_string()), + PrimitiveItem(p) => { + ItemEnum::Primitive(Primitive { + name: p.as_sym().to_string(), + impls: Vec::new(), // Added in JsonRenderer::item + }) + } TyAssocConstItem(ty) => ItemEnum::AssocConst { type_: ty.into_tcx(tcx), default: None }, AssocConstItem(ty, default) => { ItemEnum::AssocConst { type_: ty.into_tcx(tcx), default: Some(default.expr(tcx)) } diff --git a/src/librustdoc/json/mod.rs b/src/librustdoc/json/mod.rs index 5e8f5f6fe3eb9..8d6450838c1d0 100644 --- a/src/librustdoc/json/mod.rs +++ b/src/librustdoc/json/mod.rs @@ -219,12 +219,15 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> { u.impls = self.get_impls(item_id.expect_def_id()); false } + types::ItemEnum::Primitive(ref mut p) => { + p.impls = self.get_impls(item_id.expect_def_id()); + false + } types::ItemEnum::Method(_) | types::ItemEnum::Module(_) | types::ItemEnum::AssocConst { .. } - | types::ItemEnum::AssocType { .. } - | types::ItemEnum::PrimitiveType(_) => true, + | types::ItemEnum::AssocType { .. } => true, types::ItemEnum::ExternCrate { .. } | types::ItemEnum::Import(_) | types::ItemEnum::StructField(_) diff --git a/src/rustdoc-json-types/lib.rs b/src/rustdoc-json-types/lib.rs index fb183042670e8..7379b04ad1677 100644 --- a/src/rustdoc-json-types/lib.rs +++ b/src/rustdoc-json-types/lib.rs @@ -9,7 +9,7 @@ use std::path::PathBuf; use serde::{Deserialize, Serialize}; /// rustdoc format-version. -pub const FORMAT_VERSION: u32 = 21; +pub const FORMAT_VERSION: u32 = 22; /// A `Crate` is the root of the emitted JSON blob. It contains all type/documentation information /// about the language items in the local crate, as well as info about external items to allow @@ -254,7 +254,7 @@ pub enum ItemEnum { Macro(String), ProcMacro(ProcMacro), - PrimitiveType(String), + Primitive(Primitive), AssocConst { #[serde(rename = "type")] @@ -709,5 +709,11 @@ pub struct Static { pub expr: String, } +#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] +pub struct Primitive { + pub name: String, + pub impls: Vec, +} + #[cfg(test)] mod tests; diff --git a/src/test/rustdoc-json/primitives/primitive_impls.rs b/src/test/rustdoc-json/primitives/primitive_impls.rs new file mode 100644 index 0000000000000..1fc9374065f66 --- /dev/null +++ b/src/test/rustdoc-json/primitives/primitive_impls.rs @@ -0,0 +1,34 @@ +#![feature(no_core)] +#![feature(rustc_attrs)] +#![feature(rustdoc_internals)] +#![no_core] +#![rustc_coherence_is_core] + +// @set impl_i32 = "$.index[*][?(@.docs=='Only core can do this')].id" + +/// Only core can do this +impl i32 { + // @set identity = "$.index[*][?(@.docs=='Do Nothing')].id" + + /// Do Nothing + pub fn identity(self) -> Self { + self + } + + // @is "$.index[*][?(@.docs=='Only core can do this')].inner.items[*]" $identity +} + +// @set Trait = "$.index[*][?(@.name=='Trait')].id" +pub trait Trait {} +// @set impl_trait_for_i32 = "$.index[*][?(@.docs=='impl Trait for i32')].id" +/// impl Trait for i32 +impl Trait for i32 {} + +/// i32 +#[doc(primitive = "i32")] +mod prim_i32 {} + +// @set i32 = "$.index[*][?(@.docs=='i32')].id" +// @is "$.index[*][?(@.docs=='i32')].name" '"i32"' +// @is "$.index[*][?(@.docs=='i32')].inner.name" '"i32"' +// @ismany "$.index[*][?(@.docs=='i32')].inner.impls[*]" $impl_i32 $impl_trait_for_i32 diff --git a/src/test/rustdoc-json/primitive_overloading.rs b/src/test/rustdoc-json/primitives/primitive_overloading.rs similarity index 100% rename from src/test/rustdoc-json/primitive_overloading.rs rename to src/test/rustdoc-json/primitives/primitive_overloading.rs diff --git a/src/test/rustdoc-json/primitives.rs b/src/test/rustdoc-json/primitives/primitive_type.rs similarity index 100% rename from src/test/rustdoc-json/primitives.rs rename to src/test/rustdoc-json/primitives/primitive_type.rs diff --git a/src/test/rustdoc-json/primitive.rs b/src/test/rustdoc-json/primitives/use_primitive.rs similarity index 88% rename from src/test/rustdoc-json/primitive.rs rename to src/test/rustdoc-json/primitives/use_primitive.rs index 6454dd7f51fab..e22927374621f 100644 --- a/src/test/rustdoc-json/primitive.rs +++ b/src/test/rustdoc-json/primitives/use_primitive.rs @@ -5,7 +5,7 @@ #[doc(primitive = "usize")] mod usize {} -// @set local_crate_id = "$.index[*][?(@.name=='primitive')].crate_id" +// @set local_crate_id = "$.index[*][?(@.name=='use_primitive')].crate_id" // @has "$.index[*][?(@.name=='ilog10')]" // @!is "$.index[*][?(@.name=='ilog10')].crate_id" $local_crate_id diff --git a/src/tools/jsondoclint/src/item_kind.rs b/src/tools/jsondoclint/src/item_kind.rs index ad8e96a0bd81d..6d986e57501a3 100644 --- a/src/tools/jsondoclint/src/item_kind.rs +++ b/src/tools/jsondoclint/src/item_kind.rs @@ -142,8 +142,7 @@ impl Kind { ItemEnum::Static(_) => Static, ItemEnum::Macro(_) => Macro, ItemEnum::ProcMacro(_) => ProcMacro, - // https://github.com/rust-lang/rust/issues/100961 - ItemEnum::PrimitiveType(_) => Primitive, + ItemEnum::Primitive(_) => Primitive, ItemEnum::ForeignType => ForeignType, ItemEnum::ExternCrate { .. } => ExternCrate, ItemEnum::AssocConst { .. } => AssocConst, diff --git a/src/tools/jsondoclint/src/validator.rs b/src/tools/jsondoclint/src/validator.rs index a0e77127dc2ca..94af4c5e9e16d 100644 --- a/src/tools/jsondoclint/src/validator.rs +++ b/src/tools/jsondoclint/src/validator.rs @@ -4,8 +4,8 @@ use std::hash::Hash; use rustdoc_json_types::{ Constant, Crate, DynTrait, Enum, FnDecl, Function, FunctionPointer, GenericArg, GenericArgs, GenericBound, GenericParamDef, Generics, Id, Impl, Import, ItemEnum, Method, Module, OpaqueTy, - Path, ProcMacro, Static, Struct, StructKind, Term, Trait, TraitAlias, Type, TypeBinding, - TypeBindingKind, Typedef, Union, Variant, WherePredicate, + Path, Primitive, ProcMacro, Static, Struct, StructKind, Term, Trait, TraitAlias, Type, + TypeBinding, TypeBindingKind, Typedef, Union, Variant, WherePredicate, }; use crate::{item_kind::Kind, Error, ErrorKind}; @@ -76,7 +76,7 @@ impl<'a> Validator<'a> { ItemEnum::ForeignType => {} // nop ItemEnum::Macro(x) => self.check_macro(x), ItemEnum::ProcMacro(x) => self.check_proc_macro(x), - ItemEnum::PrimitiveType(x) => self.check_primitive_type(x), + ItemEnum::Primitive(x) => self.check_primitive_type(x), ItemEnum::Module(x) => self.check_module(x), // FIXME: Why don't these have their own structs? ItemEnum::ExternCrate { .. } => {} @@ -219,8 +219,8 @@ impl<'a> Validator<'a> { // nop } - fn check_primitive_type(&mut self, _: &'a str) { - // nop + fn check_primitive_type(&mut self, x: &'a Primitive) { + x.impls.iter().for_each(|i| self.add_impl_id(i)); } fn check_generics(&mut self, x: &'a Generics) { From 40f404468aa76f5d099d9617cecf91f72ac375b0 Mon Sep 17 00:00:00 2001 From: yancy Date: Mon, 26 Sep 2022 20:20:13 +0200 Subject: [PATCH 5/7] rustdoc: Update doc comment for splitn_mut to include mutable in the description --- library/core/src/slice/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index cd04fa0044241..aed8fbf092ed3 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -2076,7 +2076,7 @@ impl [T] { SplitN::new(self.split(pred), n) } - /// Returns an iterator over subslices separated by elements that match + /// Returns an iterator over mutable subslices separated by elements that match /// `pred`, limited to returning at most `n` items. The matched element is /// not contained in the subslices. /// From 0b97831af756b0b1dd7c75f1f5c35436b2424663 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Mon, 26 Sep 2022 10:50:51 -0700 Subject: [PATCH 6/7] rustdoc: give `.line-number` / `.line-numbers` meaningful names --- src/librustdoc/html/sources.rs | 2 +- src/librustdoc/html/static/css/rustdoc.css | 18 +++++++++--------- src/librustdoc/html/static/css/themes/ayu.css | 8 ++++---- src/librustdoc/html/static/css/themes/dark.css | 8 ++++---- .../html/static/css/themes/light.css | 8 ++++---- src/librustdoc/html/static/js/main.js | 6 +++--- .../html/static/js/scrape-examples.js | 2 +- src/librustdoc/html/static/js/source-script.js | 4 ++-- .../rustdoc-scrape-examples-macros/src/lib.rs | 8 ++++---- src/test/rustdoc-gui/basic-code.goml | 2 +- .../docblock-code-block-line-number.goml | 12 ++++++------ src/test/rustdoc-gui/source-code-page.goml | 16 ++++++++-------- 12 files changed, 47 insertions(+), 47 deletions(-) diff --git a/src/librustdoc/html/sources.rs b/src/librustdoc/html/sources.rs index 2e2bee78b95f9..7ab65bff3469f 100644 --- a/src/librustdoc/html/sources.rs +++ b/src/librustdoc/html/sources.rs @@ -274,7 +274,7 @@ pub(crate) fn print_src( ) { let lines = s.lines().count(); let mut line_numbers = Buffer::empty_from(buf); - line_numbers.write_str("
");
+    line_numbers.write_str("
");
     match source_context {
         SourceContext::Standalone => {
             for line in 1..=lines {
diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css
index 28dc4bf30108e..b4c7638b79841 100644
--- a/src/librustdoc/html/static/css/rustdoc.css
+++ b/src/librustdoc/html/static/css/rustdoc.css
@@ -578,7 +578,7 @@ h2.location a {
 	position: relative;
 }
 
-.example-wrap > pre.line-number {
+.example-wrap > pre.example-line-numbers {
 	overflow: initial;
 	border: 1px solid;
 	padding: 13px 8px;
@@ -591,15 +591,15 @@ h2.location a {
 	text-decoration: underline;
 }
 
-.line-numbers {
+.src-line-numbers {
 	text-align: right;
 }
-.rustdoc:not(.source) .example-wrap > pre:not(.line-number) {
+.rustdoc:not(.source) .example-wrap > pre:not(.example-line-numbers) {
 	width: 100%;
 	overflow-x: auto;
 }
 
-.rustdoc:not(.source) .example-wrap > pre.line-numbers {
+.rustdoc:not(.source) .example-wrap > pre.src-line-numbers {
 	width: auto;
 	overflow-x: visible;
 }
@@ -612,14 +612,14 @@ h2.location a {
 	text-align: center;
 }
 
-.content > .example-wrap pre.line-numbers {
+.content > .example-wrap pre.src-line-numbers {
 	position: relative;
 	-webkit-user-select: none;
 	-moz-user-select: none;
 	-ms-user-select: none;
 	user-select: none;
 }
-.line-numbers span {
+.src-line-numbers span {
 	cursor: pointer;
 }
 
@@ -2067,7 +2067,7 @@ in storage.js plus the media query with (min-width: 701px)
 	padding-bottom: 0;
 }
 
-.scraped-example:not(.expanded) .code-wrapper pre.line-numbers {
+.scraped-example:not(.expanded) .code-wrapper pre.src-line-numbers {
 	overflow-x: hidden;
 }
 
@@ -2113,12 +2113,12 @@ in storage.js plus the media query with (min-width: 701px)
 	bottom: 0;
 }
 
-.scraped-example .code-wrapper .line-numbers {
+.scraped-example .code-wrapper .src-line-numbers {
 	margin: 0;
 	padding: 14px 0;
 }
 
-.scraped-example .code-wrapper .line-numbers span {
+.scraped-example .code-wrapper .src-line-numbers span {
 	padding: 0 14px;
 }
 
diff --git a/src/librustdoc/html/static/css/themes/ayu.css b/src/librustdoc/html/static/css/themes/ayu.css
index e7a898e9fa62c..34411ace6fd37 100644
--- a/src/librustdoc/html/static/css/themes/ayu.css
+++ b/src/librustdoc/html/static/css/themes/ayu.css
@@ -93,8 +93,8 @@ pre, .rustdoc.source .example-wrap {
 	color: #ff7733;
 }
 
-.line-numbers span { color: #5c6773; }
-.line-numbers .line-highlighted {
+.src-line-numbers span { color: #5c6773; }
+.src-line-numbers .line-highlighted {
 	color: #708090;
 	background-color: rgba(255, 236, 164, 0.06);
 	padding-right: 4px;
@@ -171,7 +171,7 @@ details.rustdoc-toggle > summary::before {
 	color: #788797;
 }
 
-.line-numbers :target { background-color: transparent; }
+.src-line-numbers :target { background-color: transparent; }
 
 /* Code highlighting */
 pre.rust .number, pre.rust .string { color: #b8cc52; }
@@ -190,7 +190,7 @@ pre.rust .attribute {
 	color: #e6e1cf;
 }
 
-.example-wrap > pre.line-number {
+.example-wrap > pre.example-line-numbers {
 	color: #5c67736e;
 	border: none;
 }
diff --git a/src/librustdoc/html/static/css/themes/dark.css b/src/librustdoc/html/static/css/themes/dark.css
index 07a1ed8b7db74..9978f5f91874c 100644
--- a/src/librustdoc/html/static/css/themes/dark.css
+++ b/src/librustdoc/html/static/css/themes/dark.css
@@ -54,8 +54,8 @@ input:focus + .slider {
 	background: #444;
 }
 
-.line-numbers span { color: #3B91E2; }
-.line-numbers .line-highlighted {
+.src-line-numbers span { color: #3B91E2; }
+.src-line-numbers .line-highlighted {
 	background-color: #0a042f !important;
 }
 
@@ -141,7 +141,7 @@ details.rustdoc-toggle > summary::before {
 	background: none;
 }
 
-.line-numbers :target { background-color: transparent; }
+.src-line-numbers :target { background-color: transparent; }
 
 /* Code highlighting */
 pre.rust .kw { color: #ab8ac1; }
@@ -155,7 +155,7 @@ pre.rust .question-mark {
 	color: #ff9011;
 }
 
-.example-wrap > pre.line-number {
+.example-wrap > pre.example-line-numbers {
 	border-color: #4a4949;
 }
 
diff --git a/src/librustdoc/html/static/css/themes/light.css b/src/librustdoc/html/static/css/themes/light.css
index 64335f6292801..377aca7b3a79f 100644
--- a/src/librustdoc/html/static/css/themes/light.css
+++ b/src/librustdoc/html/static/css/themes/light.css
@@ -53,8 +53,8 @@ input:focus + .slider {
 	background-color: #fff;
 }
 
-.line-numbers span { color: #c67e2d; }
-.line-numbers .line-highlighted {
+.src-line-numbers span { color: #c67e2d; }
+.src-line-numbers .line-highlighted {
 	background-color: #FDFFD3 !important;
 }
 
@@ -125,7 +125,7 @@ body.source .example-wrap pre.rust a {
 .stab { background: #FFF5D6; border-color: #FFC600; }
 .stab.portability > code { background: none; }
 
-.line-numbers :target { background-color: transparent; }
+.src-line-numbers :target { background-color: transparent; }
 
 /* Code highlighting */
 pre.rust .kw { color: #8959A8; }
@@ -141,7 +141,7 @@ pre.rust .question-mark {
 	color: #ff9011;
 }
 
-.example-wrap > pre.line-number {
+.example-wrap > pre.example-line-numbers {
 	border-color: #c7c7c7;
 }
 
diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js
index c9674f11a5ecf..bbaf6d3b50797 100644
--- a/src/librustdoc/html/static/js/main.js
+++ b/src/librustdoc/html/static/js/main.js
@@ -699,7 +699,7 @@ 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");
+            const line_numbers = parent.querySelectorAll(".example-line-numbers");
             if (line_numbers.length > 0) {
                 return;
             }
@@ -709,7 +709,7 @@ function loadCss(cssFileName) {
                 elems.push(i + 1);
             }
             const node = document.createElement("pre");
-            addClass(node, "line-number");
+            addClass(node, "example-line-numbers");
             node.innerHTML = elems.join("\n");
             parent.insertBefore(node, x);
         });
@@ -718,7 +718,7 @@ function loadCss(cssFileName) {
     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");
+            const line_numbers = parent.querySelectorAll(".example-line-numbers");
             for (const node of line_numbers) {
                 parent.removeChild(node);
             }
diff --git a/src/librustdoc/html/static/js/scrape-examples.js b/src/librustdoc/html/static/js/scrape-examples.js
index fd7a1449763eb..d0fd115fd15c6 100644
--- a/src/librustdoc/html/static/js/scrape-examples.js
+++ b/src/librustdoc/html/static/js/scrape-examples.js
@@ -8,7 +8,7 @@
 
     // Scroll code block to the given code location
     function scrollToLoc(elt, loc) {
-        const lines = elt.querySelector(".line-numbers");
+        const lines = elt.querySelector(".src-line-numbers");
         let scrollOffset;
 
         // If the block is greater than the size of the viewer,
diff --git a/src/librustdoc/html/static/js/source-script.js b/src/librustdoc/html/static/js/source-script.js
index 06d15d9e5ffea..8286e9201e649 100644
--- a/src/librustdoc/html/static/js/source-script.js
+++ b/src/librustdoc/html/static/js/source-script.js
@@ -183,7 +183,7 @@ function highlightSourceLines(match) {
     if (x) {
         x.scrollIntoView();
     }
-    onEachLazy(document.getElementsByClassName("line-numbers"), e => {
+    onEachLazy(document.getElementsByClassName("src-line-numbers"), e => {
         onEachLazy(e.getElementsByTagName("span"), i_e => {
             removeClass(i_e, "line-highlighted");
         });
@@ -245,7 +245,7 @@ window.addEventListener("hashchange", () => {
     }
 });
 
-onEachLazy(document.getElementsByClassName("line-numbers"), el => {
+onEachLazy(document.getElementsByClassName("src-line-numbers"), el => {
     el.addEventListener("click", handleSourceHighlight);
 });
 
diff --git a/src/test/run-make-fulldeps/rustdoc-scrape-examples-macros/src/lib.rs b/src/test/run-make-fulldeps/rustdoc-scrape-examples-macros/src/lib.rs
index bac3970a4d37f..d8658a0f25577 100644
--- a/src/test/run-make-fulldeps/rustdoc-scrape-examples-macros/src/lib.rs
+++ b/src/test/run-make-fulldeps/rustdoc-scrape-examples-macros/src/lib.rs
@@ -1,8 +1,8 @@
 // Scraped example should only include line numbers for items b and c in ex.rs
-// @!has foobar/fn.f.html '//*[@class="line-numbers"]' '14'
-// @has foobar/fn.f.html '//*[@class="line-numbers"]' '15'
-// @has foobar/fn.f.html '//*[@class="line-numbers"]' '21'
-// @!has foobar/fn.f.html '//*[@class="line-numbers"]' '22'
+// @!has foobar/fn.f.html '//*[@class="src-line-numbers"]' '14'
+// @has foobar/fn.f.html '//*[@class="src-line-numbers"]' '15'
+// @has foobar/fn.f.html '//*[@class="src-line-numbers"]' '21'
+// @!has foobar/fn.f.html '//*[@class="src-line-numbers"]' '22'
 
 pub fn f() {}
 
diff --git a/src/test/rustdoc-gui/basic-code.goml b/src/test/rustdoc-gui/basic-code.goml
index 27deb2c989c8b..79090b499c832 100644
--- a/src/test/rustdoc-gui/basic-code.goml
+++ b/src/test/rustdoc-gui/basic-code.goml
@@ -1,3 +1,3 @@
 goto: file://|DOC_PATH|/test_docs/index.html
 click: ".srclink"
-assert-count: (".line-numbers", 1)
+assert-count: (".src-line-numbers", 1)
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 ebfffbce71561..4e1e83c0fbd73 100644
--- a/src/test/rustdoc-gui/docblock-code-block-line-number.goml
+++ b/src/test/rustdoc-gui/docblock-code-block-line-number.goml
@@ -2,7 +2,7 @@
 goto: file://|DOC_PATH|/test_docs/fn.foo.html
 
 // We check that without this setting, there is no line number displayed.
-assert-false: "pre.line-number"
+assert-false: "pre.example-line-numbers"
 
 // We now set the setting to show the line numbers on code examples.
 local-storage: {"rustdoc-line-numbers": "true" }
@@ -10,16 +10,16 @@ local-storage: {"rustdoc-line-numbers": "true" }
 reload:
 
 // We wait for them to be added into the DOM by the JS...
-wait-for: "pre.line-number"
+wait-for: "pre.example-line-numbers"
 // If the test didn't fail, it means that it was found!
 // Let's now check some CSS properties...
-assert-css: ("pre.line-number", {
+assert-css: ("pre.example-line-numbers", {
     "margin": "0px",
     "padding": "13px 8px",
     "text-align": "right",
 })
 // The first code block has two lines so let's check its `
` elements lists both of them.
-assert-text: ("pre.line-number", "1\n2")
+assert-text: ("pre.example-line-numbers", "1\n2")
 
 // Now, try changing the setting dynamically. We'll turn it off, using the settings menu,
 // and make sure it goes away.
@@ -32,8 +32,8 @@ 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"
+assert-false: "pre.example-line-numbers"
 
 // Finally, turn it on again.
 click: "input#line-numbers + .slider"
-wait-for: "pre.line-number"
+wait-for: "pre.example-line-numbers"
diff --git a/src/test/rustdoc-gui/source-code-page.goml b/src/test/rustdoc-gui/source-code-page.goml
index 581f826a3d94d..5f0bb7f19c050 100644
--- a/src/test/rustdoc-gui/source-code-page.goml
+++ b/src/test/rustdoc-gui/source-code-page.goml
@@ -1,22 +1,22 @@
 // Checks that the interactions with the source code pages are working as expected.
 goto: file://|DOC_PATH|/src/test_docs/lib.rs.html
 // Check that we can click on the line number.
-click: ".line-numbers > span:nth-child(4)" // This is the span for line 4.
+click: ".src-line-numbers > span:nth-child(4)" // This is the span for line 4.
 // Ensure that the page URL was updated.
 assert-document-property: ({"URL": "lib.rs.html#4"}, ENDS_WITH)
 assert-attribute: ("//*[@id='4']", {"class": "line-highlighted"})
 // We now check that the good spans are highlighted
 goto: file://|DOC_PATH|/src/test_docs/lib.rs.html#4-6
-assert-attribute-false: (".line-numbers > span:nth-child(3)", {"class": "line-highlighted"})
-assert-attribute: (".line-numbers > span:nth-child(4)", {"class": "line-highlighted"})
-assert-attribute: (".line-numbers > span:nth-child(5)", {"class": "line-highlighted"})
-assert-attribute: (".line-numbers > span:nth-child(6)", {"class": "line-highlighted"})
-assert-attribute-false: (".line-numbers > span:nth-child(7)", {"class": "line-highlighted"})
+assert-attribute-false: (".src-line-numbers > span:nth-child(3)", {"class": "line-highlighted"})
+assert-attribute: (".src-line-numbers > span:nth-child(4)", {"class": "line-highlighted"})
+assert-attribute: (".src-line-numbers > span:nth-child(5)", {"class": "line-highlighted"})
+assert-attribute: (".src-line-numbers > span:nth-child(6)", {"class": "line-highlighted"})
+assert-attribute-false: (".src-line-numbers > span:nth-child(7)", {"class": "line-highlighted"})
 // This is to ensure that the content is correctly align with the line numbers.
 compare-elements-position: ("//*[@id='1']", ".rust > code > span", ("y"))
 
 // Assert that the line numbers text is aligned to the right.
-assert-css: (".line-numbers", {"text-align": "right"})
+assert-css: (".src-line-numbers", {"text-align": "right"})
 
 // Now let's check that clicking on something else than the line number doesn't
 // do anything (and certainly not add a `#NaN` to the URL!).
@@ -24,7 +24,7 @@ show-text: true
 goto: file://|DOC_PATH|/src/test_docs/lib.rs.html
 // We use this assert-position to know where we will click.
 assert-position: ("//*[@id='1']", {"x": 104, "y": 103})
-// We click on the left of the "1" span but still in the "line-number" `
`.
+// We click on the left of the "1" span but still in the "src-line-number" `
`.
 click: (103, 103)
 assert-document-property: ({"URL": "/lib.rs.html"}, ENDS_WITH)
 

From 9ca2ae3fa74c0598d0b0dfe6e84cae7b39913539 Mon Sep 17 00:00:00 2001
From: Michael Howell 
Date: Mon, 26 Sep 2022 12:21:27 -0700
Subject: [PATCH 7/7] rustdoc: simplify example-line-numbers CSS selector

---
 src/librustdoc/html/static/css/rustdoc.css      | 2 +-
 src/librustdoc/html/static/css/themes/ayu.css   | 2 +-
 src/librustdoc/html/static/css/themes/dark.css  | 2 +-
 src/librustdoc/html/static/css/themes/light.css | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css
index b4c7638b79841..a8c044ab69bd9 100644
--- a/src/librustdoc/html/static/css/rustdoc.css
+++ b/src/librustdoc/html/static/css/rustdoc.css
@@ -578,7 +578,7 @@ h2.location a {
 	position: relative;
 }
 
-.example-wrap > pre.example-line-numbers {
+pre.example-line-numbers {
 	overflow: initial;
 	border: 1px solid;
 	padding: 13px 8px;
diff --git a/src/librustdoc/html/static/css/themes/ayu.css b/src/librustdoc/html/static/css/themes/ayu.css
index 34411ace6fd37..44238ca573dcd 100644
--- a/src/librustdoc/html/static/css/themes/ayu.css
+++ b/src/librustdoc/html/static/css/themes/ayu.css
@@ -190,7 +190,7 @@ pre.rust .attribute {
 	color: #e6e1cf;
 }
 
-.example-wrap > pre.example-line-numbers {
+pre.example-line-numbers {
 	color: #5c67736e;
 	border: none;
 }
diff --git a/src/librustdoc/html/static/css/themes/dark.css b/src/librustdoc/html/static/css/themes/dark.css
index 9978f5f91874c..858d836c03d5e 100644
--- a/src/librustdoc/html/static/css/themes/dark.css
+++ b/src/librustdoc/html/static/css/themes/dark.css
@@ -155,7 +155,7 @@ pre.rust .question-mark {
 	color: #ff9011;
 }
 
-.example-wrap > pre.example-line-numbers {
+pre.example-line-numbers {
 	border-color: #4a4949;
 }
 
diff --git a/src/librustdoc/html/static/css/themes/light.css b/src/librustdoc/html/static/css/themes/light.css
index 377aca7b3a79f..6fbea6f6c7a5d 100644
--- a/src/librustdoc/html/static/css/themes/light.css
+++ b/src/librustdoc/html/static/css/themes/light.css
@@ -141,7 +141,7 @@ pre.rust .question-mark {
 	color: #ff9011;
 }
 
-.example-wrap > pre.example-line-numbers {
+pre.example-line-numbers {
 	border-color: #c7c7c7;
 }