Skip to content

Commit 928d14b

Browse files
committed
Auto merge of #104351 - JohnTitor:rollup-ikh2dzr, r=JohnTitor
Rollup of 5 pull requests Successful merges: - #103650 (rustdoc: change `.src-line-numbers > span` to `.src-line-numbers > a`) - #104177 (rustdoc: use consistent "popover" styling for notable traits) - #104318 (Move tests) - #104323 (rustdoc: remove no-op CSS `.scrape-help { background: transparent }`) - #104345 (Fix up a Fluent message) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 3be81dd + 05cd26b commit 928d14b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+239
-179
lines changed

compiler/rustc_error_messages/locales/en-US/infer.ftl

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ infer_data_lifetime_flow = ...but data with one lifetime flows into the other he
126126
infer_declared_multiple = this type is declared with multiple lifetimes...
127127
infer_types_declared_different = these two types are declared with different lifetimes...
128128
infer_data_flows = ...but data{$label_var1_exists ->
129-
[true] -> {" "}from `{$label_var1}`
129+
[true] {" "}from `{$label_var1}`
130130
*[false] -> {""}
131131
} flows{$label_var2_exists ->
132-
[true] -> {" "}into `{$label_var2}`
132+
[true] {" "}into `{$label_var2}`
133133
*[false] -> {""}
134134
} here
135135

src/librustdoc/html/render/mod.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -1312,9 +1312,7 @@ pub(crate) fn notable_traits_button(ty: &clean::Type, cx: &mut Context<'_>) -> O
13121312
if has_notable_trait {
13131313
cx.types_with_notable_traits.insert(ty.clone());
13141314
Some(format!(
1315-
"<span class=\"notable-traits\" data-ty=\"{ty}\">\
1316-
<span class=\"notable-traits-tooltip\">ⓘ</span>\
1317-
</span>",
1315+
" <a href=\"#\" class=\"notable-traits\" data-ty=\"{ty}\">ⓘ</a>",
13181316
ty = Escape(&format!("{:#}", ty.print(cx))),
13191317
))
13201318
} else {
@@ -1343,7 +1341,7 @@ fn notable_traits_decl(ty: &clean::Type, cx: &Context<'_>) -> (String, String) {
13431341
if out.is_empty() {
13441342
write!(
13451343
&mut out,
1346-
"<h3 class=\"notable\">Notable traits for <code>{}</code></h3>\
1344+
"<h3>Notable traits for <code>{}</code></h3>\
13471345
<pre class=\"content\"><code>",
13481346
impl_.for_.print(cx)
13491347
);
@@ -2939,9 +2937,6 @@ fn render_call_locations(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Ite
29392937
})()
29402938
.unwrap_or(rustc_span::DUMMY_SP);
29412939

2942-
// The root path is the inverse of Context::current
2943-
let root_path = vec!["../"; cx.current.len() - 1].join("");
2944-
29452940
let mut decoration_info = FxHashMap::default();
29462941
decoration_info.insert("highlight focus", vec![byte_ranges.remove(0)]);
29472942
decoration_info.insert("highlight", byte_ranges);
@@ -2951,7 +2946,7 @@ fn render_call_locations(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Ite
29512946
contents_subset,
29522947
file_span,
29532948
cx,
2954-
&root_path,
2949+
&cx.root_path(),
29552950
highlight::DecorationInfo(decoration_info),
29562951
sources::SourceContext::Embedded { offset: line_min, needs_expansion },
29572952
);

src/librustdoc/html/sources.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -276,25 +276,26 @@ pub(crate) fn print_src(
276276
let mut line_numbers = Buffer::empty_from(buf);
277277
let extra;
278278
line_numbers.write_str("<pre class=\"src-line-numbers\">");
279+
let current_href = &context
280+
.href_from_span(clean::Span::new(file_span), false)
281+
.expect("only local crates should have sources emitted");
279282
match source_context {
280283
SourceContext::Standalone => {
281284
extra = None;
282285
for line in 1..=lines {
283-
writeln!(line_numbers, "<span id=\"{0}\">{0}</span>", line)
286+
writeln!(line_numbers, "<a href=\"#{line}\" id=\"{line}\">{line}</a>")
284287
}
285288
}
286289
SourceContext::Embedded { offset, needs_expansion } => {
287290
extra =
288291
if needs_expansion { Some(r#"<span class="expand">&varr;</span>"#) } else { None };
289-
for line in 1..=lines {
290-
writeln!(line_numbers, "<span>{0}</span>", line + offset)
292+
for line_number in 1..=lines {
293+
let line = line_number + offset;
294+
writeln!(line_numbers, "<span>{line}</span>")
291295
}
292296
}
293297
}
294298
line_numbers.write_str("</pre>");
295-
let current_href = &context
296-
.href_from_span(clean::Span::new(file_span), false)
297-
.expect("only local crates should have sources emitted");
298299
highlight::render_source_with_highlighting(
299300
s,
300301
buf,

src/librustdoc/html/static/css/rustdoc.css

+26-58
Original file line numberDiff line numberDiff line change
@@ -579,15 +579,16 @@ ul.block, .block li {
579579
border-color: var(--example-line-numbers-border-color);
580580
}
581581

582-
.src-line-numbers span {
583-
cursor: pointer;
582+
.src-line-numbers a, .src-line-numbers span {
584583
color: var(--src-line-numbers-span-color);
585584
}
586-
.src-line-numbers .line-highlighted {
587-
background-color: var(--src-line-number-highlighted-background-color);
588-
}
589585
.src-line-numbers :target {
590586
background-color: transparent;
587+
border-right: none;
588+
padding-right: 0;
589+
}
590+
.src-line-numbers .line-highlighted {
591+
background-color: var(--src-line-number-highlighted-background-color);
591592
}
592593

593594
.search-loading {
@@ -928,13 +929,14 @@ so that we can apply CSS-filters to change the arrow color in themes */
928929
border-radius: 3px;
929930
border: 1px solid var(--border-color);
930931
font-size: 1rem;
932+
--popover-arrow-offset: 11px;
931933
}
932934

933935
/* This rule is to draw the little arrow connecting the settings menu to the gear icon. */
934936
.popover::before {
935937
content: '';
936938
position: absolute;
937-
right: 11px;
939+
right: var(--popover-arrow-offset);
938940
border: solid var(--border-color);
939941
border-width: 1px 1px 0 0;
940942
display: inline-block;
@@ -951,10 +953,7 @@ so that we can apply CSS-filters to change the arrow color in themes */
951953
/* use larger max-width for help popover, but not for help.html */
952954
#help.popover {
953955
max-width: 600px;
954-
}
955-
956-
#help.popover::before {
957-
right: 48px;
956+
--popover-arrow-offset: 48px;
958957
}
959958

960959
#help dt {
@@ -1273,54 +1272,34 @@ h3.variant {
12731272
border-right: 3px solid var(--target-border-color);
12741273
}
12751274

1276-
.notable-traits-tooltip {
1277-
display: inline-block;
1278-
cursor: pointer;
1279-
}
1280-
1281-
.notable-traits .notable-traits-tooltiptext {
1282-
display: inline-block;
1283-
visibility: hidden;
1275+
.notable-traits {
1276+
color: inherit;
1277+
margin-right: 15px;
1278+
position: relative;
12841279
}
12851280

1286-
.notable-traits-tooltiptext {
1287-
padding: 5px 3px 3px 3px;
1288-
border-radius: 6px;
1289-
margin-left: 5px;
1290-
z-index: 10;
1291-
font-size: 1rem;
1292-
cursor: default;
1281+
/* placeholder thunk so that the mouse can easily travel from "(i)" to popover
1282+
the resulting "hover tunnel" is a stepped triangle, approximating
1283+
https://bjk5.com/post/44698559168/breaking-down-amazons-mega-dropdown */
1284+
.notable-traits:hover::after {
12931285
position: absolute;
1294-
border: 1px solid;
1295-
}
1296-
1297-
.notable-traits-tooltip::after {
1298-
/* The margin on the tooltip does not capture hover events,
1299-
this extends the area of hover enough so that mouse hover is not
1300-
lost when moving the mouse to the tooltip */
1301-
content: "\00a0\00a0\00a0";
1302-
}
1303-
1304-
.notable-traits-tooltiptext .docblock {
1305-
margin: 0;
1286+
top: calc(100% - 10px);
1287+
left: -15px;
1288+
right: -15px;
1289+
height: 20px;
1290+
content: "\00a0";
13061291
}
13071292

1308-
.notable-traits-tooltiptext .notable {
1309-
font-size: 1.1875rem;
1310-
font-weight: 600;
1311-
display: block;
1293+
.notable .docblock {
1294+
margin: 0.25em 0.5em;
13121295
}
13131296

1314-
.notable-traits-tooltiptext pre, .notable-traits-tooltiptext code {
1297+
.notable .docblock pre, .notable .docblock code {
13151298
background: transparent;
1316-
}
1317-
1318-
.notable-traits-tooltiptext .docblock pre.content {
13191299
margin: 0;
13201300
padding: 0;
13211301
font-size: 1.25rem;
13221302
white-space: pre-wrap;
1323-
overflow: hidden;
13241303
}
13251304

13261305
.search-failed {
@@ -1363,12 +1342,6 @@ h3.variant {
13631342
font-size: 1rem;
13641343
}
13651344

1366-
.notable-traits {
1367-
cursor: pointer;
1368-
z-index: 2;
1369-
margin-left: 5px;
1370-
}
1371-
13721345
#sidebar-toggle {
13731346
position: sticky;
13741347
top: 0;
@@ -1853,11 +1826,6 @@ in storage.js
18531826
border-bottom: 1px solid;
18541827
}
18551828

1856-
.notable-traits .notable-traits-tooltiptext {
1857-
left: 0;
1858-
top: 100%;
1859-
}
1860-
18611829
/* We don't display the help button on mobile devices. */
18621830
#help-button {
18631831
display: none;
@@ -1982,7 +1950,6 @@ in storage.js
19821950
font-size: 12px;
19831951
position: relative;
19841952
bottom: 1px;
1985-
background: transparent;
19861953
border-width: 1px;
19871954
border-style: solid;
19881955
border-radius: 50px;
@@ -2044,6 +2011,7 @@ in storage.js
20442011
padding: 14px 0;
20452012
}
20462013

2014+
.scraped-example .code-wrapper .src-line-numbers a,
20472015
.scraped-example .code-wrapper .src-line-numbers span {
20482016
padding: 0 14px;
20492017
}

src/librustdoc/html/static/css/themes/ayu.css

-4
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,6 @@ details.rustdoc-toggle > summary::before {
169169
border-color: transparent #314559 transparent transparent;
170170
}
171171

172-
.notable-traits-tooltiptext {
173-
background-color: #314559;
174-
}
175-
176172
#titles > button.selected {
177173
background-color: #141920 !important;
178174
border-bottom: 1px solid #ffb44c !important;

src/librustdoc/html/static/css/themes/dark.css

-4
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,6 @@ details.rustdoc-toggle > summary::before {
9292
border-color: transparent black transparent transparent;
9393
}
9494

95-
.notable-traits-tooltiptext {
96-
background-color: #111;
97-
}
98-
9995
#titles > button:not(.selected) {
10096
background-color: #252525;
10197
border-top-color: #252525;

src/librustdoc/html/static/css/themes/light.css

-4
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ body.source .example-wrap pre.rust a {
8484
border-color: transparent black transparent transparent;
8585
}
8686

87-
.notable-traits-tooltiptext {
88-
background-color: #eee;
89-
}
90-
9187
#titles > button:not(.selected) {
9288
background-color: #e6e6e6;
9389
border-top-color: #e6e6e6;

src/librustdoc/html/static/js/main.js

+51-9
Original file line numberDiff line numberDiff line change
@@ -850,18 +850,33 @@ function loadCss(cssUrl) {
850850
}
851851
hideNotable();
852852
const ty = e.getAttribute("data-ty");
853-
const tooltip = e.getElementsByClassName("notable-traits-tooltip")[0];
854853
const wrapper = document.createElement("div");
855854
wrapper.innerHTML = "<div class=\"docblock\">" + window.NOTABLE_TRAITS[ty] + "</div>";
856-
wrapper.className = "notable-traits-tooltiptext";
857-
tooltip.appendChild(wrapper);
858-
const pos = wrapper.getBoundingClientRect();
859-
tooltip.removeChild(wrapper);
860-
wrapper.style.top = (pos.top + window.scrollY) + "px";
861-
wrapper.style.left = (pos.left + window.scrollX) + "px";
862-
wrapper.style.width = pos.width + "px";
855+
wrapper.className = "notable popover";
856+
const focusCatcher = document.createElement("div");
857+
focusCatcher.setAttribute("tabindex", "0");
858+
focusCatcher.onfocus = hideNotable;
859+
wrapper.appendChild(focusCatcher);
860+
const pos = e.getBoundingClientRect();
861+
// 5px overlap so that the mouse can easily travel from place to place
862+
wrapper.style.top = (pos.top + window.scrollY + pos.height) + "px";
863+
wrapper.style.left = 0;
864+
wrapper.style.right = "auto";
865+
wrapper.style.visibility = "hidden";
863866
const body = document.getElementsByTagName("body")[0];
864867
body.appendChild(wrapper);
868+
const wrapperPos = wrapper.getBoundingClientRect();
869+
// offset so that the arrow points at the center of the "(i)"
870+
const finalPos = pos.left + window.scrollX - wrapperPos.width + 24;
871+
if (finalPos > 0) {
872+
wrapper.style.left = finalPos + "px";
873+
} else {
874+
wrapper.style.setProperty(
875+
"--popover-arrow-offset",
876+
(wrapperPos.right - pos.right + 4) + "px"
877+
);
878+
}
879+
wrapper.style.visibility = "";
865880
window.CURRENT_NOTABLE_ELEMENT = wrapper;
866881
window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE = e;
867882
wrapper.onpointerleave = function(ev) {
@@ -875,9 +890,31 @@ function loadCss(cssUrl) {
875890
};
876891
}
877892

893+
function notableBlurHandler(event) {
894+
if (window.CURRENT_NOTABLE_ELEMENT &&
895+
!elemIsInParent(document.activeElement, window.CURRENT_NOTABLE_ELEMENT) &&
896+
!elemIsInParent(event.relatedTarget, window.CURRENT_NOTABLE_ELEMENT) &&
897+
!elemIsInParent(document.activeElement, window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE) &&
898+
!elemIsInParent(event.relatedTarget, window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE)
899+
) {
900+
// Work around a difference in the focus behaviour between Firefox, Chrome, and Safari.
901+
// When I click the button on an already-opened notable trait popover, Safari
902+
// hides the popover and then immediately shows it again, while everyone else hides it
903+
// and it stays hidden.
904+
//
905+
// To work around this, make sure the click finishes being dispatched before
906+
// hiding the popover. Since `hideNotable()` is idempotent, this makes Safari behave
907+
// consistently with the other two.
908+
setTimeout(hideNotable, 0);
909+
}
910+
}
911+
878912
function hideNotable() {
879913
if (window.CURRENT_NOTABLE_ELEMENT) {
880-
window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE.NOTABLE_FORCE_VISIBLE = false;
914+
if (window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE.NOTABLE_FORCE_VISIBLE) {
915+
window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE.focus();
916+
window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE.NOTABLE_FORCE_VISIBLE = false;
917+
}
881918
const body = document.getElementsByTagName("body")[0];
882919
body.removeChild(window.CURRENT_NOTABLE_ELEMENT);
883920
window.CURRENT_NOTABLE_ELEMENT = null;
@@ -891,7 +928,11 @@ function loadCss(cssUrl) {
891928
hideNotable();
892929
} else {
893930
showNotable(this);
931+
window.CURRENT_NOTABLE_ELEMENT.setAttribute("tabindex", "0");
932+
window.CURRENT_NOTABLE_ELEMENT.focus();
933+
window.CURRENT_NOTABLE_ELEMENT.onblur = notableBlurHandler;
894934
}
935+
return false;
895936
};
896937
e.onpointerenter = function(ev) {
897938
// If this is a synthetic touch event, ignore it. A click event will be along shortly.
@@ -1018,6 +1059,7 @@ function loadCss(cssUrl) {
10181059
onEachLazy(document.querySelectorAll(".search-form .popover"), elem => {
10191060
elem.style.display = "none";
10201061
});
1062+
hideNotable();
10211063
};
10221064

10231065
/**

src/librustdoc/html/static/js/source-script.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ function highlightSourceLines(match) {
157157
x.scrollIntoView();
158158
}
159159
onEachLazy(document.getElementsByClassName("src-line-numbers"), e => {
160-
onEachLazy(e.getElementsByTagName("span"), i_e => {
160+
onEachLazy(e.getElementsByTagName("a"), i_e => {
161161
removeClass(i_e, "line-highlighted");
162162
});
163163
});
@@ -188,8 +188,13 @@ const handleSourceHighlight = (function() {
188188

189189
return ev => {
190190
let cur_line_id = parseInt(ev.target.id, 10);
191-
// It can happen when clicking not on a line number span.
192-
if (isNaN(cur_line_id)) {
191+
// This event handler is attached to the entire line number column, but it should only
192+
// be run if one of the anchors is clicked. It also shouldn't do anything if the anchor
193+
// is clicked with a modifier key (to open a new browser tab).
194+
if (isNaN(cur_line_id) ||
195+
ev.ctrlKey ||
196+
ev.altKey ||
197+
ev.metaKey) {
193198
return;
194199
}
195200
ev.preventDefault();

0 commit comments

Comments
 (0)