Skip to content

Commit 5c5ab0d

Browse files
Improve result output
1 parent 6514f44 commit 5c5ab0d

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/librustdoc/html/static/main.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@
443443
var lev_distance = MAX_LEV_DISTANCE + 1;
444444
if (obj.name === val.name) {
445445
if (literalSearch === true) {
446-
if (val.generics.length > 0) {
446+
if (val.generics.length !== 0) {
447447
if (obj.generics && obj.length >= val.generics.length) {
448448
var elems = obj.generics.slice(0);
449449
var allFound = true;
@@ -467,7 +467,8 @@
467467
}
468468
return true;
469469
}
470-
// No need to check anything else: we found it. Let's just move on.
470+
// If the type has generics but don't match, then it won't return at this point.
471+
// Otherwise, `checkGenerics` will return 0 and it'll return.
471472
var tmp_lev = checkGenerics(obj, val);
472473
if (tmp_lev <= MAX_LEV_DISTANCE) {
473474
return tmp_lev;
@@ -494,7 +495,9 @@
494495
lev_distance = min(levenshtein(obj.generics[x], val.name), lev_distance);
495496
}
496497
}
497-
return lev_distance;
498+
// Now whatever happens, the returned distance is "less good" so we should mark it
499+
// as such, and so we add 1 to the distance to make it "less good".
500+
return lev_distance + 1;
498501
}
499502

500503
function findArg(obj, val, literalSearch) {
@@ -503,7 +506,7 @@
503506
if (obj && obj.type && obj.type.inputs.length > 0) {
504507
for (var i = 0; i < obj.type.inputs.length; i++) {
505508
var tmp = checkType(obj.type.inputs[i], val, literalSearch);
506-
if (literalSearch && tmp === true) {
509+
if (literalSearch === true && tmp === true) {
507510
return true;
508511
}
509512
lev_distance = min(tmp, lev_distance);
@@ -520,7 +523,7 @@
520523

521524
if (obj && obj.type && obj.type.output) {
522525
var tmp = checkType(obj.type.output, val, literalSearch);
523-
if (literalSearch && tmp === true) {
526+
if (literalSearch === true && tmp === true) {
524527
return true;
525528
}
526529
lev_distance = min(tmp, lev_distance);

0 commit comments

Comments
 (0)