Skip to content

Commit d9ba4bf

Browse files
authored
Rollup merge of #134277 - notriddle:notriddle/inline-into, r=GuillaumeGomez
rustdoc-search: handle `impl Into<X>` better This PR fixes two bugs I ran into while searching the compiler docs: - It omitted an `impl Trait` entry in the type signature field, producing `TyCtxt, , Symbol -> bool` - It didn't let me search for `TyCtxt, DefId, Symbol -> bool` even though that's a perfectly good description of the function I was looking for (the function actually used `impl Into<DefId>` r? ``@GuillaumeGomez`` cc ``@lolbinarycat``
2 parents 9451a61 + 0be3ed0 commit d9ba4bf

File tree

5 files changed

+72
-8
lines changed

5 files changed

+72
-8
lines changed

library/core/src/convert/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ pub trait AsMut<T: ?Sized> {
443443
/// [`Vec`]: ../../std/vec/struct.Vec.html
444444
#[rustc_diagnostic_item = "Into"]
445445
#[stable(feature = "rust1", since = "1.0.0")]
446+
#[doc(search_unbox)]
446447
pub trait Into<T>: Sized {
447448
/// Converts this type into the (usually inferred) input type.
448449
#[must_use]
@@ -577,6 +578,7 @@ pub trait Into<T>: Sized {
577578
all(_Self = "&str", T = "alloc::string::String"),
578579
note = "to coerce a `{T}` into a `{Self}`, use `&*` as a prefix",
579580
))]
581+
#[doc(search_unbox)]
580582
pub trait From<T>: Sized {
581583
/// Converts to this type from the input type.
582584
#[rustc_diagnostic_item = "from_fn"]

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

+18-7
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,16 @@ will match these queries:
149149
* `&mut Read -> Result<Vec<u8>, Error>`
150150
* `Read -> Result<Vec<u8>, Error>`
151151
* `Read -> Result<Vec<u8>>`
152-
* `Read -> u8`
152+
* `Read -> Vec<u8>`
153153

154154
But it *does not* match `Result<Vec, u8>` or `Result<u8<Vec>>`,
155155
because those are nested incorrectly, and it does not match
156156
`Result<Error, Vec<u8>>` or `Result<Error>`, because those are
157-
in the wrong order.
157+
in the wrong order. It also does not match `Read -> u8`, because
158+
only [certain generic wrapper types] can be left out, and `Vec` isn't
159+
one of them.
160+
161+
[certain generic wrapper types]: #wrappers-that-can-be-omitted
158162

159163
To search for a function that accepts a function as a parameter,
160164
like `Iterator::all`, wrap the nested signature in parenthesis,
@@ -165,6 +169,18 @@ but you need to know which one you want.
165169

166170
[iterator-all]: ../../std/vec/struct.Vec.html?search=Iterator<T>%2C+(T+->+bool)+->+bool&filter-crate=std
167171

172+
### Wrappers that can be omitted
173+
174+
* References
175+
* Box
176+
* Rc
177+
* Arc
178+
* Option
179+
* Result
180+
* From
181+
* Into
182+
* Future
183+
168184
### Primitives with Special Syntax
169185

170186
| Shorthand | Explicit names |
@@ -234,11 +250,6 @@ Most of these limitations should be addressed in future version of Rustdoc.
234250
that you don't want a type parameter, you can force it to match
235251
something else by giving it a different prefix like `struct:T`.
236252

237-
* It's impossible to search for references or pointers. The
238-
wrapped types can be searched for, so a function that takes `&File` can
239-
be found with `File`, but you'll get a parse error when typing an `&`
240-
into the search field.
241-
242253
* Searching for lifetimes is not supported.
243254

244255
* It's impossible to search based on the length of an array.

src/librustdoc/html/static/js/search.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -2592,7 +2592,12 @@ class DocSearch {
25922592
const writeFn = (fnType, result) => {
25932593
if (fnType.id < 0) {
25942594
if (fnParamNames[-1 - fnType.id] === "") {
2595-
for (const nested of fnType.generics) {
2595+
// Normally, there's no need to shown an unhighlighted
2596+
// where clause, but if it's impl Trait, then we do.
2597+
const generics = fnType.generics.length > 0 ?
2598+
fnType.generics :
2599+
obj.type.where_clause[-1 - fnType.id];
2600+
for (const nested of generics) {
25962601
writeFn(nested, result);
25972602
}
25982603
return;
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// exact-check
2+
// ignore-order
3+
4+
const EXPECTED = [
5+
{
6+
'query': 'tyctxt, symbol -> bool',
7+
'others': [
8+
{
9+
'path': 'foo::TyCtxt',
10+
'name': 'has_attr',
11+
'displayType': "`TyCtxt`, Into<DefId>, `Symbol` -> `bool`",
12+
},
13+
],
14+
},
15+
{
16+
'query': 'tyctxt, into<defid>, symbol -> bool',
17+
'others': [
18+
{
19+
'path': 'foo::TyCtxt',
20+
'name': 'has_attr',
21+
'displayType': "`TyCtxt`, `Into`<`DefId`>, `Symbol` -> `bool`",
22+
},
23+
],
24+
},
25+
{
26+
'query': 'tyctxt, defid, symbol -> bool',
27+
'others': [
28+
{
29+
'path': 'foo::TyCtxt',
30+
'name': 'has_attr',
31+
'displayType': "`TyCtxt`, Into<`DefId`>, `Symbol` -> `bool`",
32+
},
33+
],
34+
},
35+
];
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![crate_name = "foo"]
2+
3+
pub struct TyCtxt;
4+
pub struct DefId;
5+
pub struct Symbol;
6+
7+
impl TyCtxt {
8+
pub fn has_attr(self, _did: impl Into<DefId>, _attr: Symbol) -> bool {
9+
unimplemented!();
10+
}
11+
}

0 commit comments

Comments
 (0)