about summary refs log tree commit diff
path: root/tests/rustdoc-js-std
AgeCommit message (Collapse)AuthorLines
2025-10-02fix rustdoc tests broke by trait item filteringbinarycat-15/+13
2025-08-21tests/rustdoc-js-std/parser-errors.js: remove syntax that is now validbinarycat-8/+0
2025-08-15rustdoc-search: search backend with partitioned suffix treeMichael Howell-221/+225
2025-08-14Revert "rustdoc search: prefer stable items in search results"Guillaume Gomez-3/+3
This reverts commit 1140e90074b0cbcfdea8535e4b51877e2838227e.
2025-08-09Rollup merge of #141658 - lolbinarycat:rustdoc-search-stability-rank-138067, ↵Stuart Cook-3/+3
r=GuillaumeGomez rustdoc search: prefer stable items in search results fixes https://github.com/rust-lang/rust/issues/138067 this does add a new field to the search index, but since we're only listing unstable items instead of adding a boolean flag to every item, it should only increase the search index size of sysroot crates, since those are the only ones using the `staged_api` feature, at least as far as the rust project is concerned.
2025-07-16Add test for aliases partial matchGuillaume Gomez-0/+11
2025-06-20add doc(alias("AsciiChar")) to core::ascii::Charbinarycat-0/+12
Added it to the reexported, which is intended rustdoc behavior, but is apparently untested, so I also added a test for it.
2025-06-10rustdoc search: prefer stable items in search resultsbinarycat-3/+3
fixes https://github.com/rust-lang/rust/issues/138067
2025-05-05Consistent trait bounds for ExtractIf Debug implsDavid Tolnay-1/+1
2025-04-11rustdoc-search: add unbox flag to Result aliasesMichael Howell-0/+20
Fixes #139665
2025-02-11Remove the common prelude moduleEric Huss-1/+1
This fixes the issues described in https://github.com/rust-lang/rust/issues/136102. Primarily, this resolves some issues with how the documentation for the prelude is generated: - It avoids showing "unstable" for macros in the prelude that are actually stable. - Avoids duplication of some pages due to the previous lack of `doc(no_inline)`. - Makes the different edition preludes consistent, and sets a pattern that can be used by future editions. We may need to rearrange these modules in the future if we decide to remove anything from the prelude again. If we do, I think we should look into a different solution that avoids the documentation problems.
2025-01-16Treat other items as functions for the purpose of type-based searchbinarycat-0/+14
constants and statics are nullary functions, and struct fields are unary functions. functions (along with methods and trait methods) are prioritized over other items, like fields and constants.
2025-01-13for purely return-type based searches, deprioritize clone-like functionsbinarycat-0/+30
A clone-like function in a function that takes as an argument the type that it returns. However, functions that return a type variable are not counted as clone-line. Because we're not unifying the whole function at once, a function like `U -> T` would otherwise be counted as "clone-like" because the generics will just unify with anything when done seperatly. Co-authored-by: Michael Howell <michael@notriddle.com>
2025-01-02rustdoc: treat `allowed_through_unstable_modules` as deprecationMichael Howell-2/+15
This ensures `std::intrinsics::transmute` is deemphasized in the search engine and other UI, by cleaning it into a deprecation without propagating it through reexports when the parent module is stable.
2024-12-26Adjust test for slightly changed inlining behaviorMichael Howell-29/+29
2024-12-13rustdoc-search: update test with now-shorter function pathMichael Howell-1/+1
Both paths are correct. This one's better.
2024-11-15rustdoc search: allow queries to end in an empty path segmentbinarycat-8/+6
fixes https://github.com/rust-lang/rust/issues/129707 this can be used to show all items in a module, or all associated items for a type. currently sufferes slightly due to case insensitivity, so `Option::` will also show items in the `option::` module. it disables the checking of the last path element, otherwise only items with short names will be shown
2024-11-14Auto merge of #133047 - matthiaskrgr:rollup-9se1vth, r=matthiaskrgrbors-0/+24
Rollup of 4 pull requests Successful merges: - #128197 (Skip locking span interner for some syntax context checks) - #133040 ([rustdoc] Fix handling of footnote reference in footnote definition) - #133043 (rustdoc-search: case-sensitive only when capitals are used) - #133046 (Clippy subtree update) r? `@ghost` `@rustbot` modify labels: rollup
2024-11-14rustdoc-search: case-sensitive only when capitals are usedMichael Howell-0/+24
This is the "smartcase" behavior, described by vim and dtolnay.
2024-11-13rustdoc: use a trie for name-based searchMichael Howell-11/+2
Preview and profiler results ---------------------------- Here's some quick profiling in Firefox done on the rust compiler docs: - Before: https://share.firefox.dev/3UPm3M8 - After: https://share.firefox.dev/40LXvYb Here's the results for the node.js profiler: - https://notriddle.com/rustdoc-html-demo-15/trie-perf/index.html Here's a copy that you can use to try it out. Compare it with [the nightly]. Try typing `typecheckercontext` one character at a time, slowly. - https://notriddle.com/rustdoc-html-demo-15/compiler-doc-trie/index.html [the nightly]: https://doc.rust-lang.org/nightly/nightly-rustc/ The fuzzy match algo is based on [Fast String Correction with Levenshtein-Automata] and the corresponding implementation code in [moman] and [Lucene]; the bit-packing representation comes from Lucene, but the actual matcher is more based on `fsc.py`. As suggested in the paper, a trie is used to represent the FSA dictionary. The same trie is used for prefix matching. Substring matching is done with a side table of three-character[^1] windows that point into the trie. [Fast String Correction with Levenshtein-Automata]: https://github.com/tpn/pdfs/blob/master/Fast%20String%20Correction%20with%20Levenshtein-Automata%20(2002)%20(10.1.1.16.652).pdf [Lucene]: https://fossies.org/linux/lucene/lucene/core/src/java/org/apache/lucene/util/automaton/Lev1TParametricDescription.java [moman]: https://gitlab.com/notriddle/moman-rustdoc User-visible changes -------------------- I don't expect anybody to notice anything, but it does cause two changes: - Substring matches, in the middle of a name, only apply if there's three or more characters in the search query. - Levenshtein distance limit now maxes out at two. In the old version, the limit was w/3, so you could get looser matches for queries with 9 or more characters[^1] in them. [^1]: technically utf-16 code units
2024-10-31Adjust ranking so that duplicates count against rankMichael Howell-10/+35
2024-10-30rustdoc-search: simplify rules for generics and type paramsMichael Howell-29/+25
This commit is a response to feedback on the displayed type signatures results, by making generics act stricter. Generics are tightened by making order significant. This means `Vec<Allocator>` now matches only with a true vector of allocators, instead of matching the second type param. It also makes unboxing within generics stricter, so `Result<A, B>` only matches if `B` is in the error type and `A` is in the success type. The top level of the function search is unaffected. Find the discussion on: * <https://rust-lang.zulipchat.com/#narrow/stream/393423-t-rustdoc.2Fmeetings/topic/meeting.202024-07-08/near/449965149> * <https://github.com/rust-lang/rust/pull/124544#issuecomment-2204272265> * <https://rust-lang.zulipchat.com/#narrow/channel/266220-t-rustdoc/topic/deciding.20on.20semantics.20of.20generics.20in.20rustdoc.20search/near/476841363>
2024-10-30rustdoc-search: show types signatures in resultsMichael Howell-18/+156
2024-10-30rustdoc-search: pass original names through ASTMichael Howell-444/+245
2024-10-02Fix rustdoc-js-std path-ordering test due to API removalUrgau-1/+0
2024-09-22Bless rustdoc-js-std testMichael Goulet-5/+5
2024-09-05rustdoc-search: allow trailing `Foo ->` arg searchMichael Howell-9/+68
2024-08-23rustdoc: show exact case-sensitive matches firstbinarycat-0/+7
fixes #119480
2024-06-07Update testsSunshine-7/+16
2024-04-19rustdoc-search: add parser for `&` syntaxMichael Howell-0/+527
2024-04-18rustdoc-search: fix description on aliases in resultsMichael Howell-1/+5
This needs to start downloading the descriptions after aliases have been added to the result set.
2024-04-08rustdoc-search: single result for items with multiple pathsMichael Howell-3/+33
This change uses the same "exact" paths as trait implementors and type alias inlining to track items with multiple reachable paths. This way, if you search for `vec`, you get only the `std` exports of it, and not the one from `alloc`. It still includes all the items in the search index so that you can search for them by all available paths. For example, try `core::option` and `std::option`, and notice that the results page doesn't show duplicates, but still shows all the items in their respective crates.
2024-03-11rustdoc-search: add search query syntax `Fn(T) -> U`Michael Howell-12/+348
This is implemented, in addition to the ML-style one, because Rust does it. If we don't, we'll never hear the end of it. This commit also refactors some duplicate parts of the parser into a dedicated function.
2024-03-11rustdoc-search: parse and search with ML-style HOFMichael Howell-2/+378
Option::map, for example, looks like this: option<t>, (t -> u) -> option<u> This syntax searches all of the HOFs in Rust: traits Fn, FnOnce, and FnMut, and bare fn primitives.
2024-01-18Add `display` method to `OsStr`riverbl-1/+1
Add `display` method to `OsStr` for lossy display of an `OsStr` which may contain invalid unicode. Invalid Unicode sequences are replaced with `U+FFFD REPLACEMENT CHARACTER`. This change also makes the `std::ffi::os_str` module public.
2024-01-06Rollup merge of #118194 - notriddle:notriddle/tuple-unit, r=GuillaumeGomezMatthias Krüger-14/+388
rustdoc: search for tuples and unit by type with `()` This feature extends rustdoc to support the syntax that most users will naturally attempt to use to search for tuples. Part of https://github.com/rust-lang/rust/issues/60485 Function signature searches already support tuples and unit. The explicit name `primitive:tuple` and `primitive:unit` can be used to match a tuple or unit, while `()` will match either one. It also follows the direction set by the actual language for parens as a group, so `(u8,)` will only match a tuple, while `(u8)` will match a plain, unwrapped byte—thanks to loose search semantics, it will also match the tuple. ## Preview * [`option<t>, option<u> -> (t, u)`](<https://notriddle.com/rustdoc-html-demo-5/tuple-unit/std/index.html?search=option%3Ct%3E%2C option%3Cu%3E -%3E (t%2C u)>) * [`[t] -> (t,)`](<https://notriddle.com/rustdoc-html-demo-5/tuple-unit/std/index.html?search=[t] -%3E (t%2C)>) * [`(ipaddr,) -> socketaddr`](<https://notriddle.com/rustdoc-html-demo-5/tuple-unit/std/index.html?search=(ipaddr%2C) -%3E socketaddr>) ## Motivation When type-based search was first landed, it was directly [described as incomplete][a comment]. [a comment]: https://github.com/rust-lang/rust/pull/23289#issuecomment-79437386 Filling out the missing functionality is going to mean adding support for more of Rust's [type expression] syntax, such as tuples (in this PR), references, raw pointers, function pointers, and closures. [type expression]: https://doc.rust-lang.org/reference/types.html#type-expressions There does seem to be demand for this sort of thing, such as [this Discord message](https://discord.com/channels/442252698964721669/443150878111694848/1042145740065099796) expressing regret at rustdoc not supporting tuples in search queries. ## Reference description (from the Rustdoc book) <table> <thead> <tr> <th>Shorthand</th> <th>Explicit names</th> </tr> </thead> <tbody> <tr><td colspan="2">Before this PR</td></tr> <tr> <td><code>[]</code></td> <td><code>primitive:slice</code> and/or <code>primitive:array</code></td> </tr> <tr> <td><code>[T]</code></td> <td><code>primitive:slice&lt;T&gt;</code> and/or <code>primitive:array&lt;T&gt;</code></td> </tr> <tr> <td><code>!</code></td> <td><code>primitive:never</code></td> </tr> <tr><td colspan="2">After this PR</td></tr> <tr> <td><code>()</code></td> <td><code>primitive:unit</code> and/or <code>primitive:tuple</code></td> </tr> <tr> <td><code>(T)</code></td> <td><code>T</code></td> </tr> <tr> <td><code>(T,)</code></td> <td><code>primitive:tuple&lt;T&gt;</code></td> </tr> </tbody> </table> A single type expression wrapped in parens is the same as that type expression, since parens act as the grouping operator. If they're empty, though, they will match both `unit` and `tuple`, and if there's more than one type (or a trailing or leading comma) it is the same as `primitive:tuple<...>`. However, since items can be left out of the query, `(T)` will still return results for types that match tuples, even though it also matches the type on its own. That is, `(u32)` matches `(u32,)` for the exact same reason that it also matches `Result<u32, Error>`. ## Future direction The [type expression grammar](https://doc.rust-lang.org/reference/types.html#type-expressions) from the Reference is given below: <pre><code>Syntax Type : TypeNoBounds | <a href="https://doc.rust-lang.org/reference/types/impl-trait.html">ImplTraitType</a> | <a href="https://doc.rust-lang.org/reference/types/trait-object.html">TraitObjectType</a> <br> TypeNoBounds : <a href="https://doc.rust-lang.org/reference/types.html#parenthesized-types">ParenthesizedType</a> | <a href="https://doc.rust-lang.org/reference/types/impl-trait.html">ImplTraitTypeOneBound</a> | <a href="https://doc.rust-lang.org/reference/types/trait-object.html">TraitObjectTypeOneBound</a> | <a href="https://doc.rust-lang.org/reference/paths.html#paths-in-types">TypePath</a> | <a href="https://doc.rust-lang.org/reference/types/tuple.html#tuple-types">TupleType</a> | <a href="https://doc.rust-lang.org/reference/types/never.html">NeverType</a> | <a href="https://doc.rust-lang.org/reference/types/pointer.html#raw-pointers-const-and-mut">RawPointerType</a> | <a href="https://doc.rust-lang.org/reference/types/pointer.html#shared-references-">ReferenceType</a> | <a href="https://doc.rust-lang.org/reference/types/array.html">ArrayType</a> | <a href="https://doc.rust-lang.org/reference/types/slice.html">SliceType</a> | <a href="https://doc.rust-lang.org/reference/types/inferred.html">InferredType</a> | <a href="https://doc.rust-lang.org/reference/paths.html#qualified-paths">QualifiedPathInType</a> | <a href="https://doc.rust-lang.org/reference/types/function-pointer.html">BareFunctionType</a> | <a href="https://doc.rust-lang.org/reference/macros.html#macro-invocation">MacroInvocation</a> </code></pre> ImplTraitType and TraitObjectType (and ImplTraitTypeOneBound and TraitObjectTypeOneBound) are not yet implemented. They would mostly desugar to `trait:`, similarly to how `!` desugars to `primitive:never`. ParenthesizedType and TuplePath are added in this PR. TypePath is already implemented (except const generics, which is not planned, and function-like trait syntax, which is planned as part of closure support). NeverType is already implemented. RawPointerType and ReferenceType require parsing and fixes to the search index to store this information, but otherwise their behavior seems simple enough. Just like tuples and slices, `&T` would be equivalent to `primitive:reference<T>`, `&mut T` would be equivalent to `primitive:reference<keyword:mut, T>`, `*T` would be equivalent to `primitive:pointer<T>`, `*mut T` would be equivalent to `primitive:pointer<keyword:mut, T>`, and `*const T` would be equivalent to `primitive:pointer<keyword:const, T>`. Lifetime generics support is not planned, because lifetime subtyping seems too complicated. ArrayType is subsumed by SliceType right now. Implementing const generics is not planned, because it seems like it would require a lot of implementation complexity for not much gain. InferredType isn't really covered right now. Its semantics in a search context are not obvious. QualifiedPathInType is not implemented, and it is not planned. I would need a use case to justify it, and act as a guide for what the exact semantics should be. BareFunctionType is not implemented. Along with function-like trait syntax, which is formally considered a TypePath, it's the biggest missing feature to be able to do structured searches over generic APIs like `Option`. MacroInvocation is not parsed (macro names are, but they don't mean the same thing here at all). Those are gone by the time Rustdoc sees the source code.
2023-12-26rustdoc-search: count path edits with separate edit limitMichael Howell-12/+62
Since the two are counted separately elsewhere, they should get their own limits, too. The biggest problem with combining them is that paths are loosely checked by not requiring every component to match, which means that if they are short and matched loosely, they can easily find "drunk typist" matches that make no sense, like this old result: std::collections::btree_map::itermut matching slice::itermut maxEditDistance = ("slice::itermut".length) / 3 = 14 / 3 = 4 editDistance("std", "slice") = 4 editDistance("itermut", "itermut") = 0 4 + 0 <= 4 PASS Of course, `slice::itermut` should not match stuff from btreemap. `slice` should not match `std`. The new result counts them separately: maxPathEditDistance = "slice".length / 3 = 5 / 3 = 1 maxEditDistance = "itermut".length / 3 = 7 / 3 = 2 editDistance("std", "slice") = 4 4 <= 1 FAIL Effectively, this makes path queries less "typo-resistant". It's not zero, but it means `vec` won't match the `v1` prelude. Queries without parent paths are unchanged.
2023-12-26rustdoc: search for tuples and unit by type with `()`Michael Howell-14/+388
2023-12-02Auto merge of #118077 - calebzulawski:sync-portable-simd-2023-11-19, ↵bors-10/+10
r=workingjubilee Portable SIMD subtree update Syncs nightly to the latest changes from rust-lang/portable-simd r? `@rust-lang/libs`
2023-11-29rustdoc-search: replace TAB/NL/LF with SP firstMichael Howell-13/+22
This way, most of the parsing code doesn't need to be designed to handle it, since they should always be treated exactly the same anyhow.
2023-11-29rustdoc-search: removed dead parser codeMichael Howell-0/+9
This is already covered by the normal unexpected char path.
2023-11-29rustdoc-search: allow `:: ` and ` ::`Michael Howell-18/+57
This restriction made sense back when spaces separated function parameters, but now that they separate path components, there's no real ambiguity any more. Additionally, the Rust language allows it.
2023-11-26Update std::simd usage and test outputsCaleb Zulawski-10/+10
2023-11-21rustdoc-search: make primitives and keywords less specialMichael Howell-33/+33
The search sorting code already sorts by item type discriminant, putting things with smaller discriminants first. There was also a special case for sorting keywords and primitives earlier, and this commit removes it by giving them lower discriminants. The sorting code has another criteria where items with descriptions appear earlier than items without, and that criteria has higher priority than the item type. This shouldn't matter, though, because primitives and keywords normally only appear in the standard library, and it always gives them descriptions.
2023-11-19rustdoc-search: add support for associated typesMichael Howell-1/+275
2023-09-21rustdoc: update test cases for changes to the printing styleMichael Howell-20/+20
This whole thing changes it so that the JS and the UI both use rustc's own path printing to handle the impl IDs. This results in the format changing a little bit; full paths are used in spots where they aren't strictly necessary, and the path sometimes uses generics where the old system used the trait's own name, but it shouldn't matter since the orphan rules will prevent it anyway.
2023-09-21rustdoc-search: add impl disambiguator to duplicate assoc itemsMichael Howell-0/+70
Helps with #90929 This changes the search results, specifically, when there's more than one impl with an associated item with the same name. For example, the search queries `simd<i8> -> simd<i8>` and `simd<i64> -> simd<i64>` don't link to the same function, but most of the functions have the same names. This change should probably be FCP-ed, especially since it adds a new anchor link format for `main.js` to handle, so that URLs like `struct.Vec.html#impl-AsMut<[T]>-for-Vec<T,+A>/method.as_mut` redirect to `struct.Vec.html#method.as_mut-2`. It's a strange design, but there are a few reasons for it: * I'd like to avoid making the HTML bigger. Obviously, fixing this bug is going to add at least a little more data to the search index, but adding more HTML penalises viewers for the benefit of searchers. * Breaking `struct.Vec.html#method.len` would also be a disappointment. On the other hand: * The path-style anchors might be less prone to link rot than the numbered anchors. It's definitely less likely to have URLs that appear to "work", but silently point at the wrong thing. * This commit arranges the path-style anchor to redirect to the numbered anchor. Nothing stops rustdoc from doing the opposite, making path-style anchors the default and redirecting the "legacy" numbered ones.
2023-09-09rustdoc-search: fix bugs when unboxing and reordering combineMichael Howell-1/+26
2023-09-03rustdoc: bug fix for `-> option<t>`Michael Howell-0/+6
2023-09-03rustdoc-search: add support for type parametersMichael Howell-0/+53
When writing a type-driven search query in rustdoc, specifically one with more than one query element, non-existent types become generic parameters instead of auto-correcting (which is currently only done for single-element queries) or giving no result. You can also force a generic type parameter by writing `generic:T` (and can force it to not use a generic type parameter with something like `struct:T` or whatever, though if this happens it means the thing you're looking for doesn't exist and will give you no results). There is no syntax provided for specifying type constraints for generic type parameters. When you have a generic type parameter in a search query, it will only match up with generic type parameters in the actual function, not concrete types that match, not concrete types that implement a trait. It also strictly matches based on when they're the same or different, so `option<T>, option<U> -> option<U>` matches `Option::and`, but not `Option::or`. Similarly, `option<T>, option<T> -> option<T>`` matches `Option::or`, but not `Option::and`.