From 07bb2f701e5bae0da724068bbce1920458df9cda Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Thu, 27 Oct 2022 11:16:30 -0700 Subject: [PATCH 01/10] rustdoc: change `.src-line-numbers > span` to `.src-line-numbers > a` This allows people to treat them like real links, such as right-click to copy URL, and makes the line numbers in a scraped example work at all, when before this commit was added, they had the clickable pointer cursor but did not actually do anything when clicked. --- src/librustdoc/html/render/mod.rs | 11 +++--- src/librustdoc/html/sources.rs | 21 +++++----- src/librustdoc/html/static/css/rustdoc.css | 5 +-- .../html/static/js/source-script.js | 11 ++++-- src/test/rustdoc-gui/source-code-page.goml | 39 ++++++++++++++----- .../rustdoc/check-source-code-urls-to-def.rs | 32 +++++++-------- 6 files changed, 72 insertions(+), 47 deletions(-) diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 27dea8ec0b312..e09106077f7ed 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -2888,9 +2888,6 @@ fn render_call_locations(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Ite })() .unwrap_or(rustc_span::DUMMY_SP); - // The root path is the inverse of Context::current - let root_path = vec!["../"; cx.current.len() - 1].join(""); - let mut decoration_info = FxHashMap::default(); decoration_info.insert("highlight focus", vec![byte_ranges.remove(0)]); decoration_info.insert("highlight", byte_ranges); @@ -2900,9 +2897,13 @@ fn render_call_locations(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Ite contents_subset, file_span, cx, - &root_path, + &cx.root_path(), highlight::DecorationInfo(decoration_info), - sources::SourceContext::Embedded { offset: line_min, needs_expansion }, + sources::SourceContext::Embedded { + url: &call_data.url, + offset: line_min, + needs_expansion, + }, ); write!(w, ""); diff --git a/src/librustdoc/html/sources.rs b/src/librustdoc/html/sources.rs index 8a01c01049d6e..99b4678c4577f 100644 --- a/src/librustdoc/html/sources.rs +++ b/src/librustdoc/html/sources.rs @@ -256,9 +256,9 @@ where } } -pub(crate) enum SourceContext { +pub(crate) enum SourceContext<'a> { Standalone, - Embedded { offset: usize, needs_expansion: bool }, + Embedded { url: &'a str, offset: usize, needs_expansion: bool }, } /// Wrapper struct to render the source code of a file. This will do things like @@ -270,31 +270,32 @@ pub(crate) fn print_src( context: &Context<'_>, root_path: &str, decoration_info: highlight::DecorationInfo, - source_context: SourceContext, + source_context: SourceContext<'_>, ) { let lines = s.lines().count(); let mut line_numbers = Buffer::empty_from(buf); let extra; line_numbers.write_str("
");
+    let current_href = &context
+        .href_from_span(clean::Span::new(file_span), false)
+        .expect("only local crates should have sources emitted");
     match source_context {
         SourceContext::Standalone => {
             extra = None;
             for line in 1..=lines {
-                writeln!(line_numbers, "{0}", line)
+                writeln!(line_numbers, "{line}")
             }
         }
-        SourceContext::Embedded { offset, needs_expansion } => {
+        SourceContext::Embedded { url, offset, needs_expansion } => {
             extra =
                 if needs_expansion { Some(r#""#) } else { None };
-            for line in 1..=lines {
-                writeln!(line_numbers, "{0}", line + offset)
+            for line_number in 1..=lines {
+                let line = line_number + offset;
+                writeln!(line_numbers, "{line}")
             }
         }
     }
     line_numbers.write_str("
"); - let current_href = &context - .href_from_span(clean::Span::new(file_span), false) - .expect("only local crates should have sources emitted"); highlight::render_source_with_highlighting( s, buf, diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 894499e5c4fc9..df7b6e9b99a4e 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -575,8 +575,7 @@ ul.block, .block li { border-color: var(--example-line-numbers-border-color); } -.src-line-numbers span { - cursor: pointer; +.src-line-numbers a { color: var(--src-line-numbers-span-color); } .src-line-numbers .line-highlighted { @@ -2060,7 +2059,7 @@ in storage.js padding: 14px 0; } -.scraped-example .code-wrapper .src-line-numbers span { +.scraped-example .code-wrapper .src-line-numbers a { padding: 0 14px; } diff --git a/src/librustdoc/html/static/js/source-script.js b/src/librustdoc/html/static/js/source-script.js index 0b9368dd89948..5db768c1c5753 100644 --- a/src/librustdoc/html/static/js/source-script.js +++ b/src/librustdoc/html/static/js/source-script.js @@ -157,7 +157,7 @@ function highlightSourceLines(match) { x.scrollIntoView(); } onEachLazy(document.getElementsByClassName("src-line-numbers"), e => { - onEachLazy(e.getElementsByTagName("span"), i_e => { + onEachLazy(e.getElementsByTagName("a"), i_e => { removeClass(i_e, "line-highlighted"); }); }); @@ -188,8 +188,13 @@ const handleSourceHighlight = (function() { return ev => { let cur_line_id = parseInt(ev.target.id, 10); - // It can happen when clicking not on a line number span. - if (isNaN(cur_line_id)) { + // This event handler is attached to the entire line number column, but it should only + // be run if one of the anchors is clicked. It also shouldn't do anything if the anchor + // is clicked with a modifier key (to open a new browser tab). + if (isNaN(cur_line_id) || + ev.ctrlKey || + ev.altKey || + ev.metaKey) { return; } ev.preventDefault(); diff --git a/src/test/rustdoc-gui/source-code-page.goml b/src/test/rustdoc-gui/source-code-page.goml index a2dac2aa681d5..31d55cd7885d3 100644 --- a/src/test/rustdoc-gui/source-code-page.goml +++ b/src/test/rustdoc-gui/source-code-page.goml @@ -2,17 +2,17 @@ goto: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html" show-text: true // Check that we can click on the line number. -click: ".src-line-numbers > span:nth-child(4)" // This is the span for line 4. +click: ".src-line-numbers > a:nth-child(4)" // This is the anchor 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 +// We now check that the good anchors are highlighted goto: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html#4-6" -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"}) +assert-attribute-false: (".src-line-numbers > a:nth-child(3)", {"class": "line-highlighted"}) +assert-attribute: (".src-line-numbers > a:nth-child(4)", {"class": "line-highlighted"}) +assert-attribute: (".src-line-numbers > a:nth-child(5)", {"class": "line-highlighted"}) +assert-attribute: (".src-line-numbers > a:nth-child(6)", {"class": "line-highlighted"}) +assert-attribute-false: (".src-line-numbers > a:nth-child(7)", {"class": "line-highlighted"}) define-function: ( "check-colors", @@ -21,12 +21,12 @@ define-function: ( ("local-storage", {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"}), ("reload"), ("assert-css", ( - ".src-line-numbers > span:not(.line-highlighted)", + ".src-line-numbers > a:not(.line-highlighted)", {"color": |color|, "background-color": |background_color|}, ALL, )), ("assert-css", ( - ".src-line-numbers > span.line-highlighted", + ".src-line-numbers > a.line-highlighted", {"color": |highlight_color|, "background-color": |highlight_background_color|}, ALL, )), @@ -57,6 +57,25 @@ call-function: ("check-colors", { // This is to ensure that the content is correctly align with the line numbers. compare-elements-position: ("//*[@id='1']", ".rust > code > span", ("y")) +// Check the `href` property so that users can treat anchors as links. +assert-property: (".src-line-numbers > a:nth-child(1)", { + "href": "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html#1" +}) +assert-property: (".src-line-numbers > a:nth-child(2)", { + "href": "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html#2" +}) +assert-property: (".src-line-numbers > a:nth-child(3)", { + "href": "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html#3" +}) +assert-property: (".src-line-numbers > a:nth-child(4)", { + "href": "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html#4" +}) +assert-property: (".src-line-numbers > a:nth-child(5)", { + "href": "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html#5" +}) +assert-property: (".src-line-numbers > a:nth-child(6)", { + "href": "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html#6" +}) // Assert that the line numbers text is aligned to the right. assert-css: (".src-line-numbers", {"text-align": "right"}) @@ -66,7 +85,7 @@ assert-css: (".src-line-numbers", {"text-align": "right"}) 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": 112}) -// We click on the left of the "1" span but still in the "src-line-number" `
`.
+// We click on the left of the "1" anchor but still in the "src-line-number" `
`.
 click: (103, 103)
 assert-document-property: ({"URL": "/lib.rs.html"}, ENDS_WITH)
 
diff --git a/src/test/rustdoc/check-source-code-urls-to-def.rs b/src/test/rustdoc/check-source-code-urls-to-def.rs
index d00a3e3551991..5959f9c7c5992 100644
--- a/src/test/rustdoc/check-source-code-urls-to-def.rs
+++ b/src/test/rustdoc/check-source-code-urls-to-def.rs
@@ -10,14 +10,14 @@ extern crate source_code;
 
 // @has 'src/foo/check-source-code-urls-to-def.rs.html'
 
-// @has - '//a[@href="auxiliary/source-code-bar.rs.html#1-17"]' 'bar'
+// @has - '//pre[@class="rust"]//a[@href="auxiliary/source-code-bar.rs.html#1-17"]' 'bar'
 #[path = "auxiliary/source-code-bar.rs"]
 pub mod bar;
 
-// @count - '//a[@href="auxiliary/source-code-bar.rs.html#5"]' 4
+// @count - '//pre[@class="rust"]//a[@href="auxiliary/source-code-bar.rs.html#5"]' 4
 use bar::Bar;
-// @has - '//a[@href="auxiliary/source-code-bar.rs.html#13"]' 'self'
-// @has - '//a[@href="auxiliary/source-code-bar.rs.html#14"]' 'Trait'
+// @has - '//pre[@class="rust"]//a[@href="auxiliary/source-code-bar.rs.html#13"]' 'self'
+// @has - '//pre[@class="rust"]//a[@href="auxiliary/source-code-bar.rs.html#14"]' 'Trait'
 use bar::sub::{self, Trait};
 
 pub struct Foo;
@@ -28,29 +28,29 @@ impl Foo {
 
 fn babar() {}
 
-// @has - '//a/@href' '/struct.String.html'
-// @has - '//a/@href' '/primitive.u32.html'
-// @has - '//a/@href' '/primitive.str.html'
-// @count - '//a[@href="#23"]' 5
-// @has - '//a[@href="../../source_code/struct.SourceCode.html"]' 'source_code::SourceCode'
+// @has - '//pre[@class="rust"]//a/@href' '/struct.String.html'
+// @has - '//pre[@class="rust"]//a/@href' '/primitive.u32.html'
+// @has - '//pre[@class="rust"]//a/@href' '/primitive.str.html'
+// @count - '//pre[@class="rust"]//a[@href="#23"]' 5
+// @has - '//pre[@class="rust"]//a[@href="../../source_code/struct.SourceCode.html"]' 'source_code::SourceCode'
 pub fn foo(a: u32, b: &str, c: String, d: Foo, e: bar::Bar, f: source_code::SourceCode) {
     let x = 12;
     let y: Foo = Foo;
     let z: Bar = bar::Bar { field: Foo };
     babar();
-    // @has - '//a[@href="#26"]' 'hello'
+    // @has - '//pre[@class="rust"]//a[@href="#26"]' 'hello'
     y.hello();
 }
 
-// @has - '//a[@href="auxiliary/source-code-bar.rs.html#14"]' 'bar::sub::Trait'
-// @has - '//a[@href="auxiliary/source-code-bar.rs.html#14"]' 'Trait'
+// @has - '//pre[@class="rust"]//a[@href="auxiliary/source-code-bar.rs.html#14"]' 'bar::sub::Trait'
+// @has - '//pre[@class="rust"]//a[@href="auxiliary/source-code-bar.rs.html#14"]' 'Trait'
 pub fn foo2(t: &T, v: &V, b: bool) {}
 
 pub trait AnotherTrait {}
 pub trait WhyNot {}
 
-// @has - '//a[@href="#49"]' 'AnotherTrait'
-// @has - '//a[@href="#50"]' 'WhyNot'
+// @has - '//pre[@class="rust"]//a[@href="#49"]' 'AnotherTrait'
+// @has - '//pre[@class="rust"]//a[@href="#50"]' 'WhyNot'
 pub fn foo3(t: &T, v: &V)
 where
     T: AnotherTrait,
@@ -59,11 +59,11 @@ where
 
 pub trait AnotherTrait2 {}
 
-// @has - '//a[@href="#60"]' 'AnotherTrait2'
+// @has - '//pre[@class="rust"]//a[@href="#60"]' 'AnotherTrait2'
 pub fn foo4() {
     let x: Vec = Vec::new();
 }
 
-// @has - '//a[@href="../../foo/primitive.bool.html"]' 'bool'
+// @has - '//pre[@class="rust"]//a[@href="../../foo/primitive.bool.html"]' 'bool'
 #[doc(primitive = "bool")]
 mod whatever {}

From ba4ae13528428cf770701ea5d9203cbf64b5a1cd Mon Sep 17 00:00:00 2001
From: Michael Howell 
Date: Fri, 28 Oct 2022 09:51:57 -0700
Subject: [PATCH 02/10] rustdoc: remove left border from `.src-line-numbers >
 a`

---
 src/librustdoc/html/static/css/rustdoc.css | 8 +++++---
 src/test/rustdoc-gui/source-code-page.goml | 5 +++++
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css
index df7b6e9b99a4e..b64fe74e960e3 100644
--- a/src/librustdoc/html/static/css/rustdoc.css
+++ b/src/librustdoc/html/static/css/rustdoc.css
@@ -578,11 +578,13 @@ ul.block, .block li {
 .src-line-numbers a {
 	color: var(--src-line-numbers-span-color);
 }
-.src-line-numbers .line-highlighted {
-	background-color: var(--src-line-number-highlighted-background-color);
-}
 .src-line-numbers :target {
 	background-color: transparent;
+	border-right: none;
+	padding-right: 0;
+}
+.src-line-numbers .line-highlighted {
+	background-color: var(--src-line-number-highlighted-background-color);
 }
 
 .search-loading {
diff --git a/src/test/rustdoc-gui/source-code-page.goml b/src/test/rustdoc-gui/source-code-page.goml
index 31d55cd7885d3..c71a3d64d0c8a 100644
--- a/src/test/rustdoc-gui/source-code-page.goml
+++ b/src/test/rustdoc-gui/source-code-page.goml
@@ -6,6 +6,11 @@ click: ".src-line-numbers > a:nth-child(4)" // This is the anchor 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"})
+// Ensure that the default style, with the right border, isn't used.
+assert-css: ("//*[@id='4']", {"border-right-width": "0px"})
+reload:
+assert-attribute: ("//*[@id='4']", {"class": "line-highlighted"})
+assert-css: ("//*[@id='4']", {"border-right-width": "0px"})
 // We now check that the good anchors are highlighted
 goto: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html#4-6"
 assert-attribute-false: (".src-line-numbers > a:nth-child(3)", {"class": "line-highlighted"})

From 89ba71649f59e402a0019828223a878c06f625b1 Mon Sep 17 00:00:00 2001
From: Michael Howell 
Date: Tue, 8 Nov 2022 18:00:22 -0700
Subject: [PATCH 03/10] rustdoc: use consistent "popover" styling for notable
 traits

---
 src/librustdoc/html/render/mod.rs             |  6 +-
 src/librustdoc/html/static/css/rustdoc.css    | 73 +++++--------------
 src/librustdoc/html/static/css/themes/ayu.css |  4 -
 .../html/static/css/themes/dark.css           |  4 -
 .../html/static/css/themes/light.css          |  4 -
 src/librustdoc/html/static/js/main.js         | 52 ++++++++++---
 src/test/rustdoc-gui/notable-trait.goml       | 61 +++++++---------
 7 files changed, 89 insertions(+), 115 deletions(-)

diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs
index 266ec2ac7ad73..75fdd6ade235f 100644
--- a/src/librustdoc/html/render/mod.rs
+++ b/src/librustdoc/html/render/mod.rs
@@ -1312,9 +1312,7 @@ pub(crate) fn notable_traits_button(ty: &clean::Type, cx: &mut Context<'_>) -> O
     if has_notable_trait {
         cx.types_with_notable_traits.insert(ty.clone());
         Some(format!(
-            "\
-                \
-            ",
+            " ",
             ty = Escape(&format!("{:#}", ty.print(cx))),
         ))
     } else {
@@ -1343,7 +1341,7 @@ fn notable_traits_decl(ty: &clean::Type, cx: &Context<'_>) -> (String, String) {
                 if out.is_empty() {
                     write!(
                         &mut out,
-                        "

Notable traits for {}

\ + "

Notable traits for {}

\
",
                         impl_.for_.print(cx)
                     );
diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css
index 6a068a3d243d9..1209187dc4817 100644
--- a/src/librustdoc/html/static/css/rustdoc.css
+++ b/src/librustdoc/html/static/css/rustdoc.css
@@ -183,8 +183,6 @@ h4.code-header {
 	font-weight: 600;
 	margin: 0;
 	padding: 0;
-	/* position notable traits in mobile mode within the header */
-	position: relative;
 }
 
 #crate-search,
@@ -930,13 +928,14 @@ so that we can apply CSS-filters to change the arrow color in themes */
 	border-radius: 3px;
 	border: 1px solid var(--border-color);
 	font-size: 1rem;
+	--popover-arrow-offset: 11px;
 }
 
 /* This rule is to draw the little arrow connecting the settings menu to the gear icon. */
 .popover::before {
 	content: '';
 	position: absolute;
-	right: 11px;
+	right: var(--popover-arrow-offset);
 	border: solid var(--border-color);
 	border-width: 1px 1px 0 0;
 	display: inline-block;
@@ -953,10 +952,7 @@ so that we can apply CSS-filters to change the arrow color in themes */
 /* use larger max-width for help popover, but not for help.html */
 #help.popover {
 	max-width: 600px;
-}
-
-#help.popover::before {
-	right: 48px;
+	--popover-arrow-offset: 48px;
 }
 
 #help dt {
@@ -1275,54 +1271,34 @@ h3.variant {
 	border-right: 3px solid var(--target-border-color);
 }
 
-.notable-traits-tooltip {
-	display: inline-block;
-	cursor: pointer;
-}
-
-.notable-traits .notable-traits-tooltiptext {
-	display: inline-block;
-	visibility: hidden;
+.notable-traits {
+	color: inherit;
+	margin-right: 15px;
+	position: relative;
 }
 
-.notable-traits-tooltiptext {
-	padding: 5px 3px 3px 3px;
-	border-radius: 6px;
-	margin-left: 5px;
-	z-index: 10;
-	font-size: 1rem;
-	cursor: default;
+/* placeholder thunk so that the mouse can easily travel from "(i)" to popover
+	the resulting "hover tunnel" is a stepped triangle, approximating
+	https://bjk5.com/post/44698559168/breaking-down-amazons-mega-dropdown */
+.notable-traits:hover::after {
 	position: absolute;
-	border: 1px solid;
-}
-
-.notable-traits-tooltip::after {
-	/* The margin on the tooltip does not capture hover events,
-	   this extends the area of hover enough so that mouse hover is not
-	   lost when moving the mouse to the tooltip */
-	content: "\00a0\00a0\00a0";
-}
-
-.notable-traits-tooltiptext .docblock {
-	margin: 0;
+	top: calc(100% - 10px);
+	left: -15px;
+	right: -15px;
+	height: 20px;
+	content: "\00a0";
 }
 
-.notable-traits-tooltiptext .notable {
-	font-size: 1.1875rem;
-	font-weight: 600;
-	display: block;
+.notable .docblock {
+	margin: 0.25em 0.5em;
 }
 
-.notable-traits-tooltiptext pre, .notable-traits-tooltiptext code {
+.notable .docblock pre, .notable .docblock code {
 	background: transparent;
-}
-
-.notable-traits-tooltiptext .docblock pre.content {
 	margin: 0;
 	padding: 0;
 	font-size: 1.25rem;
 	white-space: pre-wrap;
-	overflow: hidden;
 }
 
 .search-failed {
@@ -1365,12 +1341,6 @@ h3.variant {
 	font-size: 1rem;
 }
 
-.notable-traits {
-	cursor: pointer;
-	z-index: 2;
-	margin-left: 5px;
-}
-
 #sidebar-toggle {
 	position: sticky;
 	top: 0;
@@ -1855,11 +1825,6 @@ in storage.js
 		border-bottom: 1px solid;
 	}
 
-	.notable-traits .notable-traits-tooltiptext {
-		left: 0;
-		top: 100%;
-	}
-
 	/* We don't display the help button on mobile devices. */
 	#help-button {
 		display: none;
diff --git a/src/librustdoc/html/static/css/themes/ayu.css b/src/librustdoc/html/static/css/themes/ayu.css
index 2fa1fa39d63ab..eec3ce55e22f9 100644
--- a/src/librustdoc/html/static/css/themes/ayu.css
+++ b/src/librustdoc/html/static/css/themes/ayu.css
@@ -183,10 +183,6 @@ details.rustdoc-toggle > summary::before {
 	border-color: transparent #314559 transparent transparent;
 }
 
-.notable-traits-tooltiptext {
-	background-color: #314559;
-}
-
 #titles > button.selected {
 	background-color: #141920 !important;
 	border-bottom: 1px solid #ffb44c !important;
diff --git a/src/librustdoc/html/static/css/themes/dark.css b/src/librustdoc/html/static/css/themes/dark.css
index 43f8dd42ab347..a93d9d6790a17 100644
--- a/src/librustdoc/html/static/css/themes/dark.css
+++ b/src/librustdoc/html/static/css/themes/dark.css
@@ -106,10 +106,6 @@ details.rustdoc-toggle > summary::before {
 	border-color: transparent black transparent transparent;
 }
 
-.notable-traits-tooltiptext {
-	background-color: #111;
-}
-
 #titles > button:not(.selected) {
 	background-color: #252525;
 	border-top-color: #252525;
diff --git a/src/librustdoc/html/static/css/themes/light.css b/src/librustdoc/html/static/css/themes/light.css
index c8c5289ab540c..e69ae5abbc393 100644
--- a/src/librustdoc/html/static/css/themes/light.css
+++ b/src/librustdoc/html/static/css/themes/light.css
@@ -98,10 +98,6 @@ body.source .example-wrap pre.rust a {
 	border-color: transparent black transparent transparent;
 }
 
-.notable-traits-tooltiptext {
-	background-color: #eee;
-}
-
 #titles > button:not(.selected) {
 	background-color: #e6e6e6;
 	border-top-color: #e6e6e6;
diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js
index 0426774e80d46..b670ea3f0201d 100644
--- a/src/librustdoc/html/static/js/main.js
+++ b/src/librustdoc/html/static/js/main.js
@@ -850,18 +850,33 @@ function loadCss(cssUrl) {
         }
         hideNotable();
         const ty = e.getAttribute("data-ty");
-        const tooltip = e.getElementsByClassName("notable-traits-tooltip")[0];
         const wrapper = document.createElement("div");
         wrapper.innerHTML = "
" + window.NOTABLE_TRAITS[ty] + "
"; - wrapper.className = "notable-traits-tooltiptext"; - tooltip.appendChild(wrapper); - const pos = wrapper.getBoundingClientRect(); - tooltip.removeChild(wrapper); - wrapper.style.top = (pos.top + window.scrollY) + "px"; - wrapper.style.left = (pos.left + window.scrollX) + "px"; - wrapper.style.width = pos.width + "px"; + wrapper.className = "notable popover"; + const focusCatcher = document.createElement("div"); + focusCatcher.setAttribute("tabindex", "0"); + focusCatcher.onfocus = hideNotable; + wrapper.appendChild(focusCatcher); + const pos = e.getBoundingClientRect(); + // 5px overlap so that the mouse can easily travel from place to place + wrapper.style.top = (pos.top + window.scrollY + pos.height) + "px"; + wrapper.style.left = 0; + wrapper.style.right = "auto"; + wrapper.style.visibility = "hidden"; const body = document.getElementsByTagName("body")[0]; body.appendChild(wrapper); + const wrapperPos = wrapper.getBoundingClientRect(); + // offset so that the arrow points at the center of the "(i)" + const finalPos = pos.left + window.scrollX - wrapperPos.width + 24; + if (finalPos > 0) { + wrapper.style.left = finalPos + "px"; + } else { + wrapper.style.setProperty( + "--popover-arrow-offset", + (wrapperPos.right - pos.right + 4) + "px" + ); + } + wrapper.style.visibility = ""; window.CURRENT_NOTABLE_ELEMENT = wrapper; window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE = e; wrapper.onpointerleave = function(ev) { @@ -875,9 +890,23 @@ function loadCss(cssUrl) { }; } + function notableBlurHandler(event) { + if (window.CURRENT_NOTABLE_ELEMENT && + !elemIsInParent(document.activeElement, window.CURRENT_NOTABLE_ELEMENT) && + !elemIsInParent(event.relatedTarget, window.CURRENT_NOTABLE_ELEMENT) && + !elemIsInParent(document.activeElement, window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE) && + !elemIsInParent(event.relatedTarget, window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE) + ) { + hideNotable(); + } + } + function hideNotable() { if (window.CURRENT_NOTABLE_ELEMENT) { - window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE.NOTABLE_FORCE_VISIBLE = false; + if (window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE.NOTABLE_FORCE_VISIBLE) { + window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE.focus(); + window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE.NOTABLE_FORCE_VISIBLE = false; + } const body = document.getElementsByTagName("body")[0]; body.removeChild(window.CURRENT_NOTABLE_ELEMENT); window.CURRENT_NOTABLE_ELEMENT = null; @@ -891,7 +920,11 @@ function loadCss(cssUrl) { hideNotable(); } else { showNotable(this); + window.CURRENT_NOTABLE_ELEMENT.setAttribute("tabindex", "0"); + window.CURRENT_NOTABLE_ELEMENT.focus(); + window.CURRENT_NOTABLE_ELEMENT.onblur = notableBlurHandler; } + return false; }; e.onpointerenter = function(ev) { // If this is a synthetic touch event, ignore it. A click event will be along shortly. @@ -1018,6 +1051,7 @@ function loadCss(cssUrl) { onEachLazy(document.querySelectorAll(".search-form .popover"), elem => { elem.style.display = "none"; }); + hideNotable(); }; /** diff --git a/src/test/rustdoc-gui/notable-trait.goml b/src/test/rustdoc-gui/notable-trait.goml index d8261d8dc902c..3bc1c5365e9e1 100644 --- a/src/test/rustdoc-gui/notable-trait.goml +++ b/src/test/rustdoc-gui/notable-trait.goml @@ -22,31 +22,26 @@ assert-position: ( ) assert-position: ( "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']", - {"x": 951}, + {"x": 955}, ) -// The tooltip should be beside the `i` +// The tooltip should be below the `i` // Also, clicking the tooltip should bring its text into the DOM -assert-count: ("//*[@class='notable-traits-tooltiptext']", 0) +assert-count: ("//*[@class='notable popover']", 0) click: "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']" -assert-count: ("//*[@class='notable-traits-tooltiptext']", 1) +assert-count: ("//*[@class='notable popover']", 1) compare-elements-position-near: ( "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']", - "//*[@class='notable-traits-tooltiptext']", - {"y": 2} + "//*[@class='notable popover']", + {"y": 30} ) compare-elements-position-false: ( "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']", - "//*[@class='notable-traits-tooltiptext']", + "//*[@class='notable popover']", ("x") ) -// The docblock should be flush with the border. -assert-css: ( - "//*[@class='notable-traits-tooltiptext']/*[@class='docblock']", - {"margin-left": "0px"} -) click: "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']" move-cursor-to: "//h1" -assert-count: ("//*[@class='notable-traits-tooltiptext']", 0) +assert-count: ("//*[@class='notable popover']", 0) // Now only the `i` should be on the next line. size: (1055, 600) @@ -77,7 +72,7 @@ assert-position: ( ) assert-position: ( "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']", - {"x": 519}, + {"x": 523}, ) // Checking on mobile now. @@ -101,34 +96,28 @@ assert-position: ( ) assert-position: ( "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']", - {"x": 289}, + {"x": 293}, ) -// The tooltip should be below `i` +// The tooltip should STILL be below `i` click: "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']" -assert-count: ("//*[@class='notable-traits-tooltiptext']", 1) -compare-elements-position-near-false: ( +assert-count: ("//*[@class='notable popover']", 1) +compare-elements-position-near: ( "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']", - "//*[@class='notable-traits-tooltiptext']", - {"y": 2} + "//*[@class='notable popover']", + {"y": 30} ) compare-elements-position-false: ( "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']", - "//*[@class='notable-traits-tooltiptext']", + "//*[@class='notable popover']", ("x") ) -compare-elements-position-near: ( - "//*[@id='method.create_an_iterator_from_read']", - "//*[@class='notable-traits-tooltiptext']", - {"x": 10} -) -// The docblock should be flush with the border. -assert-css: ( - "//*[@class='notable-traits-tooltiptext']/*[@class='docblock']", - {"margin-left": "0px"} +assert-position: ( + "//*[@class='notable popover']", + {"x": 0} ) click: "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']" move-cursor-to: "//h1" -assert-count: ("//*[@class='notable-traits-tooltiptext']", 0) +assert-count: ("//*[@class='notable popover']", 0) // Checking on very small mobile. The `i` should be on its own line. size: (365, 600) @@ -153,25 +142,25 @@ define-function: ( ("reload"), ("move-cursor-to", "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']"), - ("assert-count", (".notable-traits-tooltiptext", 1)), + ("assert-count", (".notable.popover", 1)), ("assert-css", ( - ".notable-traits-tooltiptext h3.notable", + ".notable.popover h3", {"color": |header_color|}, ALL, )), ("assert-css", ( - ".notable-traits-tooltiptext pre.content", + ".notable.popover pre", {"color": |content_color|}, ALL, )), ("assert-css", ( - ".notable-traits-tooltiptext pre.content a.struct", + ".notable.popover pre a.struct", {"color": |type_color|}, ALL, )), ("assert-css", ( - ".notable-traits-tooltiptext pre.content a.trait", + ".notable.popover pre a.trait", {"color": |trait_color|}, ALL, )), From 155750dc330d0a2148cff7efadd75d821854e947 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Tue, 8 Nov 2022 17:59:03 -0700 Subject: [PATCH 04/10] rustdoc: make notable traits popover behavior consistent with Help and Settings --- src/librustdoc/html/static/js/main.js | 10 ++++++++- src/test/rustdoc-gui/notable-trait.goml | 28 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js index b670ea3f0201d..0538762e44d03 100644 --- a/src/librustdoc/html/static/js/main.js +++ b/src/librustdoc/html/static/js/main.js @@ -897,7 +897,15 @@ function loadCss(cssUrl) { !elemIsInParent(document.activeElement, window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE) && !elemIsInParent(event.relatedTarget, window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE) ) { - hideNotable(); + // Work around a difference in the focus behaviour between Firefox, Chrome, and Safari. + // When I click the button on an already-opened notable trait popover, Safari + // hides the popover and then immediately shows it again, while everyone else hides it + // and it stays hidden. + // + // To work around this, make sure the click finishes being dispatched before + // hiding the popover. Since `hideNotable()` is idempotent, this makes Safari behave + // consistently with the other two. + setTimeout(hideNotable, 0); } } diff --git a/src/test/rustdoc-gui/notable-trait.goml b/src/test/rustdoc-gui/notable-trait.goml index 3bc1c5365e9e1..0b97cbae4991d 100644 --- a/src/test/rustdoc-gui/notable-trait.goml +++ b/src/test/rustdoc-gui/notable-trait.goml @@ -199,3 +199,31 @@ call-function: ( "trait_color": "rgb(110, 79, 201)", }, ) + +reload: + +// Check that pressing escape works +click: "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']" +move-cursor-to: "//*[@class='notable popover']" +assert-count: ("//*[@class='notable popover']", 1) +press-key: "Escape" +assert-count: ("//*[@class='notable popover']", 0) + +// Check that clicking outside works. +click: "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']" +assert-count: ("//*[@class='notable popover']", 1) +click: ".search-input" +assert-count: ("//*[@class='notable popover']", 0) + +// Check that pressing tab over and over works. +click: "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']" +move-cursor-to: "//*[@class='notable popover']" +assert-count: ("//*[@class='notable popover']", 1) +press-key: "Tab" +press-key: "Tab" +press-key: "Tab" +press-key: "Tab" +press-key: "Tab" +press-key: "Tab" +press-key: "Tab" +assert-count: ("//*[@class='notable popover']", 0) From 79b6112ab53a9f5cd2b267dfbdb8bcae7049b2f7 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Tue, 8 Nov 2022 17:49:29 -0700 Subject: [PATCH 05/10] rustdoc: update test cases --- src/test/rustdoc-gui/notable-trait.goml | 8 -------- .../rustdoc/doc-notable_trait-slice.bare_fn_matches.html | 2 +- src/test/rustdoc/doc-notable_trait.bare-fn.html | 2 +- src/test/rustdoc/doc-notable_trait.rs | 6 +++--- src/test/rustdoc/doc-notable_trait.some-struct-new.html | 2 +- src/test/rustdoc/doc-notable_trait.wrap-me.html | 2 +- src/test/rustdoc/spotlight-from-dependency.odd.html | 2 +- src/test/rustdoc/spotlight-from-dependency.rs | 2 +- 8 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/test/rustdoc-gui/notable-trait.goml b/src/test/rustdoc-gui/notable-trait.goml index 0b97cbae4991d..4c3943d885830 100644 --- a/src/test/rustdoc-gui/notable-trait.goml +++ b/src/test/rustdoc-gui/notable-trait.goml @@ -119,14 +119,6 @@ click: "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits move-cursor-to: "//h1" assert-count: ("//*[@class='notable popover']", 0) -// Checking on very small mobile. The `i` should be on its own line. -size: (365, 600) -compare-elements-position-false: ( - "//*[@id='method.create_an_iterator_from_read']//a[text()='NotableStructWithLongName']", - "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']", - ("y", "x"), -) - // Now check the colors. define-function: ( "check-colors", diff --git a/src/test/rustdoc/doc-notable_trait-slice.bare_fn_matches.html b/src/test/rustdoc/doc-notable_trait-slice.bare_fn_matches.html index 6b58be7e6853e..f2ec8320a0525 100644 --- a/src/test/rustdoc/doc-notable_trait-slice.bare_fn_matches.html +++ b/src/test/rustdoc/doc-notable_trait-slice.bare_fn_matches.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/src/test/rustdoc/doc-notable_trait.bare-fn.html b/src/test/rustdoc/doc-notable_trait.bare-fn.html index 4e4a3f18f2498..b426a4d7a8b7b 100644 --- a/src/test/rustdoc/doc-notable_trait.bare-fn.html +++ b/src/test/rustdoc/doc-notable_trait.bare-fn.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/src/test/rustdoc/doc-notable_trait.rs b/src/test/rustdoc/doc-notable_trait.rs index 1f2cd7181c3d4..279faf5540140 100644 --- a/src/test/rustdoc/doc-notable_trait.rs +++ b/src/test/rustdoc/doc-notable_trait.rs @@ -9,7 +9,7 @@ impl SomeTrait for Wrapper {} #[doc(notable_trait)] pub trait SomeTrait { // @has doc_notable_trait/trait.SomeTrait.html - // @has - '//span[@class="notable-traits"]/@data-ty' 'Wrapper' + // @has - '//a[@class="notable-traits"]/@data-ty' 'Wrapper' // @snapshot wrap-me - '//script[@id="notable-traits-data"]' fn wrap_me(self) -> Wrapper where Self: Sized { Wrapper { @@ -23,7 +23,7 @@ impl SomeTrait for SomeStruct {} impl SomeStruct { // @has doc_notable_trait/struct.SomeStruct.html - // @has - '//span[@class="notable-traits"]/@data-ty' 'SomeStruct' + // @has - '//a[@class="notable-traits"]/@data-ty' 'SomeStruct' // @snapshot some-struct-new - '//script[@id="notable-traits-data"]' pub fn new() -> SomeStruct { SomeStruct @@ -31,7 +31,7 @@ impl SomeStruct { } // @has doc_notable_trait/fn.bare_fn.html -// @has - '//span[@class="notable-traits"]/@data-ty' 'SomeStruct' +// @has - '//a[@class="notable-traits"]/@data-ty' 'SomeStruct' // @snapshot bare-fn - '//script[@id="notable-traits-data"]' pub fn bare_fn() -> SomeStruct { SomeStruct diff --git a/src/test/rustdoc/doc-notable_trait.some-struct-new.html b/src/test/rustdoc/doc-notable_trait.some-struct-new.html index c0fd9748fd371..4f8063807e67d 100644 --- a/src/test/rustdoc/doc-notable_trait.some-struct-new.html +++ b/src/test/rustdoc/doc-notable_trait.some-struct-new.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/src/test/rustdoc/doc-notable_trait.wrap-me.html b/src/test/rustdoc/doc-notable_trait.wrap-me.html index 9a59d5edd12a8..bed2a38b24a2b 100644 --- a/src/test/rustdoc/doc-notable_trait.wrap-me.html +++ b/src/test/rustdoc/doc-notable_trait.wrap-me.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/src/test/rustdoc/spotlight-from-dependency.odd.html b/src/test/rustdoc/spotlight-from-dependency.odd.html index 987a949af44b1..1d02c13ebfb3c 100644 --- a/src/test/rustdoc/spotlight-from-dependency.odd.html +++ b/src/test/rustdoc/spotlight-from-dependency.odd.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/src/test/rustdoc/spotlight-from-dependency.rs b/src/test/rustdoc/spotlight-from-dependency.rs index 156aedca62b4e..090ad187d9cc0 100644 --- a/src/test/rustdoc/spotlight-from-dependency.rs +++ b/src/test/rustdoc/spotlight-from-dependency.rs @@ -3,7 +3,7 @@ use std::iter::Iterator; // @has foo/struct.Odd.html -// @has - '//*[@id="method.new"]//span[@class="notable-traits"]/@data-ty' 'Odd' +// @has - '//*[@id="method.new"]//a[@class="notable-traits"]/@data-ty' 'Odd' // @snapshot odd - '//script[@id="notable-traits-data"]' pub struct Odd { current: usize, From e66de455197cba33f788832a245b04e1064061db Mon Sep 17 00:00:00 2001 From: Caio Date: Sat, 12 Nov 2022 09:51:53 -0300 Subject: [PATCH 06/10] Move tests --- src/test/ui/{issues => enum-discriminant}/issue-46519.rs | 0 .../issue-36139-normalize-closure-sig.rs | 0 src/test/ui/{issues => higher-rank-trait-bounds}/issue-43623.rs | 0 src/test/ui/{issues => pattern}/issue-52240.rs | 0 src/test/ui/{issues => pattern}/issue-52240.stderr | 0 src/test/ui/{issues => privacy}/auxiliary/issue-75907.rs | 0 src/test/ui/{issues => privacy}/issue-75907.rs | 0 src/test/ui/{issues => privacy}/issue-75907.stderr | 0 src/test/ui/{issues => privacy}/issue-75907_b.rs | 0 src/test/ui/{issues => privacy}/issue-75907_b.stderr | 0 src/test/ui/{issues => regions}/issue-11612.rs | 0 src/test/ui/{issues => resolve}/issue-35675.rs | 0 src/test/ui/{issues => resolve}/issue-35675.stderr | 0 src/test/ui/{issues => resolve}/issue-5927.rs | 0 src/test/ui/{issues => resolve}/issue-5927.stderr | 0 src/test/ui/{issues => static}/issue-5216.rs | 0 src/test/ui/{issues => static}/issue-5216.stderr | 0 src/test/ui/{issues => traits}/issue-7013.rs | 0 src/test/ui/{issues => traits}/issue-7013.stderr | 0 19 files changed, 0 insertions(+), 0 deletions(-) rename src/test/ui/{issues => enum-discriminant}/issue-46519.rs (100%) rename src/test/ui/{issues => higher-rank-trait-bounds}/issue-36139-normalize-closure-sig.rs (100%) rename src/test/ui/{issues => higher-rank-trait-bounds}/issue-43623.rs (100%) rename src/test/ui/{issues => pattern}/issue-52240.rs (100%) rename src/test/ui/{issues => pattern}/issue-52240.stderr (100%) rename src/test/ui/{issues => privacy}/auxiliary/issue-75907.rs (100%) rename src/test/ui/{issues => privacy}/issue-75907.rs (100%) rename src/test/ui/{issues => privacy}/issue-75907.stderr (100%) rename src/test/ui/{issues => privacy}/issue-75907_b.rs (100%) rename src/test/ui/{issues => privacy}/issue-75907_b.stderr (100%) rename src/test/ui/{issues => regions}/issue-11612.rs (100%) rename src/test/ui/{issues => resolve}/issue-35675.rs (100%) rename src/test/ui/{issues => resolve}/issue-35675.stderr (100%) rename src/test/ui/{issues => resolve}/issue-5927.rs (100%) rename src/test/ui/{issues => resolve}/issue-5927.stderr (100%) rename src/test/ui/{issues => static}/issue-5216.rs (100%) rename src/test/ui/{issues => static}/issue-5216.stderr (100%) rename src/test/ui/{issues => traits}/issue-7013.rs (100%) rename src/test/ui/{issues => traits}/issue-7013.stderr (100%) diff --git a/src/test/ui/issues/issue-46519.rs b/src/test/ui/enum-discriminant/issue-46519.rs similarity index 100% rename from src/test/ui/issues/issue-46519.rs rename to src/test/ui/enum-discriminant/issue-46519.rs diff --git a/src/test/ui/issues/issue-36139-normalize-closure-sig.rs b/src/test/ui/higher-rank-trait-bounds/issue-36139-normalize-closure-sig.rs similarity index 100% rename from src/test/ui/issues/issue-36139-normalize-closure-sig.rs rename to src/test/ui/higher-rank-trait-bounds/issue-36139-normalize-closure-sig.rs diff --git a/src/test/ui/issues/issue-43623.rs b/src/test/ui/higher-rank-trait-bounds/issue-43623.rs similarity index 100% rename from src/test/ui/issues/issue-43623.rs rename to src/test/ui/higher-rank-trait-bounds/issue-43623.rs diff --git a/src/test/ui/issues/issue-52240.rs b/src/test/ui/pattern/issue-52240.rs similarity index 100% rename from src/test/ui/issues/issue-52240.rs rename to src/test/ui/pattern/issue-52240.rs diff --git a/src/test/ui/issues/issue-52240.stderr b/src/test/ui/pattern/issue-52240.stderr similarity index 100% rename from src/test/ui/issues/issue-52240.stderr rename to src/test/ui/pattern/issue-52240.stderr diff --git a/src/test/ui/issues/auxiliary/issue-75907.rs b/src/test/ui/privacy/auxiliary/issue-75907.rs similarity index 100% rename from src/test/ui/issues/auxiliary/issue-75907.rs rename to src/test/ui/privacy/auxiliary/issue-75907.rs diff --git a/src/test/ui/issues/issue-75907.rs b/src/test/ui/privacy/issue-75907.rs similarity index 100% rename from src/test/ui/issues/issue-75907.rs rename to src/test/ui/privacy/issue-75907.rs diff --git a/src/test/ui/issues/issue-75907.stderr b/src/test/ui/privacy/issue-75907.stderr similarity index 100% rename from src/test/ui/issues/issue-75907.stderr rename to src/test/ui/privacy/issue-75907.stderr diff --git a/src/test/ui/issues/issue-75907_b.rs b/src/test/ui/privacy/issue-75907_b.rs similarity index 100% rename from src/test/ui/issues/issue-75907_b.rs rename to src/test/ui/privacy/issue-75907_b.rs diff --git a/src/test/ui/issues/issue-75907_b.stderr b/src/test/ui/privacy/issue-75907_b.stderr similarity index 100% rename from src/test/ui/issues/issue-75907_b.stderr rename to src/test/ui/privacy/issue-75907_b.stderr diff --git a/src/test/ui/issues/issue-11612.rs b/src/test/ui/regions/issue-11612.rs similarity index 100% rename from src/test/ui/issues/issue-11612.rs rename to src/test/ui/regions/issue-11612.rs diff --git a/src/test/ui/issues/issue-35675.rs b/src/test/ui/resolve/issue-35675.rs similarity index 100% rename from src/test/ui/issues/issue-35675.rs rename to src/test/ui/resolve/issue-35675.rs diff --git a/src/test/ui/issues/issue-35675.stderr b/src/test/ui/resolve/issue-35675.stderr similarity index 100% rename from src/test/ui/issues/issue-35675.stderr rename to src/test/ui/resolve/issue-35675.stderr diff --git a/src/test/ui/issues/issue-5927.rs b/src/test/ui/resolve/issue-5927.rs similarity index 100% rename from src/test/ui/issues/issue-5927.rs rename to src/test/ui/resolve/issue-5927.rs diff --git a/src/test/ui/issues/issue-5927.stderr b/src/test/ui/resolve/issue-5927.stderr similarity index 100% rename from src/test/ui/issues/issue-5927.stderr rename to src/test/ui/resolve/issue-5927.stderr diff --git a/src/test/ui/issues/issue-5216.rs b/src/test/ui/static/issue-5216.rs similarity index 100% rename from src/test/ui/issues/issue-5216.rs rename to src/test/ui/static/issue-5216.rs diff --git a/src/test/ui/issues/issue-5216.stderr b/src/test/ui/static/issue-5216.stderr similarity index 100% rename from src/test/ui/issues/issue-5216.stderr rename to src/test/ui/static/issue-5216.stderr diff --git a/src/test/ui/issues/issue-7013.rs b/src/test/ui/traits/issue-7013.rs similarity index 100% rename from src/test/ui/issues/issue-7013.rs rename to src/test/ui/traits/issue-7013.rs diff --git a/src/test/ui/issues/issue-7013.stderr b/src/test/ui/traits/issue-7013.stderr similarity index 100% rename from src/test/ui/issues/issue-7013.stderr rename to src/test/ui/traits/issue-7013.stderr From f800edf23603223dc18410f8da0dce259f31c74b Mon Sep 17 00:00:00 2001 From: Caio Date: Sat, 12 Nov 2022 09:54:06 -0300 Subject: [PATCH 07/10] Tidy --- src/tools/tidy/src/ui_tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/tidy/src/ui_tests.rs b/src/tools/tidy/src/ui_tests.rs index 2b82e9b3f998c..21c6a96747eef 100644 --- a/src/tools/tidy/src/ui_tests.rs +++ b/src/tools/tidy/src/ui_tests.rs @@ -10,7 +10,7 @@ use std::path::Path; const ENTRY_LIMIT: usize = 1000; // FIXME: The following limits should be reduced eventually. const ROOT_ENTRY_LIMIT: usize = 939; -const ISSUES_ENTRY_LIMIT: usize = 2105; +const ISSUES_ENTRY_LIMIT: usize = 2085; fn check_entries(path: &Path, bad: &mut bool) { for dir in Walk::new(&path.join("test/ui")) { From fa2c08112fd9e7ce9d4109ed52a36f7378710526 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sat, 12 Nov 2022 09:21:29 -0700 Subject: [PATCH 08/10] rustdoc: remove no-op CSS `.scrape-help { background: transparent }` It's a link. This is the default CSS for it. --- 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 6a068a3d243d9..74d7518de6b66 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -1984,7 +1984,6 @@ in storage.js font-size: 12px; position: relative; bottom: 1px; - background: transparent; border-width: 1px; border-style: solid; border-radius: 50px; From cb3a04b6ef4db1b16d5e8dac5fcc00d66183eed6 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sat, 12 Nov 2022 08:53:12 -0700 Subject: [PATCH 09/10] rustdoc: avoid excessive HTML generated in example sources --- src/librustdoc/html/render/mod.rs | 6 +----- src/librustdoc/html/sources.rs | 10 +++++----- src/librustdoc/html/static/css/rustdoc.css | 5 +++-- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index e09106077f7ed..1fe52353449ba 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -2899,11 +2899,7 @@ fn render_call_locations(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Ite cx, &cx.root_path(), highlight::DecorationInfo(decoration_info), - sources::SourceContext::Embedded { - url: &call_data.url, - offset: line_min, - needs_expansion, - }, + sources::SourceContext::Embedded { offset: line_min, needs_expansion }, ); write!(w, ""); diff --git a/src/librustdoc/html/sources.rs b/src/librustdoc/html/sources.rs index 99b4678c4577f..50135d6019006 100644 --- a/src/librustdoc/html/sources.rs +++ b/src/librustdoc/html/sources.rs @@ -256,9 +256,9 @@ where } } -pub(crate) enum SourceContext<'a> { +pub(crate) enum SourceContext { Standalone, - Embedded { url: &'a str, offset: usize, needs_expansion: bool }, + Embedded { offset: usize, needs_expansion: bool }, } /// Wrapper struct to render the source code of a file. This will do things like @@ -270,7 +270,7 @@ pub(crate) fn print_src( context: &Context<'_>, root_path: &str, decoration_info: highlight::DecorationInfo, - source_context: SourceContext<'_>, + source_context: SourceContext, ) { let lines = s.lines().count(); let mut line_numbers = Buffer::empty_from(buf); @@ -286,12 +286,12 @@ pub(crate) fn print_src( writeln!(line_numbers, "{line}") } } - SourceContext::Embedded { url, offset, needs_expansion } => { + SourceContext::Embedded { offset, needs_expansion } => { extra = if needs_expansion { Some(r#""#) } else { None }; for line_number in 1..=lines { let line = line_number + offset; - writeln!(line_numbers, "{line}") + writeln!(line_numbers, "{line}") } } } diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index b64fe74e960e3..bbcce72666852 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -575,7 +575,7 @@ ul.block, .block li { border-color: var(--example-line-numbers-border-color); } -.src-line-numbers a { +.src-line-numbers a, .src-line-numbers span { color: var(--src-line-numbers-span-color); } .src-line-numbers :target { @@ -2061,7 +2061,8 @@ in storage.js padding: 14px 0; } -.scraped-example .code-wrapper .src-line-numbers a { +.scraped-example .code-wrapper .src-line-numbers a, +.scraped-example .code-wrapper .src-line-numbers span { padding: 0 14px; } From 23dadb561783870be104b26fd8db9a9d2abfb0ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Sun, 13 Nov 2022 04:10:56 +0100 Subject: [PATCH 10/10] fix up a fluent message --- .../locales/en-US/infer.ftl | 4 ++-- .../hrlt-implied-trait-bounds-guard.rs | 10 ++++++++++ .../hrlt-implied-trait-bounds-guard.stderr | 20 ++++++++++++++++++- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_error_messages/locales/en-US/infer.ftl b/compiler/rustc_error_messages/locales/en-US/infer.ftl index fa975ff2c20cf..c9d83746d5454 100644 --- a/compiler/rustc_error_messages/locales/en-US/infer.ftl +++ b/compiler/rustc_error_messages/locales/en-US/infer.ftl @@ -126,10 +126,10 @@ infer_data_lifetime_flow = ...but data with one lifetime flows into the other he infer_declared_multiple = this type is declared with multiple lifetimes... infer_types_declared_different = these two types are declared with different lifetimes... infer_data_flows = ...but data{$label_var1_exists -> - [true] -> {" "}from `{$label_var1}` + [true] {" "}from `{$label_var1}` *[false] -> {""} } flows{$label_var2_exists -> - [true] -> {" "}into `{$label_var2}` + [true] {" "}into `{$label_var2}` *[false] -> {""} } here diff --git a/src/test/ui/implied-bounds/hrlt-implied-trait-bounds-guard.rs b/src/test/ui/implied-bounds/hrlt-implied-trait-bounds-guard.rs index d9de73a38efff..79844dcbdacfd 100644 --- a/src/test/ui/implied-bounds/hrlt-implied-trait-bounds-guard.rs +++ b/src/test/ui/implied-bounds/hrlt-implied-trait-bounds-guard.rs @@ -31,6 +31,16 @@ fn badboi<'in_, 'out, T>(x: Foo<'in_, 'out, T>, sadness: &'in_ T) -> &'out T { sadness.cast() } +fn badboi2<'in_, 'out, T>(x: Foo<'in_, 'out, T>, sadness: &'in_ T) { + //~^ ERROR lifetime mismatch + let _: &'out T = sadness.cast(); +} + +fn badboi3<'in_, 'out, T>(a: Foo<'in_, 'out, (&'in_ T, &'out T)>, sadness: &'in_ T) { + //~^ ERROR lifetime mismatch + let _: &'out T = sadness.cast(); +} + fn bad<'short, T>(value: &'short T) -> &'static T { let x: for<'in_, 'out> fn(Foo<'in_, 'out, T>, &'in_ T) -> &'out T = badboi; let x: for<'out> fn(Foo<'short, 'out, T>, &'short T) -> &'out T = x; diff --git a/src/test/ui/implied-bounds/hrlt-implied-trait-bounds-guard.stderr b/src/test/ui/implied-bounds/hrlt-implied-trait-bounds-guard.stderr index b020ea64bf46e..0c00bbc380e8a 100644 --- a/src/test/ui/implied-bounds/hrlt-implied-trait-bounds-guard.stderr +++ b/src/test/ui/implied-bounds/hrlt-implied-trait-bounds-guard.stderr @@ -7,6 +7,24 @@ LL | fn badboi<'in_, 'out, T>(x: Foo<'in_, 'out, T>, sadness: &'in_ T) -> &'out | this parameter and the return type are declared with different lifetimes... | ...but data from `x` is returned here -error: aborting due to previous error +error[E0623]: lifetime mismatch + --> $DIR/hrlt-implied-trait-bounds-guard.rs:34:30 + | +LL | fn badboi2<'in_, 'out, T>(x: Foo<'in_, 'out, T>, sadness: &'in_ T) { + | ^^^^^^^^^^^^^^^^^^ + | | + | this type is declared with multiple lifetimes... + | ...but data with one lifetime flows into the other here + +error[E0623]: lifetime mismatch + --> $DIR/hrlt-implied-trait-bounds-guard.rs:39:30 + | +LL | fn badboi3<'in_, 'out, T>(a: Foo<'in_, 'out, (&'in_ T, &'out T)>, sadness: &'in_ T) { + | ^^^^^^^^^^^^^^^^^-------^^-------^^ + | | | + | | these two types are declared with different lifetimes... + | ...but data from `a` flows into `a` here + +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0623`.