rustdoc-search: simplify rules for generics and type params
This commit is a response to feedback on the displayed type signatures results, by making generics act stricter. Generics are tightened by making order significant. This means `Vec<Allocator>` now matches only with a true vector of allocators, instead of matching the second type param. It also makes unboxing within generics stricter, so `Result<A, B>` only matches if `B` is in the error type and `A` is in the success type. The top level of the function search is unaffected. Find the discussion on: * <https://rust-lang.zulipchat.com/#narrow/stream/393423-t-rustdoc.2Fmeetings/topic/meeting.202024-07-08/near/449965149> * <https://github.com/rust-lang/rust/pull/124544#issuecomment-2204272265> * <https://rust-lang.zulipchat.com/#narrow/channel/266220-t-rustdoc/topic/deciding.20on.20semantics.20of.20generics.20in.20rustdoc.20search/near/476841363>
This commit is contained in:
parent
20a4b4fea1
commit
12dc24f460
40 changed files with 630 additions and 217 deletions
|
|
@ -130,29 +130,31 @@ pub trait MyTrait {
|
|||
/// This function can be found using the following search queries:
|
||||
///
|
||||
/// MyTrait<First=u8, Second=u32> -> bool
|
||||
/// MyTrait<u32, First=u8> -> bool
|
||||
/// MyTrait<Second=u32> -> bool
|
||||
/// MyTrait<u32, u8> -> bool
|
||||
///
|
||||
/// The following queries, however, will *not* match it:
|
||||
///
|
||||
/// MyTrait<First=u32> -> bool
|
||||
/// MyTrait<u32, u32> -> bool
|
||||
/// MyTrait<u32, First=u8> -> bool
|
||||
/// MyTrait<u32, u8> -> bool
|
||||
pub fn my_fn(x: impl MyTrait<First=u8, Second=u32>) -> bool { true }
|
||||
```
|
||||
|
||||
Generics and function parameters are order-agnostic, but sensitive to nesting
|
||||
Function parameters are order-agnostic, but sensitive to nesting
|
||||
and number of matches. For example, a function with the signature
|
||||
`fn read_all(&mut self: impl Read) -> Result<Vec<u8>, Error>`
|
||||
will match these queries:
|
||||
|
||||
* `&mut Read -> Result<Vec<u8>, Error>`
|
||||
* `Read -> Result<Vec<u8>, Error>`
|
||||
* `Read -> Result<Error, Vec>`
|
||||
* `Read -> Result<Vec<u8>>`
|
||||
* `Read -> u8`
|
||||
|
||||
But it *does not* match `Result<Vec, u8>` or `Result<u8<Vec>>`.
|
||||
But it *does not* match `Result<Vec, u8>` or `Result<u8<Vec>>`,
|
||||
because those are nested incorrectly, and it does not match
|
||||
`Result<Error, Vec<u8>>` or `Result<Error>`, because those are
|
||||
in the wrong order.
|
||||
|
||||
To search for a function that accepts a function as a parameter,
|
||||
like `Iterator::all`, wrap the nested signature in parenthesis,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue