Skip to content

Commit 84daa9e

Browse files
authored
Unrolled build for rust-lang#133043
Rollup merge of rust-lang#133043 - notriddle:master, r=fmease rustdoc-search: case-sensitive only when capitals are used This is the "smartcase" behavior, described by vim and dtolnay. Fixes rust-lang#133017
2 parents 90ab8ea + 32500aa commit 84daa9e

File tree

4 files changed

+55
-4
lines changed

4 files changed

+55
-4
lines changed

Diff for: src/librustdoc/html/static/js/search.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -2667,6 +2667,7 @@ class DocSearch {
26672667
const sortResults = async(results, typeInfo, preferredCrate) => {
26682668
const userQuery = parsedQuery.userQuery;
26692669
const normalizedUserQuery = parsedQuery.userQuery.toLowerCase();
2670+
const isMixedCase = normalizedUserQuery !== userQuery;
26702671
const result_list = [];
26712672
for (const result of results.values()) {
26722673
result.item = this.searchIndex[result.id];
@@ -2678,10 +2679,12 @@ class DocSearch {
26782679
let a, b;
26792680

26802681
// sort by exact case-sensitive match
2681-
a = (aaa.item.name !== userQuery);
2682-
b = (bbb.item.name !== userQuery);
2683-
if (a !== b) {
2684-
return a - b;
2682+
if (isMixedCase) {
2683+
a = (aaa.item.name !== userQuery);
2684+
b = (bbb.item.name !== userQuery);
2685+
if (a !== b) {
2686+
return a - b;
2687+
}
26852688
}
26862689

26872690
// sort by exact match with regard to the last word (mismatch goes later)

Diff for: tests/rustdoc-js-std/write.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const EXPECTED = [
2+
{
3+
'query': 'write',
4+
'others': [
5+
{ 'path': 'std::fmt', 'name': 'write' },
6+
{ 'path': 'std::fs', 'name': 'write' },
7+
{ 'path': 'std::ptr', 'name': 'write' },
8+
{ 'path': 'std::fmt', 'name': 'Write' },
9+
{ 'path': 'std::io', 'name': 'Write' },
10+
{ 'path': 'std::hash::Hasher', 'name': 'write' },
11+
],
12+
},
13+
{
14+
'query': 'Write',
15+
'others': [
16+
{ 'path': 'std::fmt', 'name': 'Write' },
17+
{ 'path': 'std::io', 'name': 'Write' },
18+
{ 'path': 'std::fmt', 'name': 'write' },
19+
{ 'path': 'std::fs', 'name': 'write' },
20+
{ 'path': 'std::ptr', 'name': 'write' },
21+
{ 'path': 'std::hash::Hasher', 'name': 'write' },
22+
],
23+
},
24+
];

Diff for: tests/rustdoc-js/case.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const EXPECTED = [
2+
{
3+
'query': 'Foo',
4+
'others': [
5+
{ 'path': 'case', 'name': 'Foo', 'desc': 'Docs for Foo' },
6+
{ 'path': 'case', 'name': 'foo', 'desc': 'Docs for foo' },
7+
],
8+
},
9+
{
10+
'query': 'foo',
11+
'others': [
12+
// https://github.com/rust-lang/rust/issues/133017
13+
{ 'path': 'case', 'name': 'Foo', 'desc': 'Docs for Foo' },
14+
{ 'path': 'case', 'name': 'foo', 'desc': 'Docs for foo' },
15+
],
16+
},
17+
];

Diff for: tests/rustdoc-js/case.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![allow(nonstandard_style)]
2+
3+
/// Docs for Foo
4+
pub struct Foo;
5+
6+
/// Docs for foo
7+
pub struct foo;

0 commit comments

Comments
 (0)