Skip to content

Commit fca9093

Browse files
author
Yuki Okushi
authored
Rollup merge of #103799 - GuillaumeGomez:search-index-tuple-struct-field, r=notriddle
Remove generation of tuple struct fields in the search index This comes from [this discussion](#103710) as they're not very useful. r? `@notriddle`
2 parents 0f40e95 + 5062a77 commit fca9093

File tree

2 files changed

+40
-15
lines changed

2 files changed

+40
-15
lines changed

Diff for: src/librustdoc/formats/cache.rs

+22-15
Original file line numberDiff line numberDiff line change
@@ -316,21 +316,28 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
316316
let desc = item.doc_value().map_or_else(String::new, |x| {
317317
short_markdown_summary(x.as_str(), &item.link_names(self.cache))
318318
});
319-
self.cache.search_index.push(IndexItem {
320-
ty: item.type_(),
321-
name: s.to_string(),
322-
path: join_with_double_colon(path),
323-
desc,
324-
parent,
325-
parent_idx: None,
326-
search_type: get_function_type_for_search(
327-
&item,
328-
self.tcx,
329-
clean_impl_generics(self.cache.parent_stack.last()).as_ref(),
330-
self.cache,
331-
),
332-
aliases: item.attrs.get_doc_aliases(),
333-
});
319+
let ty = item.type_();
320+
let name = s.to_string();
321+
if ty != ItemType::StructField || u16::from_str_radix(&name, 10).is_err() {
322+
// In case this is a field from a tuple struct, we don't add it into
323+
// the search index because its name is something like "0", which is
324+
// not useful for rustdoc search.
325+
self.cache.search_index.push(IndexItem {
326+
ty,
327+
name,
328+
path: join_with_double_colon(path),
329+
desc,
330+
parent,
331+
parent_idx: None,
332+
search_type: get_function_type_for_search(
333+
&item,
334+
self.tcx,
335+
clean_impl_generics(self.cache.parent_stack.last()).as_ref(),
336+
self.cache,
337+
),
338+
aliases: item.attrs.get_doc_aliases(),
339+
});
340+
}
334341
}
335342
}
336343
(Some(parent), None) if is_inherent_impl_item => {

Diff for: src/test/rustdoc/no-unit-struct-field.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// This test ensures that the tuple struct fields are not generated in the
2+
// search index.
3+
4+
// @!hasraw search-index.js '"0"'
5+
// @!hasraw search-index.js '"1"'
6+
// @hasraw search-index.js '"foo_a"'
7+
// @hasraw search-index.js '"bar_a"'
8+
9+
pub struct Bar(pub u32, pub u8);
10+
pub struct Foo {
11+
pub foo_a: u8,
12+
}
13+
pub enum Enum {
14+
Foo(u8),
15+
Bar {
16+
bar_a: u8,
17+
},
18+
}

0 commit comments

Comments
 (0)