Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 14 additions & 21 deletions src/librustdoc/html/render/search_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down
41 changes: 41 additions & 0 deletions tests/rustdoc-js/auxiliary/emptytype.rs
Original file line number Diff line number Diff line change
@@ -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<A: T1<B>, B: T2<C>, C: T3<D>, D: T4<A>>(a: A) {}

pub trait T1<T: ?Sized> {}
pub trait T2<T: ?Sized> {}
pub trait T3<T: ?Sized> {}
pub trait T4<T: ?Sized> {}

// 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<A: U1<B>, B: U2<C>, C: U3<D>, D: U4<E>, E: U5<A>>(a: A) {}

pub trait U1<T: ?Sized> {}
pub trait U2<T: ?Sized> {}
pub trait U3<T: ?Sized> {}
pub trait U4<T: ?Sized> {}
pub trait U5<T: ?Sized> {}

pub fn foobar3<A: V1<B>, B: V2<C>, C: V3<D>, D: V4<E>, E: V5<F>, F: V6<A>>(a: A) {}

pub trait V1<T: ?Sized> {}
pub trait V2<T: ?Sized> {}
pub trait V3<T: ?Sized> {}
pub trait V4<T: ?Sized> {}
pub trait V5<T: ?Sized> {}
pub trait V6<T: ?Sized> {}

pub fn foobar4<A: W1<B>, B: W2<C>, C: W3<A>>(a: A) {}

pub trait W1<T: ?Sized> {}
pub trait W2<T: ?Sized> {}
pub trait W3<T: ?Sized> {}
8 changes: 8 additions & 0 deletions tests/rustdoc-js/empty-type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const EXPECTED = [
{
query: 'baz',
others: [
{ name: 'baz' }
],
},
];
8 changes: 8 additions & 0 deletions tests/rustdoc-js/empty-type.rs
Original file line number Diff line number Diff line change
@@ -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() {}
Loading