diff options
| author | Michael Howell <michael@notriddle.com> | 2024-12-13 10:47:02 -0700 |
|---|---|---|
| committer | Michael Howell <michael@notriddle.com> | 2024-12-13 10:47:20 -0700 |
| commit | f068d8b809e09f4c685bddeebfe63e736a02d473 (patch) | |
| tree | a0f9dfb5015704c5b912efeabc6e0ae546e3753b | |
| parent | 4847d6a9d07d4be9ba3196f6ad444af2d7bdde72 (diff) | |
| download | rust-f068d8b809e09f4c685bddeebfe63e736a02d473.tar.gz rust-f068d8b809e09f4c685bddeebfe63e736a02d473.zip | |
rustdoc-search: show `impl Trait` inline when unhighlighted
While normal generics can be skipped in this case, no-names need something to show here. Before: `TyCtxt, , Symbol -> bool` After: `TyCtxt, Into<DefId>, Symbol -> bool`
| -rw-r--r-- | src/librustdoc/html/static/js/search.js | 7 | ||||
| -rw-r--r-- | tests/rustdoc-js/impl-trait-inlining.js | 25 | ||||
| -rw-r--r-- | tests/rustdoc-js/impl-trait-inlining.rs | 11 |
3 files changed, 42 insertions, 1 deletions
diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index 9e5cf497211..04eeee37fe8 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -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; diff --git a/tests/rustdoc-js/impl-trait-inlining.js b/tests/rustdoc-js/impl-trait-inlining.js new file mode 100644 index 00000000000..02c9853dd63 --- /dev/null +++ b/tests/rustdoc-js/impl-trait-inlining.js @@ -0,0 +1,25 @@ +// 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`", + }, + ], + }, +]; diff --git a/tests/rustdoc-js/impl-trait-inlining.rs b/tests/rustdoc-js/impl-trait-inlining.rs new file mode 100644 index 00000000000..a6ca0dcbd8d --- /dev/null +++ b/tests/rustdoc-js/impl-trait-inlining.rs @@ -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!(); + } +} |
