From c8b2a9af2b10295436828e6678c466536bada981 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Wed, 5 Nov 2025 23:37:51 -0700 Subject: [PATCH] rustdoc-search: remove broken index special case --- src/librustdoc/html/render/search_index.rs | 35 ++++++++---------- tests/rustdoc-js/auxiliary/emptytype.rs | 41 ++++++++++++++++++++++ tests/rustdoc-js/empty-type.js | 8 +++++ tests/rustdoc-js/empty-type.rs | 8 +++++ 4 files changed, 71 insertions(+), 21 deletions(-) create mode 100644 tests/rustdoc-js/auxiliary/emptytype.rs create mode 100644 tests/rustdoc-js/empty-type.js create mode 100644 tests/rustdoc-js/empty-type.rs diff --git a/src/librustdoc/html/render/search_index.rs b/src/librustdoc/html/render/search_index.rs index 96e941b598ad1..9c072eed51aec 100644 --- a/src/librustdoc/html/render/search_index.rs +++ b/src/librustdoc/html/render/search_index.rs @@ -1051,28 +1051,21 @@ impl Serialize for TypeData { where S: Serializer, { - if self.search_unbox - || !self.inverted_function_inputs_index.is_empty() - || !self.inverted_function_output_index.is_empty() - { - let mut seq = serializer.serialize_seq(None)?; - let mut buf = Vec::new(); - encode::write_postings_to_string(&self.inverted_function_inputs_index, &mut buf); - let mut serialized_result = Vec::new(); - stringdex_internals::encode::write_base64_to_bytes(&buf, &mut serialized_result); - seq.serialize_element(&str::from_utf8(&serialized_result).unwrap())?; - buf.clear(); - serialized_result.clear(); - encode::write_postings_to_string(&self.inverted_function_output_index, &mut buf); - stringdex_internals::encode::write_base64_to_bytes(&buf, &mut serialized_result); - seq.serialize_element(&str::from_utf8(&serialized_result).unwrap())?; - if self.search_unbox { - seq.serialize_element(&1)?; - } - seq.end() - } else { - None::<()>.serialize(serializer) + let mut seq = serializer.serialize_seq(None)?; + let mut buf = Vec::new(); + encode::write_postings_to_string(&self.inverted_function_inputs_index, &mut buf); + let mut serialized_result = Vec::new(); + stringdex_internals::encode::write_base64_to_bytes(&buf, &mut serialized_result); + seq.serialize_element(&str::from_utf8(&serialized_result).unwrap())?; + buf.clear(); + serialized_result.clear(); + encode::write_postings_to_string(&self.inverted_function_output_index, &mut buf); + stringdex_internals::encode::write_base64_to_bytes(&buf, &mut serialized_result); + seq.serialize_element(&str::from_utf8(&serialized_result).unwrap())?; + if self.search_unbox { + seq.serialize_element(&1)?; } + seq.end() } } diff --git a/tests/rustdoc-js/auxiliary/emptytype.rs b/tests/rustdoc-js/auxiliary/emptytype.rs new file mode 100644 index 0000000000000..2a06b4ec9f8ca --- /dev/null +++ b/tests/rustdoc-js/auxiliary/emptytype.rs @@ -0,0 +1,41 @@ +// https://github.com/rust-lang/rust/issues/148431 + +// This test is designed to hit a case where, thanks to the +// recursion limit, the where clause gets generated, but not +// used, because we run out of fuel. +// +// This results in a reverse index with nothing in it, which +// used to crash when we parsed it. +pub fn foobar1, B: T2, C: T3, D: T4>(a: A) {} + +pub trait T1 {} +pub trait T2 {} +pub trait T3 {} +pub trait T4 {} + +// foobar1 is the version that worked at the time this test was written +// the rest are here to try to make the test at least a little more +// robust, in the sense that it actually tests the code and isn't magically +// fixed by the recursion limit changing +pub fn foobar2, B: U2, C: U3, D: U4, E: U5>(a: A) {} + +pub trait U1 {} +pub trait U2 {} +pub trait U3 {} +pub trait U4 {} +pub trait U5 {} + +pub fn foobar3, B: V2, C: V3, D: V4, E: V5, F: V6>(a: A) {} + +pub trait V1 {} +pub trait V2 {} +pub trait V3 {} +pub trait V4 {} +pub trait V5 {} +pub trait V6 {} + +pub fn foobar4, B: W2, C: W3>(a: A) {} + +pub trait W1 {} +pub trait W2 {} +pub trait W3 {} diff --git a/tests/rustdoc-js/empty-type.js b/tests/rustdoc-js/empty-type.js new file mode 100644 index 0000000000000..e4c8f9954cb7f --- /dev/null +++ b/tests/rustdoc-js/empty-type.js @@ -0,0 +1,8 @@ +const EXPECTED = [ + { + query: 'baz', + others: [ + { name: 'baz' } + ], + }, +]; diff --git a/tests/rustdoc-js/empty-type.rs b/tests/rustdoc-js/empty-type.rs new file mode 100644 index 0000000000000..87ea73709b6bb --- /dev/null +++ b/tests/rustdoc-js/empty-type.rs @@ -0,0 +1,8 @@ +//@ aux-crate:emptytype=emptytype.rs +//@ compile-flags: --extern emptytype +//@ aux-build:emptytype.rs +//@ build-aux-docs + +extern crate emptytype; + +pub fn baz() {}