about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2021-11-13 22:35:05 +0100
committerGitHub <noreply@github.com>2021-11-13 22:35:05 +0100
commitc677a8da86e8bc5fb2a2c0fec54e0e71c2caca97 (patch)
treee1778f97cdfe1fe7e71263747be63353c9874d9b
parente273fab434f6accf42b3bbcd37e900db26b36cba (diff)
parent688ed0a019af8ac5097ac829ef24e4c69cd8d5c8 (diff)
downloadrust-c677a8da86e8bc5fb2a2c0fec54e0e71c2caca97.tar.gz
rust-c677a8da86e8bc5fb2a2c0fec54e0e71c2caca97.zip
Rollup merge of #90853 - notriddle:notriddle/option-vec, r=GuillaumeGomez
rustdoc: Use an empty Vec instead of Option<Vec>
-rw-r--r--src/librustdoc/html/render/cache.rs1
-rw-r--r--src/librustdoc/html/render/mod.rs19
2 files changed, 7 insertions, 13 deletions
diff --git a/src/librustdoc/html/render/cache.rs b/src/librustdoc/html/render/cache.rs
index 7aa950d905d..6f90695067c 100644
--- a/src/librustdoc/html/render/cache.rs
+++ b/src/librustdoc/html/render/cache.rs
@@ -204,7 +204,6 @@ crate fn get_index_search_type<'tcx>(
 
     inputs.retain(|a| a.ty.name.is_some());
     output.retain(|a| a.ty.name.is_some());
-    let output = if output.is_empty() { None } else { Some(output) };
 
     Some(IndexItemFunctionType { inputs, output })
 }
diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs
index fdadc68998d..00e8af22b48 100644
--- a/src/librustdoc/html/render/mod.rs
+++ b/src/librustdoc/html/render/mod.rs
@@ -117,7 +117,7 @@ crate struct RenderType {
 #[derive(Debug)]
 crate struct IndexItemFunctionType {
     inputs: Vec<TypeWithKind>,
-    output: Option<Vec<TypeWithKind>>,
+    output: Vec<TypeWithKind>,
 }
 
 impl Serialize for IndexItemFunctionType {
@@ -126,21 +126,16 @@ impl Serialize for IndexItemFunctionType {
         S: Serializer,
     {
         // If we couldn't figure out a type, just write `null`.
-        let mut iter = self.inputs.iter();
-        if match self.output {
-            Some(ref output) => iter.chain(output.iter()).any(|i| i.ty.name.is_none()),
-            None => iter.any(|i| i.ty.name.is_none()),
-        } {
+        let has_missing = self.inputs.iter().chain(self.output.iter()).any(|i| i.ty.name.is_none());
+        if has_missing {
             serializer.serialize_none()
         } else {
             let mut seq = serializer.serialize_seq(None)?;
             seq.serialize_element(&self.inputs)?;
-            if let Some(output) = &self.output {
-                if output.len() > 1 {
-                    seq.serialize_element(&output)?;
-                } else {
-                    seq.serialize_element(&output[0])?;
-                }
+            match self.output.as_slice() {
+                [] => {}
+                [one] => seq.serialize_element(one)?,
+                all => seq.serialize_element(all)?,
             }
             seq.end()
         }