Skip to content

Commit f952de8

Browse files
committed
rustdoc-search: improve type signature display
Make it a fixed width font, fix the trait bound format, and don't show `T is T` maps or unhighlighted bounds.
1 parent 5c72ce4 commit f952de8

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ details:not(.toggle) summary {
336336
margin-bottom: .6em;
337337
}
338338

339-
code, pre, a.test-arrow, .code-header {
339+
code, pre, a.test-arrow, .code-header, .type-signature {
340340
font-family: "Source Code Pro", monospace;
341341
}
342342
.docblock code, .docblock-short code {

src/librustdoc/html/static/js/search.js

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,7 +1569,13 @@ function initSearch(rawSearchIndex) {
15691569
highlighted: !!fnType.highlighted,
15701570
}, result);
15711571
const where = [];
1572+
let first = true;
15721573
for (const nested of fnType.generics) {
1574+
if (first) {
1575+
first = false;
1576+
} else {
1577+
pushText({ name: " + ", highlighted: false }, where);
1578+
}
15731579
writeFn(nested, where);
15741580
}
15751581
if (where.length > 0) {
@@ -3080,13 +3086,18 @@ ${item.displayPath}<span class="${type}">${name}</span>\
30803086
tooltip.href = `#${tooltip.id}`;
30813087
const tooltipCode = document.createElement("code");
30823088
for (const [name, qname] of mappedNames) {
3089+
// don't care unless the generic name is different
3090+
if (name === qname) {
3091+
continue;
3092+
}
30833093
const line = document.createElement("div");
30843094
line.className = "where";
30853095
line.appendChild(document.createTextNode(`${name} is ${qname}`));
30863096
tooltipCode.appendChild(line);
30873097
}
30883098
for (const [name, innerType] of whereClause) {
3089-
if (innerType.length === 0) {
3099+
// don't care unless there's at least one highlighted entry
3100+
if (innerType.length <= 1) {
30903101
continue;
30913102
}
30923103
const line = document.createElement("div");
@@ -3103,20 +3114,22 @@ ${item.displayPath}<span class="${type}">${name}</span>\
31033114
});
31043115
tooltipCode.appendChild(line);
31053116
}
3106-
tooltip.RUSTDOC_TOOLTIP_DOM = document.createElement("div");
3107-
tooltip.RUSTDOC_TOOLTIP_DOM.className = "content";
3108-
const tooltipH3 = document.createElement("h3");
3109-
tooltipH3.innerHTML = "About this result";
3110-
tooltip.RUSTDOC_TOOLTIP_DOM.appendChild(tooltipH3);
3111-
const tooltipPre = document.createElement("pre");
3112-
tooltipPre.appendChild(tooltipCode);
3113-
tooltip.RUSTDOC_TOOLTIP_DOM.appendChild(tooltipPre);
3114-
tooltip.typeWhereClause = whereClause;
3115-
tooltip.innerText = "ⓘ";
3116-
tooltip.className = "tooltip";
3117-
window.rustdocConfigureTooltip(tooltip);
3118-
displayType.appendChild(tooltip);
3119-
displayType.appendChild(document.createTextNode(" "));
3117+
if (tooltipCode.childNodes.length !== 0) {
3118+
tooltip.RUSTDOC_TOOLTIP_DOM = document.createElement("div");
3119+
tooltip.RUSTDOC_TOOLTIP_DOM.className = "content";
3120+
const tooltipH3 = document.createElement("h3");
3121+
tooltipH3.innerHTML = "About this result";
3122+
tooltip.RUSTDOC_TOOLTIP_DOM.appendChild(tooltipH3);
3123+
const tooltipPre = document.createElement("pre");
3124+
tooltipPre.appendChild(tooltipCode);
3125+
tooltip.RUSTDOC_TOOLTIP_DOM.appendChild(tooltipPre);
3126+
tooltip.typeWhereClause = whereClause;
3127+
tooltip.innerText = "ⓘ";
3128+
tooltip.className = "tooltip";
3129+
window.rustdocConfigureTooltip(tooltip);
3130+
displayType.appendChild(tooltip);
3131+
displayType.appendChild(document.createTextNode(" "));
3132+
}
31203133
}
31213134
type.forEach((value, index) => {
31223135
if (index % 2 !== 0) {

0 commit comments

Comments
 (0)