diff options
| author | bors <bors@rust-lang.org> | 2024-11-11 12:26:00 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-11-11 12:26:00 +0000 |
| commit | d4822c2d84c242cc7403118b50c571464f38ef8f (patch) | |
| tree | bf58926e659f32c0de796e2730a90729910a6c55 /src/doc | |
| parent | 71042b4b201a432b426304f511b3169850ed8923 (diff) | |
| parent | 9900ea48b566656fb12b5fcbd0a1b20aaa96e5ca (diff) | |
| download | rust-d4822c2d84c242cc7403118b50c571464f38ef8f.tar.gz rust-d4822c2d84c242cc7403118b50c571464f38ef8f.zip | |
Auto merge of #127589 - notriddle:notriddle/search-sem-3, r=GuillaumeGomez
rustdoc-search: simplify rules for generics and type params **Heads up!**: This PR is a follow-up that depends on #124544. It adds 12dc24f46007f82b93ed85614347a42d47580afa, a change to the filtering behavior, and 9900ea48b566656fb12b5fcbd0a1b20aaa96e5ca, a minor ranking tweak. Part of https://github.com/rust-lang/rust-project-goals/issues/112 This PR overturns https://github.com/rust-lang/rust/pull/109802 ## Preview * no results: [`Box<[A]> -> Vec<B>`](http://notriddle.com/rustdoc-html-demo-12/search-sem-3/std/index.html?search=Box%3C%5BA%5D%3E%20-%3E%20Vec%3CB%3E) * results: [`Box<[A]> -> Vec<A>`](http://notriddle.com/rustdoc-html-demo-12/search-sem-3/std/index.html?search=Box%3C%5BA%5D%3E%20-%3E%20Vec%3CA%3E) * [`T -> U`](http://notriddle.com/rustdoc-html-demo-12/search-sem-3/std/index.html?search=T%20-%3E%20U) * [`Cx -> TyCtxt`](http://notriddle.com/rustdoc-html-demo-12/search-sem-3-compiler/rustdoc/index.html?search=Cx%20-%3E%20TyCtxt)  ## Description This commit is a response to feedback on the displayed type signatures results, by making generics act stricter. - Order within generics is 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. - Generics are only "unboxed" if a type is explicitly opted into it. References and tuples are hardcoded to allow unboxing, and Box, Rc, Arc, Option, Result, and Future are opted in with an unstable attribute. Search result unboxing is the process that allows you to search for `i32 -> str` and get back a function with the type signature `&Future<i32> -> Box<str>`. - Instead of ranking by set overlap, it ranks by the number of items in the type signature. This makes it easier to find single type signatures like transmute. ## 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>
Diffstat (limited to 'src/doc')
| -rw-r--r-- | src/doc/rustdoc/src/read-documentation/search.md | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/doc/rustdoc/src/read-documentation/search.md b/src/doc/rustdoc/src/read-documentation/search.md index e912ca0fe5b..718d2201c3a 100644 --- a/src/doc/rustdoc/src/read-documentation/search.md +++ b/src/doc/rustdoc/src/read-documentation/search.md @@ -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, |
