Skip to content

Commit 876a3bc

Browse files
committed
Auto merge of #59622 - GuillaumeGomez:improve-one-char-search, r=QuietMisdreavus
Ensure that exact matches come first in rustdoc search Fixes #59287. cc @scottmcm r? @QuietMisdreavus
2 parents 2226c09 + 1907367 commit 876a3bc

File tree

3 files changed

+83
-3
lines changed

3 files changed

+83
-3
lines changed

src/librustdoc/html/static/main.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -930,10 +930,10 @@ if (!DOMTokenList.prototype.remove) {
930930
returned = checkReturned(ty, output, true);
931931
if (output.name === "*" || returned === true) {
932932
in_args = false;
933-
var module = false;
933+
var is_module = false;
934934

935935
if (input === "*") {
936-
module = true;
936+
is_module = true;
937937
} else {
938938
var allFound = true;
939939
for (var it = 0; allFound === true && it < inputs.length; it++) {
@@ -955,7 +955,7 @@ if (!DOMTokenList.prototype.remove) {
955955
dontValidate: true,
956956
};
957957
}
958-
if (module === true) {
958+
if (is_module === true) {
959959
results[fullId] = {
960960
id: i,
961961
index: -1,
@@ -1073,6 +1073,10 @@ if (!DOMTokenList.prototype.remove) {
10731073
if (index !== -1 || lev <= MAX_LEV_DISTANCE) {
10741074
if (index !== -1 && paths.length < 2) {
10751075
lev = 0;
1076+
} else if (searchWords[j] === val) {
1077+
// Small trick to fix when you're looking for a one letter type
1078+
// and there are other short named types.
1079+
lev = -1;
10761080
}
10771081
if (results[fullId] === undefined) {
10781082
results[fullId] = {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const QUERY = 'P';
2+
3+
const EXPECTED = {
4+
'others': [
5+
{ 'path': 'search_short_types', 'name': 'P' },
6+
{ 'path': 'search_short_types', 'name': 'Ap' },
7+
],
8+
};
+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
macro_rules! imp {
2+
($name:ident) => {
3+
pub struct $name {
4+
pub op: usize,
5+
}
6+
impl $name {
7+
pub fn op() {}
8+
pub fn cmp() {}
9+
pub fn map() {}
10+
pub fn pop() {}
11+
pub fn ptr() {}
12+
pub fn rpo() {}
13+
pub fn drop() {}
14+
pub fn copy() {}
15+
pub fn zip() {}
16+
pub fn sup() {}
17+
pub fn pa() {}
18+
pub fn pb() {}
19+
pub fn pc() {}
20+
pub fn pd() {}
21+
pub fn pe() {}
22+
pub fn pf() {}
23+
pub fn pg() {}
24+
pub fn ph() {}
25+
pub fn pi() {}
26+
pub fn pj() {}
27+
pub fn pk() {}
28+
pub fn pl() {}
29+
pub fn pm() {}
30+
pub fn pn() {}
31+
pub fn po() {}
32+
}
33+
};
34+
($name:ident, $($names:ident),*) => {
35+
imp!($name);
36+
imp!($($names),*);
37+
};
38+
}
39+
macro_rules! en {
40+
($name:ident) => {
41+
pub enum $name {
42+
Ptr,
43+
Rp,
44+
Rpo,
45+
Pt,
46+
Drop,
47+
Dr,
48+
Dro,
49+
Sup,
50+
Op,
51+
Cmp,
52+
Map,
53+
Mp,
54+
}
55+
};
56+
($name:ident, $($names:ident),*) => {
57+
en!($name);
58+
en!($($names),*);
59+
};
60+
}
61+
62+
imp!(Ot, Foo, Cmp, Map, Loc, Lac, Toc, Si, Sig, Sip, Psy, Psi, Py, Pi, Pa, Pb, Pc, Pd);
63+
imp!(Pe, Pf, Pg, Ph, Pj, Pk, Pl, Pm, Pn, Po, Pq, Pr, Ps, Pt, Pu, Pv, Pw, Px, Pz, Ap, Bp, Cp);
64+
imp!(Dp, Ep, Fp, Gp, Hp, Ip, Jp, Kp, Lp, Mp, Np, Op, Pp, Qp, Rp, Sp, Tp, Up, Vp, Wp, Xp, Yp, Zp);
65+
66+
en!(Place, Plac, Plae, Plce, Pace, Scalar, Scalr, Scaar, Sclar, Salar);
67+
68+
pub struct P;

0 commit comments

Comments
 (0)