Skip to content

Commit 3dca81d

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 801c978 commit 3dca81d

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ details:not(.toggle) summary {
335335
margin-bottom: .6em;
336336
}
337337

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

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

+28-15
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) {
@@ -3076,13 +3082,18 @@ ${item.displayPath}<span class="${type}">${name}</span>\
30763082
tooltip.href = `#${tooltip.id}`;
30773083
const tooltipCode = document.createElement("code");
30783084
for (const [name, qname] of mappedNames) {
3085+
// don't care unless the generic name is different
3086+
if (name === qname) {
3087+
continue;
3088+
}
30793089
const line = document.createElement("div");
30803090
line.className = "where";
30813091
line.appendChild(document.createTextNode(`${name} is ${qname}`));
30823092
tooltipCode.appendChild(line);
30833093
}
30843094
for (const [name, innerType] of whereClause) {
3085-
if (innerType.length === 0) {
3095+
// don't care unless there's at least one highlighted entry
3096+
if (innerType.length <= 1) {
30863097
continue;
30873098
}
30883099
const line = document.createElement("div");
@@ -3099,20 +3110,22 @@ ${item.displayPath}<span class="${type}">${name}</span>\
30993110
});
31003111
tooltipCode.appendChild(line);
31013112
}
3102-
tooltip.RUSTDOC_TOOLTIP_DOM = document.createElement("div");
3103-
tooltip.RUSTDOC_TOOLTIP_DOM.className = "content";
3104-
const tooltipH3 = document.createElement("h3");
3105-
tooltipH3.innerHTML = "About this result";
3106-
tooltip.RUSTDOC_TOOLTIP_DOM.appendChild(tooltipH3);
3107-
const tooltipPre = document.createElement("pre");
3108-
tooltipPre.appendChild(tooltipCode);
3109-
tooltip.RUSTDOC_TOOLTIP_DOM.appendChild(tooltipPre);
3110-
tooltip.typeWhereClause = whereClause;
3111-
tooltip.innerText = "ⓘ";
3112-
tooltip.className = "tooltip";
3113-
window.rustdocConfigureTooltip(tooltip);
3114-
displayType.appendChild(tooltip);
3115-
displayType.appendChild(document.createTextNode(" "));
3113+
if (tooltipCode.childNodes.length !== 0) {
3114+
tooltip.RUSTDOC_TOOLTIP_DOM = document.createElement("div");
3115+
tooltip.RUSTDOC_TOOLTIP_DOM.className = "content";
3116+
const tooltipH3 = document.createElement("h3");
3117+
tooltipH3.innerHTML = "About this result";
3118+
tooltip.RUSTDOC_TOOLTIP_DOM.appendChild(tooltipH3);
3119+
const tooltipPre = document.createElement("pre");
3120+
tooltipPre.appendChild(tooltipCode);
3121+
tooltip.RUSTDOC_TOOLTIP_DOM.appendChild(tooltipPre);
3122+
tooltip.typeWhereClause = whereClause;
3123+
tooltip.innerText = "ⓘ";
3124+
tooltip.className = "tooltip";
3125+
window.rustdocConfigureTooltip(tooltip);
3126+
displayType.appendChild(tooltip);
3127+
displayType.appendChild(document.createTextNode(" "));
3128+
}
31163129
}
31173130
type.forEach((value, index) => {
31183131
if (index % 2 !== 0) {

0 commit comments

Comments
 (0)