Skip to content

Commit d4822c2

Browse files
committedNov 11, 2024
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 12dc24f, a change to the filtering behavior, and 9900ea4, a minor ranking tweak. Part of rust-lang/rust-project-goals#112 This PR overturns #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) ![image](https://github.com/user-attachments/assets/015ae28c-7469-4f7f-be03-157d28d7ec97) ## 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> * <#124544 (comment)> * <https://rust-lang.zulipchat.com/#narrow/channel/266220-t-rustdoc/topic/deciding.20on.20semantics.20of.20generics.20in.20rustdoc.20search>
2 parents 71042b4 + 9900ea4 commit d4822c2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+1980
-851
lines changed
 

‎compiler/rustc_ast_passes/src/feature_gate.rs

+1
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
204204
"meant for internal use only" {
205205
keyword => rustdoc_internals
206206
fake_variadic => rustdoc_internals
207+
search_unbox => rustdoc_internals
207208
}
208209
);
209210
}

‎compiler/rustc_passes/messages.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ passes_doc_masked_only_extern_crate =
234234
passes_doc_rust_logo =
235235
the `#[doc(rust_logo)]` attribute is used for Rust branding
236236
237+
passes_doc_search_unbox_invalid =
238+
`#[doc(search_unbox)]` should be used on generic structs and enums
239+
237240
passes_doc_test_literal = `#![doc(test(...)]` does not take a literal
238241
239242
passes_doc_test_takes_list =

0 commit comments

Comments
 (0)
Please sign in to comment.