]> git.lizzy.rs Git - rust.git/commitdiff
Improve result output
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Sat, 11 Nov 2017 22:53:37 +0000 (23:53 +0100)
committerGuillaume Gomez <guillaume1.gomez@gmail.com>
Sun, 12 Nov 2017 20:38:24 +0000 (21:38 +0100)
src/librustdoc/html/static/main.js

index 0d3d52ead173b23a8a4d4ca38003764630583545..7cc06760162681def5a1da53a8438df6bf7cde58 100644 (file)
                 var lev_distance = MAX_LEV_DISTANCE + 1;
                 if (obj.name === val.name) {
                     if (literalSearch === true) {
-                        if (val.generics.length > 0) {
+                        if (val.generics.length !== 0) {
                             if (obj.generics && obj.length >= val.generics.length) {
                                 var elems = obj.generics.slice(0);
                                 var allFound = true;
                         }
                         return true;
                     }
-                    // No need to check anything else: we found it. Let's just move on.
+                    // If the type has generics but don't match, then it won't return at this point.
+                    // Otherwise, `checkGenerics` will return 0 and it'll return.
                     var tmp_lev = checkGenerics(obj, val);
                     if (tmp_lev <= MAX_LEV_DISTANCE) {
                         return tmp_lev;
                         lev_distance = min(levenshtein(obj.generics[x], val.name), lev_distance);
                     }
                 }
-                return lev_distance;
+                // Now whatever happens, the returned distance is "less good" so we should mark it
+                // as such, and so we add 1 to the distance to make it "less good".
+                return lev_distance + 1;
             }
 
             function findArg(obj, val, literalSearch) {
                 if (obj && obj.type && obj.type.inputs.length > 0) {
                     for (var i = 0; i < obj.type.inputs.length; i++) {
                         var tmp = checkType(obj.type.inputs[i], val, literalSearch);
-                        if (literalSearch && tmp === true) {
+                        if (literalSearch === true && tmp === true) {
                             return true;
                         }
                         lev_distance = min(tmp, lev_distance);
 
                 if (obj && obj.type && obj.type.output) {
                     var tmp = checkType(obj.type.output, val, literalSearch);
-                    if (literalSearch && tmp === true) {
+                    if (literalSearch === true && tmp === true) {
                         return true;
                     }
                     lev_distance = min(tmp, lev_distance);