Skip to content

Commit 1fb4805

Browse files
authored
Rollup merge of #126176 - notriddle:notriddle/fix-type-name-normalize, r=fmease
rustdoc-search: use lowercase, non-normalized name for type search The type name ID map has underscores in its names, so the query element should have them, too. Fixes #125993
2 parents cbb9869 + 8865b8c commit 1fb4805

File tree

3 files changed

+78
-4
lines changed

3 files changed

+78
-4
lines changed

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

+8-4
Original file line numberDiff line numberDiff line change
@@ -2399,15 +2399,19 @@ function initSearch(rawSearchIndex) {
23992399
* @param {boolean} isAssocType
24002400
*/
24012401
function convertNameToId(elem, isAssocType) {
2402-
if (typeNameIdMap.has(elem.normalizedPathLast) &&
2403-
(isAssocType || !typeNameIdMap.get(elem.normalizedPathLast).assocOnly)) {
2404-
elem.id = typeNameIdMap.get(elem.normalizedPathLast).id;
2402+
const loweredName = elem.pathLast.toLowerCase();
2403+
if (typeNameIdMap.has(loweredName) &&
2404+
(isAssocType || !typeNameIdMap.get(loweredName).assocOnly)) {
2405+
elem.id = typeNameIdMap.get(loweredName).id;
24052406
} else if (!parsedQuery.literalSearch) {
24062407
let match = null;
24072408
let matchDist = maxEditDistance + 1;
24082409
let matchName = "";
24092410
for (const [name, {id, assocOnly}] of typeNameIdMap) {
2410-
const dist = editDistance(name, elem.normalizedPathLast, maxEditDistance);
2411+
const dist = Math.min(
2412+
editDistance(name, loweredName, maxEditDistance),
2413+
editDistance(name, elem.normalizedPathLast, maxEditDistance),
2414+
);
24112415
if (dist <= matchDist && dist <= maxEditDistance &&
24122416
(isAssocType || !assocOnly)) {
24132417
if (dist === matchDist && matchName > name) {

tests/rustdoc-js/underscoredtype.js

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
const EXPECTED = [
2+
{
3+
'query': 'pid_t',
4+
'correction': null,
5+
'proposeCorrectionFrom': null,
6+
'proposeCorrectionTo': null,
7+
'others': [
8+
{ 'path': 'underscoredtype::unix', 'name': 'pid_t' },
9+
],
10+
'returned': [
11+
{ 'path': 'underscoredtype::unix', 'name': 'set_pid' },
12+
],
13+
'returned': [
14+
{ 'path': 'underscoredtype::unix', 'name': 'get_pid' },
15+
],
16+
},
17+
{
18+
'query': 'pidt',
19+
'correction': 'pid_t',
20+
'proposeCorrectionFrom': null,
21+
'proposeCorrectionTo': null,
22+
'others': [
23+
{ 'path': 'underscoredtype::unix', 'name': 'pid_t' },
24+
],
25+
'returned': [
26+
{ 'path': 'underscoredtype::unix', 'name': 'set_pid' },
27+
],
28+
'returned': [
29+
{ 'path': 'underscoredtype::unix', 'name': 'get_pid' },
30+
],
31+
},
32+
{
33+
'query': 'unix::pid_t',
34+
'correction': null,
35+
'proposeCorrectionFrom': null,
36+
'proposeCorrectionTo': null,
37+
'others': [
38+
{ 'path': 'underscoredtype::unix', 'name': 'pid_t' },
39+
],
40+
'returned': [
41+
{ 'path': 'underscoredtype::unix', 'name': 'set_pid' },
42+
],
43+
'returned': [
44+
{ 'path': 'underscoredtype::unix', 'name': 'get_pid' },
45+
],
46+
},
47+
{
48+
'query': 'unix::pidt',
49+
'correction': 'pid_t',
50+
'proposeCorrectionFrom': null,
51+
'proposeCorrectionTo': null,
52+
'others': [
53+
{ 'path': 'underscoredtype::unix', 'name': 'pid_t' },
54+
],
55+
'returned': [
56+
{ 'path': 'underscoredtype::unix', 'name': 'set_pid' },
57+
],
58+
'returned': [
59+
{ 'path': 'underscoredtype::unix', 'name': 'get_pid' },
60+
],
61+
},
62+
];

tests/rustdoc-js/underscoredtype.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
pub mod unix {
2+
#[allow(non_camel_case_types)]
3+
pub type pid_t = i32;
4+
pub fn get_pid() -> pid_t {
5+
0
6+
}
7+
pub fn set_pid(_: pid_t) {}
8+
}

0 commit comments

Comments
 (0)