Use an empty Vec instead of Option<Vec>
This commit is contained in:
parent
e90c5fbbc5
commit
688ed0a019
2 changed files with 7 additions and 13 deletions
|
@ -204,7 +204,6 @@ crate fn get_index_search_type<'tcx>(
|
||||||
|
|
||||||
inputs.retain(|a| a.ty.name.is_some());
|
inputs.retain(|a| a.ty.name.is_some());
|
||||||
output.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 })
|
Some(IndexItemFunctionType { inputs, output })
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,7 +117,7 @@ crate struct RenderType {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
crate struct IndexItemFunctionType {
|
crate struct IndexItemFunctionType {
|
||||||
inputs: Vec<TypeWithKind>,
|
inputs: Vec<TypeWithKind>,
|
||||||
output: Option<Vec<TypeWithKind>>,
|
output: Vec<TypeWithKind>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Serialize for IndexItemFunctionType {
|
impl Serialize for IndexItemFunctionType {
|
||||||
|
@ -126,21 +126,16 @@ impl Serialize for IndexItemFunctionType {
|
||||||
S: Serializer,
|
S: Serializer,
|
||||||
{
|
{
|
||||||
// If we couldn't figure out a type, just write `null`.
|
// If we couldn't figure out a type, just write `null`.
|
||||||
let mut iter = self.inputs.iter();
|
let has_missing = self.inputs.iter().chain(self.output.iter()).any(|i| i.ty.name.is_none());
|
||||||
if match self.output {
|
if has_missing {
|
||||||
Some(ref output) => iter.chain(output.iter()).any(|i| i.ty.name.is_none()),
|
|
||||||
None => iter.any(|i| i.ty.name.is_none()),
|
|
||||||
} {
|
|
||||||
serializer.serialize_none()
|
serializer.serialize_none()
|
||||||
} else {
|
} else {
|
||||||
let mut seq = serializer.serialize_seq(None)?;
|
let mut seq = serializer.serialize_seq(None)?;
|
||||||
seq.serialize_element(&self.inputs)?;
|
seq.serialize_element(&self.inputs)?;
|
||||||
if let Some(output) = &self.output {
|
match self.output.as_slice() {
|
||||||
if output.len() > 1 {
|
[] => {}
|
||||||
seq.serialize_element(&output)?;
|
[one] => seq.serialize_element(one)?,
|
||||||
} else {
|
all => seq.serialize_element(all)?,
|
||||||
seq.serialize_element(&output[0])?;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
seq.end()
|
seq.end()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue