Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 5 pull requests #104351

Merged
merged 15 commits into from
Nov 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/rustc_error_messages/locales/en-US/infer.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 3 additions & 8 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
"<span class=\"notable-traits\" data-ty=\"{ty}\">\
<span class=\"notable-traits-tooltip\">ⓘ</span>\
</span>",
" <a href=\"#\" class=\"notable-traits\" data-ty=\"{ty}\">ⓘ</a>",
ty = Escape(&format!("{:#}", ty.print(cx))),
))
} else {
Expand Down Expand Up @@ -1343,7 +1341,7 @@ fn notable_traits_decl(ty: &clean::Type, cx: &Context<'_>) -> (String, String) {
if out.is_empty() {
write!(
&mut out,
"<h3 class=\"notable\">Notable traits for <code>{}</code></h3>\
"<h3>Notable traits for <code>{}</code></h3>\
<pre class=\"content\"><code>",
impl_.for_.print(cx)
);
Expand Down Expand Up @@ -2939,9 +2937,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);
Expand All @@ -2951,7 +2946,7 @@ 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 },
);
Expand Down
13 changes: 7 additions & 6 deletions src/librustdoc/html/sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,25 +276,26 @@ pub(crate) fn print_src(
let mut line_numbers = Buffer::empty_from(buf);
let extra;
line_numbers.write_str("<pre class=\"src-line-numbers\">");
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, "<span id=\"{0}\">{0}</span>", line)
writeln!(line_numbers, "<a href=\"#{line}\" id=\"{line}\">{line}</a>")
}
}
SourceContext::Embedded { offset, needs_expansion } => {
extra =
if needs_expansion { Some(r#"<span class="expand">&varr;</span>"#) } else { None };
for line in 1..=lines {
writeln!(line_numbers, "<span>{0}</span>", line + offset)
for line_number in 1..=lines {
let line = line_number + offset;
writeln!(line_numbers, "<span>{line}</span>")
}
}
}
line_numbers.write_str("</pre>");
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,
Expand Down
84 changes: 26 additions & 58 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -579,15 +579,16 @@ ul.block, .block li {
border-color: var(--example-line-numbers-border-color);
}

.src-line-numbers span {
cursor: pointer;
.src-line-numbers a, .src-line-numbers span {
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 {
Expand Down Expand Up @@ -928,13 +929,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;
Expand All @@ -951,10 +953,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 {
Expand Down Expand Up @@ -1273,54 +1272,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 {
Expand Down Expand Up @@ -1363,12 +1342,6 @@ h3.variant {
font-size: 1rem;
}

.notable-traits {
cursor: pointer;
z-index: 2;
margin-left: 5px;
}

#sidebar-toggle {
position: sticky;
top: 0;
Expand Down Expand Up @@ -1853,11 +1826,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;
Expand Down Expand Up @@ -1982,7 +1950,6 @@ in storage.js
font-size: 12px;
position: relative;
bottom: 1px;
background: transparent;
border-width: 1px;
border-style: solid;
border-radius: 50px;
Expand Down Expand Up @@ -2044,6 +2011,7 @@ in storage.js
padding: 14px 0;
}

.scraped-example .code-wrapper .src-line-numbers a,
.scraped-example .code-wrapper .src-line-numbers span {
padding: 0 14px;
}
Expand Down
4 changes: 0 additions & 4 deletions src/librustdoc/html/static/css/themes/ayu.css
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,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;
Expand Down
4 changes: 0 additions & 4 deletions src/librustdoc/html/static/css/themes/dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,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;
Expand Down
4 changes: 0 additions & 4 deletions src/librustdoc/html/static/css/themes/light.css
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,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;
Expand Down
60 changes: 51 additions & 9 deletions src/librustdoc/html/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<div class=\"docblock\">" + window.NOTABLE_TRAITS[ty] + "</div>";
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) {
Expand All @@ -875,9 +890,31 @@ 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)
) {
// 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);
}
}

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;
Expand All @@ -891,7 +928,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.
Expand Down Expand Up @@ -1018,6 +1059,7 @@ function loadCss(cssUrl) {
onEachLazy(document.querySelectorAll(".search-form .popover"), elem => {
elem.style.display = "none";
});
hideNotable();
};

/**
Expand Down
11 changes: 8 additions & 3 deletions src/librustdoc/html/static/js/source-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
});
Expand Down Expand Up @@ -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();
Expand Down
Loading