about summary refs log tree commit diff
path: root/src/doc
diff options
context:
space:
mode:
authorMichael Howell <michael@notriddle.com>2023-09-29 12:52:30 -0700
committerMichael Howell <michael@notriddle.com>2023-12-26 12:54:17 -0700
commitf6a045cc6b24dd033c207dd63d8adccdedf672d2 (patch)
tree7ccbf87bff8e0dc808f45d9d9393cbab4a093be3 /src/doc
parenta75fed74b62f95d1659ff70bea7895ed5c85bdba (diff)
downloadrust-f6a045cc6b24dd033c207dd63d8adccdedf672d2.tar.gz
rust-f6a045cc6b24dd033c207dd63d8adccdedf672d2.zip
rustdoc: search for tuples and unit by type with `()`
Diffstat (limited to 'src/doc')
-rw-r--r--src/doc/rustdoc/src/read-documentation/search.md67
1 files changed, 56 insertions, 11 deletions
diff --git a/src/doc/rustdoc/src/read-documentation/search.md b/src/doc/rustdoc/src/read-documentation/search.md
index 1f45bd6c6b8..d773794504e 100644
--- a/src/doc/rustdoc/src/read-documentation/search.md
+++ b/src/doc/rustdoc/src/read-documentation/search.md
@@ -150,12 +150,55 @@ will match these queries:
 
 But it *does not* match `Result<Vec, u8>` or `Result<u8<Vec>>`.
 
-Function signature searches also 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 or array regardless of what
-it contains, while a slice with a type parameter, like `[T]`, will only match
-functions that actually operate on generic slices.
+### Primitives with Special Syntax
+
+<table>
+<thead>
+  <tr>
+    <th>Shorthand</th>
+    <th>Explicit names</th>
+  </tr>
+</thead>
+<tbody>
+  <tr>
+    <td><code>[]</code></td>
+    <td><code>primitive:slice</code> and/or <code>primitive:array</code></td>
+  </tr>
+  <tr>
+    <td><code>[T]</code></td>
+    <td><code>primitive:slice&lt;T&gt;</code> and/or <code>primitive:array&lt;T&gt;</code></td>
+  </tr>
+  <tr>
+    <td><code>()</code></td>
+    <td><code>primitive:unit</code> and/or <code>primitive:tuple</code></td>
+  </tr>
+  <tr>
+    <td><code>(T)</code></td>
+    <td><code>T</code></td>
+  </tr>
+  <tr>
+    <td><code>(T,)</code></td>
+    <td><code>primitive:tuple&lt;T&gt;</code></td>
+  </tr>
+  <tr>
+    <td><code>!</code></td>
+    <td><code>primitive:never</code></td>
+  </tr>
+</tbody>
+</table>
+
+When searching for `[]`, Rustdoc will return search results with either slices
+or arrays. If you know which one you want, you can force it to return results
+for `primitive:slice` or `primitive:array` using the explicit name syntax.
+Empty square brackets, `[]`, will match any slice or array regardless of what
+it contains, or an item type can be provided, such as `[u8]` or `[T]`, to
+explicitly find functions that operate on byte slices or generic slices,
+respectively.
+
+A single type expression wrapped in parens is the same as that type expression,
+since parens act as the grouping operator. If they're empty, though, they will
+match both `unit` and `tuple`, and if there's more than one type (or a trailing
+or leading comma) it is the same as `primitive:tuple<...>`.
 
 ### Limitations and quirks of type-based search
 
@@ -188,11 +231,10 @@ Most of these limitations should be addressed in future version of Rustdoc.
     that you don't want a type parameter, you can force it to match
     something else by giving it a different prefix like `struct:T`.
 
-  * It's impossible to search for references, pointers, or tuples. The
+  * It's impossible to search for references or pointers. The
     wrapped types can be searched for, so a function that takes `&File` can
     be found with `File`, but you'll get a parse error when typing an `&`
-    into the search field. Similarly, `Option<(T, U)>` can be matched with
-    `Option<T, U>`, but `(` will give a parse error.
+    into the search field.
 
   * Searching for lifetimes is not supported.
 
@@ -216,8 +258,9 @@ Item filters can be used in both name-based and type signature-based searches.
 ```text
 ident = *(ALPHA / DIGIT / "_")
 path = ident *(DOUBLE-COLON ident) [!]
-slice = OPEN-SQUARE-BRACKET [ nonempty-arg-list ] CLOSE-SQUARE-BRACKET
-arg = [type-filter *WS COLON *WS] (path [generics] / slice / [!])
+slice-like = OPEN-SQUARE-BRACKET [ nonempty-arg-list ] CLOSE-SQUARE-BRACKET
+tuple-like = OPEN-PAREN [ nonempty-arg-list ] CLOSE-PAREN
+arg = [type-filter *WS COLON *WS] (path [generics] / slice-like / tuple-like / [!])
 type-sep = COMMA/WS *(COMMA/WS)
 nonempty-arg-list = *(type-sep) arg *(type-sep arg) *(type-sep)
 generic-arg-list = *(type-sep) arg [ EQUAL arg ] *(type-sep arg [ EQUAL arg ]) *(type-sep)
@@ -263,6 +306,8 @@ OPEN-ANGLE-BRACKET = "<"
 CLOSE-ANGLE-BRACKET = ">"
 OPEN-SQUARE-BRACKET = "["
 CLOSE-SQUARE-BRACKET = "]"
+OPEN-PAREN = "("
+CLOSE-PAREN = ")"
 COLON = ":"
 DOUBLE-COLON = "::"
 QUOTE = %x22