Skip to content

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

Closed

Description

@rapidfsn

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.

Activity

  1. syphar commented on Apr 11, 2025

    @syphar
    Member

    ( 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?

  2. GuillaumeGomez commented on Apr 11, 2025

    @GuillaumeGomez
    Member

    It should be on rust repository indeed. Moving it.

  3. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Apr 11, 2025
  4. added
    T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.
    A-type-based-searchArea: Searching rustdoc pages using type signatures
    on Apr 11, 2025
  5. added
    T-rustdoc-frontendRelevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.
    on Apr 11, 2025
  6. removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Apr 11, 2025
  7. GuillaumeGomez commented on Apr 11, 2025

    @GuillaumeGomez
    Member
  8. notriddle commented on Apr 11, 2025

    @notriddle
    Contributor

    This is #127589

  9. mohan314e commented on Apr 11, 2025

    @mohan314e
    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.

  10. mohan314e commented on Apr 11, 2025

    @mohan314e

    @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.

  11. notriddle commented on Apr 11, 2025

    @notriddle
    Contributor

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

  12. rapidfsn commented on Apr 11, 2025

    @rapidfsn
    Author

    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)

  13. notriddle commented on Apr 11, 2025

    @notriddle
    Contributor

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

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

  14. rapidfsn commented on Apr 11, 2025

    @rapidfsn
    Author

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

  15. added a commit that references this issue on Apr 11, 2025
    e013cf8
  16. added a commit that references this issue on Apr 12, 2025
    e0f92bb
  17. added a commit that references this issue on Apr 13, 2025
    30f9dd5
  18. added 2 commits that reference this issue on Apr 19, 2025
    b40d106
    2b92d8d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-rustdoc-searchArea: Rustdoc's search featureA-type-based-searchArea: Searching rustdoc pages using type signaturesT-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.T-rustdoc-frontendRelevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions