From f068d8b809e09f4c685bddeebfe63e736a02d473 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Fri, 13 Dec 2024 10:47:02 -0700 Subject: [PATCH 1/3] rustdoc-search: show `impl Trait` inline when unhighlighted While normal generics can be skipped in this case, no-names need something to show here. Before: `TyCtxt, , Symbol -> bool` After: `TyCtxt, Into, Symbol -> bool` --- src/librustdoc/html/static/js/search.js | 7 ++++++- tests/rustdoc-js/impl-trait-inlining.js | 25 +++++++++++++++++++++++++ tests/rustdoc-js/impl-trait-inlining.rs | 11 +++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 tests/rustdoc-js/impl-trait-inlining.js create mode 100644 tests/rustdoc-js/impl-trait-inlining.rs diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index 9e5cf49721139..04eeee37fe8ee 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -2592,7 +2592,12 @@ class DocSearch { const writeFn = (fnType, result) => { if (fnType.id < 0) { if (fnParamNames[-1 - fnType.id] === "") { - for (const nested of fnType.generics) { + // Normally, there's no need to shown an unhighlighted + // where clause, but if it's impl Trait, then we do. + const generics = fnType.generics.length > 0 ? + fnType.generics : + obj.type.where_clause[-1 - fnType.id]; + for (const nested of generics) { writeFn(nested, result); } return; diff --git a/tests/rustdoc-js/impl-trait-inlining.js b/tests/rustdoc-js/impl-trait-inlining.js new file mode 100644 index 0000000000000..02c9853dd63fe --- /dev/null +++ b/tests/rustdoc-js/impl-trait-inlining.js @@ -0,0 +1,25 @@ +// exact-check +// ignore-order + +const EXPECTED = [ + { + 'query': 'tyctxt, symbol -> bool', + 'others': [ + { + 'path': 'foo::TyCtxt', + 'name': 'has_attr', + 'displayType': "`TyCtxt`, Into, `Symbol` -> `bool`", + }, + ], + }, + { + 'query': 'tyctxt, into, symbol -> bool', + 'others': [ + { + 'path': 'foo::TyCtxt', + 'name': 'has_attr', + 'displayType': "`TyCtxt`, `Into`<`DefId`>, `Symbol` -> `bool`", + }, + ], + }, +]; diff --git a/tests/rustdoc-js/impl-trait-inlining.rs b/tests/rustdoc-js/impl-trait-inlining.rs new file mode 100644 index 0000000000000..a6ca0dcbd8ddd --- /dev/null +++ b/tests/rustdoc-js/impl-trait-inlining.rs @@ -0,0 +1,11 @@ +#![crate_name="foo"] + +pub struct TyCtxt; +pub struct DefId; +pub struct Symbol; + +impl TyCtxt { + pub fn has_attr(self, _did: impl Into, _attr: Symbol) -> bool { + unimplemented!(); + } +} From 246835eda4a89bb09842ebc67776fedb6e3aba78 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Fri, 13 Dec 2024 11:05:30 -0700 Subject: [PATCH 2/3] rustdoc-search: let From and Into be unboxed --- library/core/src/convert/mod.rs | 2 ++ tests/rustdoc-js/impl-trait-inlining.js | 10 ++++++++++ tests/rustdoc-js/impl-trait-inlining.rs | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/library/core/src/convert/mod.rs b/library/core/src/convert/mod.rs index 432e55e8c9a4c..e468f4f0f7e66 100644 --- a/library/core/src/convert/mod.rs +++ b/library/core/src/convert/mod.rs @@ -443,6 +443,7 @@ pub trait AsMut { /// [`Vec`]: ../../std/vec/struct.Vec.html #[rustc_diagnostic_item = "Into"] #[stable(feature = "rust1", since = "1.0.0")] +#[doc(search_unbox)] pub trait Into: Sized { /// Converts this type into the (usually inferred) input type. #[must_use] @@ -577,6 +578,7 @@ pub trait Into: Sized { all(_Self = "&str", T = "alloc::string::String"), note = "to coerce a `{T}` into a `{Self}`, use `&*` as a prefix", ))] +#[doc(search_unbox)] pub trait From: Sized { /// Converts to this type from the input type. #[rustc_diagnostic_item = "from_fn"] diff --git a/tests/rustdoc-js/impl-trait-inlining.js b/tests/rustdoc-js/impl-trait-inlining.js index 02c9853dd63fe..e97669c7b3082 100644 --- a/tests/rustdoc-js/impl-trait-inlining.js +++ b/tests/rustdoc-js/impl-trait-inlining.js @@ -22,4 +22,14 @@ const EXPECTED = [ }, ], }, + { + 'query': 'tyctxt, defid, symbol -> bool', + 'others': [ + { + 'path': 'foo::TyCtxt', + 'name': 'has_attr', + 'displayType': "`TyCtxt`, Into<`DefId`>, `Symbol` -> `bool`", + }, + ], + }, ]; diff --git a/tests/rustdoc-js/impl-trait-inlining.rs b/tests/rustdoc-js/impl-trait-inlining.rs index a6ca0dcbd8ddd..f90fb72659ae7 100644 --- a/tests/rustdoc-js/impl-trait-inlining.rs +++ b/tests/rustdoc-js/impl-trait-inlining.rs @@ -1,4 +1,4 @@ -#![crate_name="foo"] +#![crate_name = "foo"] pub struct TyCtxt; pub struct DefId; From 0be3ed0d8fe9e74963117db7c2d93d383cfcacc4 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Fri, 13 Dec 2024 11:05:48 -0700 Subject: [PATCH 3/3] rustdoc-search: update documentation with notes about unboxing --- .../rustdoc/src/read-documentation/search.md | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/doc/rustdoc/src/read-documentation/search.md b/src/doc/rustdoc/src/read-documentation/search.md index 718d2201c3a5d..e06dcdb7ed2fb 100644 --- a/src/doc/rustdoc/src/read-documentation/search.md +++ b/src/doc/rustdoc/src/read-documentation/search.md @@ -149,12 +149,16 @@ will match these queries: * `&mut Read -> Result, Error>` * `Read -> Result, Error>` * `Read -> Result>` -* `Read -> u8` +* `Read -> Vec` But it *does not* match `Result` or `Result>`, because those are nested incorrectly, and it does not match `Result>` or `Result`, because those are -in the wrong order. +in the wrong order. It also does not match `Read -> u8`, because +only [certain generic wrapper types] can be left out, and `Vec` isn't +one of them. + +[certain generic wrapper types]: #wrappers-that-can-be-omitted To search for a function that accepts a function as a parameter, like `Iterator::all`, wrap the nested signature in parenthesis, @@ -165,6 +169,18 @@ but you need to know which one you want. [iterator-all]: ../../std/vec/struct.Vec.html?search=Iterator%2C+(T+->+bool)+->+bool&filter-crate=std +### Wrappers that can be omitted + +* References +* Box +* Rc +* Arc +* Option +* Result +* From +* Into +* Future + ### Primitives with Special Syntax | Shorthand | Explicit names | @@ -234,11 +250,6 @@ 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 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. - * Searching for lifetimes is not supported. * It's impossible to search based on the length of an array.