Skip to content

Commit

Permalink
Unrolled build for rust-lang#134277
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#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``
  • Loading branch information
rust-timer authored Dec 16, 2024
2 parents 83ab648 + 0be3ed0 commit d81191e
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 8 deletions.
2 changes: 2 additions & 0 deletions library/core/src/convert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ pub trait AsMut<T: ?Sized> {
/// [`Vec`]: ../../std/vec/struct.Vec.html
#[rustc_diagnostic_item = "Into"]
#[stable(feature = "rust1", since = "1.0.0")]
#[doc(search_unbox)]
pub trait Into<T>: Sized {
/// Converts this type into the (usually inferred) input type.
#[must_use]
Expand Down Expand Up @@ -577,6 +578,7 @@ pub trait Into<T>: 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<T>: Sized {
/// Converts to this type from the input type.
#[rustc_diagnostic_item = "from_fn"]
Expand Down
25 changes: 18 additions & 7 deletions src/doc/rustdoc/src/read-documentation/search.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,16 @@ will match these queries:
* `&mut Read -> Result<Vec<u8>, Error>`
* `Read -> Result<Vec<u8>, Error>`
* `Read -> Result<Vec<u8>>`
* `Read -> u8`
* `Read -> Vec<u8>`

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.
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,
Expand All @@ -165,6 +169,18 @@ but you need to know which one you want.

[iterator-all]: ../../std/vec/struct.Vec.html?search=Iterator<T>%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 |
Expand Down Expand Up @@ -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.
Expand Down
7 changes: 6 additions & 1 deletion src/librustdoc/html/static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
35 changes: 35 additions & 0 deletions tests/rustdoc-js/impl-trait-inlining.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// exact-check
// ignore-order

const EXPECTED = [
{
'query': 'tyctxt, symbol -> bool',
'others': [
{
'path': 'foo::TyCtxt',
'name': 'has_attr',
'displayType': "`TyCtxt`, Into<DefId>, `Symbol` -> `bool`",
},
],
},
{
'query': 'tyctxt, into<defid>, symbol -> bool',
'others': [
{
'path': 'foo::TyCtxt',
'name': 'has_attr',
'displayType': "`TyCtxt`, `Into`<`DefId`>, `Symbol` -> `bool`",
},
],
},
{
'query': 'tyctxt, defid, symbol -> bool',
'others': [
{
'path': 'foo::TyCtxt',
'name': 'has_attr',
'displayType': "`TyCtxt`, Into<`DefId`>, `Symbol` -> `bool`",
},
],
},
];
11 changes: 11 additions & 0 deletions tests/rustdoc-js/impl-trait-inlining.rs
Original file line number Diff line number Diff line change
@@ -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<DefId>, _attr: Symbol) -> bool {
unimplemented!();
}
}

0 comments on commit d81191e

Please sign in to comment.