Skip to content

Allow search to find methods involving a type even when wrapped in another type #139665

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mohantandi opened this issue Apr 8, 2025 · 10 comments · Fixed by #139688
Closed

Allow search to find methods involving a type even when wrapped in another type #139665

mohantandi opened this issue Apr 8, 2025 · 10 comments · Fixed by #139688
Labels
A-rustdoc-search Area: Rustdoc's search feature A-type-based-search Area: Searching rustdoc pages using type signatures T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.

Comments

@mohantandi
Copy link

mohantandi commented Apr 8, 2025

Currently, docs.rs search only matches exact type names. I'd like the search to include methods that return or accept a type even if that type is wrapped inside another type.

Example:
Suppose I have a struct called S, and a method defined as follows:

fn m(&self) -> E<S>

When I search for S, I expect to find this method listed in search results, even though the method returns E<S> rather than directly returning S.

Similarly, if a method takes an argument like E<S>:

fn another_method(arg: E<S>)

Then searching for S should also return another_method.

Deep/Nested Types:

This shouldn't be limited to just one level of wrapping. Ideally, the search should support multi-level nested types as well. For example:

fn complex_method() -> Arc<Mutex<S>>

This method should also show up when searching for S, despite S being deeply wrapped inside Arc and Mutex.

UI Suggestion:

If showing deeply nested matches by default is considered too noisy or expensive, it would be great to have a toggle or checkbox in the UI settings to enable "nested type search". That way, users who want deeper results can opt in when needed.

This enhancement would significantly improve the discoverability of methods and types, especially when generics and error handling wrappers are involved.

@syphar
Copy link
Member

syphar commented Apr 11, 2025

( I did some slight reformatting to make it readable).

This is a request not to docs.rs, but to rustdoc itself.

cc @GuillaumeGomez should we move it? Or does it already exist?

@GuillaumeGomez
Copy link
Member

It should be on rust repository indeed. Moving it.

@GuillaumeGomez GuillaumeGomez transferred this issue from rust-lang/docs.rs Apr 11, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 11, 2025
@GuillaumeGomez GuillaumeGomez added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. A-type-based-search Area: Searching rustdoc pages using type signatures A-rustdoc-search Area: Rustdoc's search feature labels Apr 11, 2025
@rustbot rustbot added the T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. label Apr 11, 2025
@GuillaumeGomez GuillaumeGomez removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 11, 2025
@GuillaumeGomez
Copy link
Member

cc @lolbinarycat @notriddle

@notriddle
Copy link
Contributor

This is #127589

@mohan314e
Copy link

mohan314e commented Apr 11, 2025

Image

If you look at the screenshot above, we have the metadata method inside DirEntry that returns Result<Metadata>.

I previously requested that whenever I search for Metadata, this specific method (DirEntry::metadata) should also appear in the results—but currently, it does not. See the following screenshot for reference:

Image

However, when I search specifically for Result<Metadata>, the method correctly appears, as shown in the screenshot below:

Image

To clarify once again: when I search for just Metadata, the method DirEntry::metadata should appear in the search results as well.

@mohan314e
Copy link

mohan314e commented Apr 11, 2025

@notriddle @syphar @GuillaumeGomez Please take a look at the above comment and help me if I’m doing the search incorrectly, if this feature has already been merged, or if there’s any documentation on how to use the search—please point me to it. From my perspective, nobody should need to learn how to search; it should be straightforward and intuitive. You simply search for something, and it should just appear. For example, I should be able to search for Metadata, and the DirEntry::metadata method should immediately appear, as simple as that.

@notriddle
Copy link
Contributor

You're right. In this case, it's supposed to unbox the Result, and it isn't. That's an actual bug.

@mohantandi
Copy link
Author

mohantandi commented Apr 11, 2025

Thanks! @notriddle

Could you please assign someone to address this bug? Additionally, just as a gentle reminder, the fix shouldn't be limited only to unwrapping a single generic layer, but should also handle multiple nested layers of genetics. For example, if we have a method returning a deeply nested type like Result<Option<Vec<Box<Metadata>>>>, then searching simply Metadata should still surface such method in search results which either return or take as argument this type(Metadata)

@notriddle
Copy link
Contributor

Vec isn't marked as unboxable, so that example won't work.

Result<Option<Box<Metadata>>>, however, will work.

@mohantandi
Copy link
Author

That will do the job. It is fine to skip the type which are not marked as unboxable.

ChrisDenton added a commit to ChrisDenton/rust that referenced this issue Apr 12, 2025
…x, r=GuillaumeGomez

rustdoc-search: add unbox flag to Result aliases

Fixes rust-lang#139665
@bors bors closed this as completed in e013cf8 Apr 13, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Apr 13, 2025
Rollup merge of rust-lang#139688 - rust-lang:notriddle/io-result-unbox, r=GuillaumeGomez

rustdoc-search: add unbox flag to Result aliases

Fixes rust-lang#139665
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this issue Apr 19, 2025
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this issue Apr 19, 2025
…x, r=GuillaumeGomez

rustdoc-search: add unbox flag to Result aliases

Fixes rust-lang#139665
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-search Area: Rustdoc's search feature A-type-based-search Area: Searching rustdoc pages using type signatures T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants