Skip to content

Commit 249730f

Browse files
authored
Rollup merge of #146448 - GuillaumeGomez:fix-literal-search-paths, r=lolbinarycat
[rustdoc] Correctly handle literal search on paths Fixes #146129. cc ```@notriddle``` r? ```@lolbinarycat```
2 parents 2e51a38 + 04a1dd1 commit 249730f

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3639,7 +3639,7 @@ class DocSearch {
36393639
if (contains.length === 0) {
36403640
return 0;
36413641
}
3642-
const maxPathEditDistance = Math.floor(
3642+
const maxPathEditDistance = parsedQuery.literalSearch ? 0 : Math.floor(
36433643
contains.reduce((acc, next) => acc + next.length, 0) / 3,
36443644
);
36453645
let ret_dist = maxPathEditDistance + 1;
@@ -3650,7 +3650,9 @@ class DocSearch {
36503650
let dist_total = 0;
36513651
for (let x = 0; x < clength; ++x) {
36523652
const [p, c] = [path[i + x], contains[x]];
3653-
if (Math.floor((p.length - c.length) / 3) <= maxPathEditDistance &&
3653+
if (parsedQuery.literalSearch && p !== c) {
3654+
continue pathiter;
3655+
} else if (Math.floor((p.length - c.length) / 3) <= maxPathEditDistance &&
36543656
p.indexOf(c) !== -1
36553657
) {
36563658
// discount distance on substring match

tests/rustdoc-js/literal-path.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// exact-check
2+
3+
// This test ensures that literal search is always applied on elements of the path.
4+
5+
const EXPECTED = [
6+
{
7+
'query': '"some::path"',
8+
'others': [
9+
{ 'path': 'literal_path::some', 'name': 'Path' },
10+
],
11+
},
12+
{
13+
'query': '"somea::path"',
14+
'others': [
15+
{ 'path': 'literal_path::somea', 'name': 'Path' },
16+
],
17+
},
18+
{
19+
'query': '"soma::path"',
20+
'others': [
21+
],
22+
},
23+
];

tests/rustdoc-js/literal-path.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pub mod some {
2+
pub struct Path;
3+
}
4+
5+
pub mod somea {
6+
pub struct Path;
7+
}

0 commit comments

Comments
 (0)