From 198e3aba8f00bc086ed6020f6420064e26a820c7 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 30 Jan 2021 17:39:18 +0100 Subject: [PATCH 1/3] Put back primitives in search --- src/librustdoc/clean/types.rs | 11 +++++++++++ src/librustdoc/clean/utils.rs | 27 ++++++++++++++------------- src/librustdoc/formats/item_type.rs | 1 + src/librustdoc/html/render/cache.rs | 2 +- 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 86bce8b8707..a1709226578 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -1302,6 +1302,7 @@ crate enum TypeKind { Attr, Derive, TraitAlias, + Primitive, } crate trait GetDefId { @@ -1404,6 +1405,16 @@ impl Type { matches!(self, Type::Generic(_)) } + crate fn is_primitive(&self) -> bool { + match self { + Self::Primitive(_) => true, + Self::BorrowedRef { ref type_, .. } | Self::RawPointer(_, ref type_) => { + type_.is_primitive() + } + _ => false, + } + } + crate fn projection(&self) -> Option<(&Type, DefId, Symbol)> { let (self_, trait_, name) = match self { QPath { self_type, trait_, name } => (self_type, trait_, name), diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index 869d48fc25e..695614f2702 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -171,11 +171,20 @@ crate fn get_real_types( cx: &DocContext<'_>, recurse: i32, ) -> FxHashSet<(Type, TypeKind)> { + fn insert(res: &mut FxHashSet<(Type, TypeKind)>, cx: &DocContext<'_>, ty: Type) { + if let Some(kind) = ty.def_id().map(|did| cx.tcx.def_kind(did).clean(cx)) { + res.insert((ty, kind)); + } else if ty.is_primitive() { + // This is a primitive, let's store it as such. + res.insert((ty, TypeKind::Primitive)); + } + } let mut res = FxHashSet::default(); if recurse >= 10 { // FIXME: remove this whole recurse thing when the recursion bug is fixed return res; } + if arg.is_full_generic() { let arg_s = Symbol::intern(&arg.print(&cx.cache).to_string()); if let Some(where_pred) = generics.where_predicates.iter().find(|g| match g { @@ -194,11 +203,7 @@ crate fn get_real_types( if !adds.is_empty() { res.extend(adds); } else if !ty.is_full_generic() { - if let Some(kind) = - ty.def_id().map(|did| cx.tcx.def_kind(did).clean(cx)) - { - res.insert((ty, kind)); - } + insert(&mut res, cx, ty); } } } @@ -212,17 +217,13 @@ crate fn get_real_types( if !adds.is_empty() { res.extend(adds); } else if !ty.is_full_generic() { - if let Some(kind) = ty.def_id().map(|did| cx.tcx.def_kind(did).clean(cx)) { - res.insert((ty.clone(), kind)); - } + insert(&mut res, cx, ty); } } } } } else { - if let Some(kind) = arg.def_id().map(|did| cx.tcx.def_kind(did).clean(cx)) { - res.insert((arg.clone(), kind)); - } + insert(&mut res, cx, arg.clone()); if let Some(gens) = arg.generics() { for gen in gens.iter() { if gen.is_full_generic() { @@ -230,8 +231,8 @@ crate fn get_real_types( if !adds.is_empty() { res.extend(adds); } - } else if let Some(kind) = gen.def_id().map(|did| cx.tcx.def_kind(did).clean(cx)) { - res.insert((gen.clone(), kind)); + } else { + insert(&mut res, cx, gen.clone()); } } } diff --git a/src/librustdoc/formats/item_type.rs b/src/librustdoc/formats/item_type.rs index ad51adf2fe3..be2e419bdff 100644 --- a/src/librustdoc/formats/item_type.rs +++ b/src/librustdoc/formats/item_type.rs @@ -119,6 +119,7 @@ impl From for ItemType { clean::TypeKind::Attr => ItemType::ProcAttribute, clean::TypeKind::Derive => ItemType::ProcDerive, clean::TypeKind::TraitAlias => ItemType::TraitAlias, + clean::TypeKind::Primitive => ItemType::Primitive, } } } diff --git a/src/librustdoc/html/render/cache.rs b/src/librustdoc/html/render/cache.rs index 5c02be14181..74a770b9548 100644 --- a/src/librustdoc/html/render/cache.rs +++ b/src/librustdoc/html/render/cache.rs @@ -78,7 +78,7 @@ crate fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String { desc: item.doc_value().map_or_else(String::new, |s| short_markdown_summary(&s)), parent: Some(did), parent_idx: None, - search_type: get_index_search_type(&item, None), + search_type: get_index_search_type(&item, Some(cache)), }); for alias in item.attrs.get_doc_aliases() { cache From d5243e3a973899e0f12c0c11f2175ed9ead665a8 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 30 Jan 2021 17:39:44 +0100 Subject: [PATCH 2/3] Add test for primitive search --- src/test/rustdoc-js/primitive.js | 25 +++++++++++++++++++++++++ src/test/rustdoc-js/primitive.rs | 5 +++++ 2 files changed, 30 insertions(+) create mode 100644 src/test/rustdoc-js/primitive.js create mode 100644 src/test/rustdoc-js/primitive.rs diff --git a/src/test/rustdoc-js/primitive.js b/src/test/rustdoc-js/primitive.js new file mode 100644 index 00000000000..918f7099918 --- /dev/null +++ b/src/test/rustdoc-js/primitive.js @@ -0,0 +1,25 @@ +// exact-check + +const QUERY = [ + "i32", + "str", + "TotoIsSomewhere", +]; + +const EXPECTED = [ + { + 'in_args': [ + { 'path': 'primitive', 'name': 'foo' }, + ], + }, + { + 'returned': [ + { 'path': 'primitive', 'name': 'foo' }, + ], + }, + { + 'others': [], + 'in_args': [], + 'returned': [], + }, +]; diff --git a/src/test/rustdoc-js/primitive.rs b/src/test/rustdoc-js/primitive.rs new file mode 100644 index 00000000000..2b30ccf1520 --- /dev/null +++ b/src/test/rustdoc-js/primitive.rs @@ -0,0 +1,5 @@ +pub fn foo(i: i32) -> &'static str { + "hello" +} + +pub fn foo2(i: &TotoIsSomewhere, j: TotoIsSomewhere) {} From c013f2a735989a4407201eaaafcba3844ef1846e Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 1 Feb 2021 11:27:17 +0100 Subject: [PATCH 3/3] Improve diff display in case the whole key in missing --- src/tools/rustdoc-js/tester.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/tools/rustdoc-js/tester.js b/src/tools/rustdoc-js/tester.js index 3f6bd603975..c21277de335 100644 --- a/src/tools/rustdoc-js/tester.js +++ b/src/tools/rustdoc-js/tester.js @@ -203,6 +203,10 @@ function betterLookingDiff(entry, data) { if (!entry.hasOwnProperty(key)) { continue; } + if (!data || !data.hasOwnProperty(key)) { + output += '-' + spaces + contentToDiffLine(key, entry[key]) + '\n'; + continue; + } let value = data[key]; if (value !== entry[key]) { output += '-' + spaces + contentToDiffLine(key, entry[key]) + '\n';