diff options
| author | bors <bors@rust-lang.org> | 2023-06-11 14:48:58 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-06-11 14:48:58 +0000 |
| commit | 81c02da94e5f5ec1ec4732e75049c3a3cb4d6c7a (patch) | |
| tree | b75fa323bca90f358829f4b42ecce4333417ce0e /tests/rustdoc-js-std/parser-slice-array.js | |
| parent | 7b6093ee0805570d1af441673ebce409f8a14587 (diff) | |
| parent | d3a4cd68130c8aaed7ce5a4d0a58861b66c72eea (diff) | |
| download | rust-81c02da94e5f5ec1ec4732e75049c3a3cb4d6c7a.tar.gz rust-81c02da94e5f5ec1ec4732e75049c3a3cb4d6c7a.zip | |
Auto merge of #111958 - notriddle:notriddle/type-search-slice-array, r=GuillaumeGomez
rustdoc: search for slices and arrays by type with `[]` This feature extends rustdoc to support the syntax that most users will naturally attempt to use to search for slices and arrays. Part of #60485 Function signature searches already support arrays and slices. The explicit name `primitive:slice<u8>` and `primitive:array<u8>` can be used to match a slice or array of bytes, while square brackets `[u8]` will match either one. Empty square brackets, `[]`, will match any slice regardless of what it contains. Preview: * [`option -> []`](https://notriddle.com/rustdoc-demo-html-3/search-slice-array/std/index.html?search=option%20-%3E%20%5B%5D) * [`[u8] -> str`](https://notriddle.com/rustdoc-demo-html-3/search-slice-array/std/index.html?search=%5Bu8%5D%20-%3E%20str) * [`Box<[u8]> -> str`](https://notriddle.com/rustdoc-demo-html-3/search-slice-array/std/index.html?search=Box%3C%5Bu8%5D%3E%20-%3E%20str) Motivation: When type-based search was first landed, it was directly described as "incomplete". Here's [a comment] from the discussion thread: [a comment]: https://github.com/rust-lang/rust/pull/23289#issuecomment-79437386 > This is looking really great, nice work! I can think of a number of cases that aren't quite covered by this, but I feel like this is a great improvement regardless and it can always be iterated on so I'm fine landing with a few known cases where it may not work :) Filling out the missing functionality is going to mean adding support for more of Rust's [type expression] syntax, such as slices (in this PR), tuples, references, raw pointers, function pointers, and generics. [type expression]: https://doc.rust-lang.org/reference/types.html#type-expressions There does seem to be demand for this sort of thing, such as [this Discord message](https://discord.com/channels/442252698964721669/443150878111694848/1042145740065099796) expressing regret at rustdoc not supporting tuples in search queries.
Diffstat (limited to 'tests/rustdoc-js-std/parser-slice-array.js')
| -rw-r--r-- | tests/rustdoc-js-std/parser-slice-array.js | 305 |
1 files changed, 305 insertions, 0 deletions
diff --git a/tests/rustdoc-js-std/parser-slice-array.js b/tests/rustdoc-js-std/parser-slice-array.js new file mode 100644 index 00000000000..f85dd199741 --- /dev/null +++ b/tests/rustdoc-js-std/parser-slice-array.js @@ -0,0 +1,305 @@ +const PARSED = [ + { + query: '[[[D, []]]', + elems: [], + foundElems: 0, + original: '[[[D, []]]', + returned: [], + userQuery: '[[[d, []]]', + error: 'Unclosed `[`', + }, + { + query: '[[[D, []]]]', + elems: [ + { + name: "[]", + fullPath: ["[]"], + pathWithoutLast: [], + pathLast: "[]", + generics: [ + { + name: "[]", + fullPath: ["[]"], + pathWithoutLast: [], + pathLast: "[]", + generics: [ + { + name: "[]", + fullPath: ["[]"], + pathWithoutLast: [], + pathLast: "[]", + generics: [ + { + name: "d", + fullPath: ["d"], + pathWithoutLast: [], + pathLast: "d", + generics: [], + typeFilter: -1, + }, + { + name: "[]", + fullPath: ["[]"], + pathWithoutLast: [], + pathLast: "[]", + generics: [], + typeFilter: 15, + }, + ], + typeFilter: 15, + }, + ], + typeFilter: 15, + }, + ], + typeFilter: 15, + }, + ], + foundElems: 1, + original: '[[[D, []]]]', + returned: [], + userQuery: '[[[d, []]]]', + error: null, + }, + { + query: '[] u8', + elems: [ + { + name: "[]", + fullPath: ["[]"], + pathWithoutLast: [], + pathLast: "[]", + generics: [], + typeFilter: 15, + }, + { + name: "u8", + fullPath: ["u8"], + pathWithoutLast: [], + pathLast: "u8", + generics: [], + typeFilter: -1, + }, + ], + foundElems: 2, + original: "[] u8", + returned: [], + userQuery: "[] u8", + error: null, + }, + { + query: '[u8]', + elems: [ + { + name: "[]", + fullPath: ["[]"], + pathWithoutLast: [], + pathLast: "[]", + generics: [ + { + name: "u8", + fullPath: ["u8"], + pathWithoutLast: [], + pathLast: "u8", + generics: [], + typeFilter: -1, + }, + ], + typeFilter: 15, + }, + ], + foundElems: 1, + original: "[u8]", + returned: [], + userQuery: "[u8]", + error: null, + }, + { + query: '[u8,u8]', + elems: [ + { + name: "[]", + fullPath: ["[]"], + pathWithoutLast: [], + pathLast: "[]", + generics: [ + { + name: "u8", + fullPath: ["u8"], + pathWithoutLast: [], + pathLast: "u8", + generics: [], + typeFilter: -1, + }, + { + name: "u8", + fullPath: ["u8"], + pathWithoutLast: [], + pathLast: "u8", + generics: [], + typeFilter: -1, + }, + ], + typeFilter: 15, + }, + ], + foundElems: 1, + original: "[u8,u8]", + returned: [], + userQuery: "[u8,u8]", + error: null, + }, + { + query: '[u8<u8>]', + elems: [ + { + name: "[]", + fullPath: ["[]"], + pathWithoutLast: [], + pathLast: "[]", + generics: [ + { + name: "u8", + fullPath: ["u8"], + pathWithoutLast: [], + pathLast: "u8", + generics: [ + { + name: "u8", + fullPath: ["u8"], + pathWithoutLast: [], + pathLast: "u8", + generics: [], + typeFilter: -1, + }, + ], + typeFilter: -1, + }, + ], + typeFilter: 15, + }, + ], + foundElems: 1, + original: "[u8<u8>]", + returned: [], + userQuery: "[u8<u8>]", + error: null, + }, + { + query: '[]', + elems: [ + { + name: "[]", + fullPath: ["[]"], + pathWithoutLast: [], + pathLast: "[]", + generics: [], + typeFilter: 15, + }, + ], + foundElems: 1, + original: "[]", + returned: [], + userQuery: "[]", + error: null, + }, + { + query: '[>', + elems: [], + foundElems: 0, + original: "[>", + returned: [], + userQuery: "[>", + error: "Unexpected `>` after `[`", + }, + { + query: '[<', + elems: [], + foundElems: 0, + original: "[<", + returned: [], + userQuery: "[<", + error: "Found generics without a path", + }, + { + query: '[a>', + elems: [], + foundElems: 0, + original: "[a>", + returned: [], + userQuery: "[a>", + error: "Unexpected `>` after `[`", + }, + { + query: '[a<', + elems: [], + foundElems: 0, + original: "[a<", + returned: [], + userQuery: "[a<", + error: "Unclosed `<`", + }, + { + query: '[a', + elems: [], + foundElems: 0, + original: "[a", + returned: [], + userQuery: "[a", + error: "Unclosed `[`", + }, + { + query: '[', + elems: [], + foundElems: 0, + original: "[", + returned: [], + userQuery: "[", + error: "Unclosed `[`", + }, + { + query: ']', + elems: [], + foundElems: 0, + original: "]", + returned: [], + userQuery: "]", + error: "Unexpected `]`", + }, + { + query: 'primitive:[u8]', + elems: [ + { + name: "[]", + fullPath: ["[]"], + pathWithoutLast: [], + pathLast: "[]", + generics: [ + { + name: "u8", + fullPath: ["u8"], + pathWithoutLast: [], + pathLast: "u8", + generics: [], + typeFilter: -1, + }, + ], + typeFilter: 15, + }, + ], + foundElems: 1, + original: "primitive:[u8]", + returned: [], + userQuery: "primitive:[u8]", + error: null, + }, + { + query: 'macro:[u8]', + elems: [], + foundElems: 0, + original: "macro:[u8]", + returned: [], + userQuery: "macro:[u8]", + error: "Invalid search type: primitive `[]` and `macro` both specified", + }, +]; |
