Skip to content

Commit c677a8d

Browse files
authored
Rollup merge of #90853 - notriddle:notriddle/option-vec, r=GuillaumeGomez
rustdoc: Use an empty Vec instead of Option<Vec>
2 parents e273fab + 688ed0a commit c677a8d

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

src/librustdoc/html/render/cache.rs

-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ crate fn get_index_search_type<'tcx>(
204204

205205
inputs.retain(|a| a.ty.name.is_some());
206206
output.retain(|a| a.ty.name.is_some());
207-
let output = if output.is_empty() { None } else { Some(output) };
208207

209208
Some(IndexItemFunctionType { inputs, output })
210209
}

src/librustdoc/html/render/mod.rs

+7-12
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ crate struct RenderType {
117117
#[derive(Debug)]
118118
crate struct IndexItemFunctionType {
119119
inputs: Vec<TypeWithKind>,
120-
output: Option<Vec<TypeWithKind>>,
120+
output: Vec<TypeWithKind>,
121121
}
122122

123123
impl Serialize for IndexItemFunctionType {
@@ -126,21 +126,16 @@ impl Serialize for IndexItemFunctionType {
126126
S: Serializer,
127127
{
128128
// If we couldn't figure out a type, just write `null`.
129-
let mut iter = self.inputs.iter();
130-
if match self.output {
131-
Some(ref output) => iter.chain(output.iter()).any(|i| i.ty.name.is_none()),
132-
None => iter.any(|i| i.ty.name.is_none()),
133-
} {
129+
let has_missing = self.inputs.iter().chain(self.output.iter()).any(|i| i.ty.name.is_none());
130+
if has_missing {
134131
serializer.serialize_none()
135132
} else {
136133
let mut seq = serializer.serialize_seq(None)?;
137134
seq.serialize_element(&self.inputs)?;
138-
if let Some(output) = &self.output {
139-
if output.len() > 1 {
140-
seq.serialize_element(&output)?;
141-
} else {
142-
seq.serialize_element(&output[0])?;
143-
}
135+
match self.output.as_slice() {
136+
[] => {}
137+
[one] => seq.serialize_element(one)?,
138+
all => seq.serialize_element(all)?,
144139
}
145140
seq.end()
146141
}

0 commit comments

Comments
 (0)