From e802e996c0dbb0002657e489863f031287803c13 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 31 Oct 2022 11:21:06 +0100 Subject: [PATCH] Don't generate tuple struct fields into the search index --- src/librustdoc/formats/cache.rs | 37 ++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/librustdoc/formats/cache.rs b/src/librustdoc/formats/cache.rs index a0cf1ec78e2..d027fb6e876 100644 --- a/src/librustdoc/formats/cache.rs +++ b/src/librustdoc/formats/cache.rs @@ -316,21 +316,28 @@ fn fold_item(&mut self, item: clean::Item) -> Option { let desc = item.doc_value().map_or_else(String::new, |x| { short_markdown_summary(x.as_str(), &item.link_names(self.cache)) }); - self.cache.search_index.push(IndexItem { - ty: item.type_(), - name: s.to_string(), - path: join_with_double_colon(path), - desc, - parent, - parent_idx: None, - search_type: get_function_type_for_search( - &item, - self.tcx, - clean_impl_generics(self.cache.parent_stack.last()).as_ref(), - self.cache, - ), - aliases: item.attrs.get_doc_aliases(), - }); + let ty = item.type_(); + let name = s.to_string(); + if ty != ItemType::StructField || u16::from_str_radix(&name, 10).is_err() { + // In case this is a field from a tuple struct, we don't add it into + // the search index because its name is something like "0", which is + // not useful for rustdoc search. + self.cache.search_index.push(IndexItem { + ty, + name, + path: join_with_double_colon(path), + desc, + parent, + parent_idx: None, + search_type: get_function_type_for_search( + &item, + self.tcx, + clean_impl_generics(self.cache.parent_stack.last()).as_ref(), + self.cache, + ), + aliases: item.attrs.get_doc_aliases(), + }); + } } } (Some(parent), None) if is_inherent_impl_item => { -- 2.44.0