Skip to content

Commit f28eca5

Browse files
committed
Add docs for how multiple types are handled
1 parent 6b386bc commit f28eca5

File tree

1 file changed

+28
-0
lines changed
  • src/doc/rustdoc/src/read-documentation

1 file changed

+28
-0
lines changed

src/doc/rustdoc/src/read-documentation/search.md

+28
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,30 @@ can be matched with the following queries:
115115
Each of the above queries is progressively looser, except the last one
116116
would not match `dyn Iterator`, since that's not a type parameter.
117117

118+
If a bound has multiple associated types, specifying the name allows you to
119+
pick which one gets matched. If no name is specified, then the query will
120+
match of any of them. For example,
121+
122+
```rust
123+
pub trait MyTrait {
124+
type First;
125+
type Second;
126+
}
127+
128+
/// This function can be found using the following search queries:
129+
///
130+
/// MyTrait<First=u8, Second=u32> -> bool
131+
/// MyTrait<u32, First=u8> -> bool
132+
/// MyTrait<Second=u32> -> bool
133+
/// MyTrait<u32, u8> -> bool
134+
///
135+
/// The following queries, however, will *not* match it:
136+
///
137+
/// MyTrait<First=u32> -> bool
138+
/// MyTrait<u32, u32> -> bool
139+
pub fn my_fn(x: impl MyTrait<First=u8, Second=u32>) -> bool { true }
140+
```
141+
118142
Generics and function parameters are order-agnostic, but sensitive to nesting
119143
and number of matches. For example, a function with the signature
120144
`fn read_all(&mut self: impl Read) -> Result<Vec<u8>, Error>`
@@ -143,6 +167,10 @@ Most of these limitations should be addressed in future version of Rustdoc.
143167
with that bound, it'll match, but `option<T> -> T where T: Default`
144168
cannot be precisely searched for (use `option<Default> -> Default`).
145169

170+
* Supertraits, type aliases, and Deref are all ignored. Search mostly
171+
operates on type signatures *as written*, and not as they are
172+
represented within the compiler.
173+
146174
* Type parameters match type parameters, such that `Option<A>` matches
147175
`Option<T>`, but never match concrete types in function signatures.
148176
A trait named as if it were a type, such as `Option<Read>`, will match

0 commit comments

Comments
 (0)