1
Fork 0

Add bounds for return types as well

This commit is contained in:
Guillaume Gomez 2019-03-07 16:47:40 +01:00
parent 6ae73e2ff6
commit aefe75095a
4 changed files with 59 additions and 30 deletions

View file

@ -446,7 +446,7 @@ impl ToJson for Type {
}
Json::Array(data)
}
None => Json::Null
None => Json::Null,
}
}
}
@ -455,7 +455,7 @@ impl ToJson for Type {
#[derive(Debug)]
struct IndexItemFunctionType {
inputs: Vec<Type>,
output: Option<Type>,
output: Vec<Type>,
}
impl ToJson for IndexItemFunctionType {
@ -466,8 +466,8 @@ impl ToJson for IndexItemFunctionType {
} else {
let mut data = Vec::with_capacity(2);
data.push(self.inputs.to_json());
if let Some(ref output) = self.output {
data.push(output.to_json());
if !self.output.is_empty() {
data.push(self.output.to_json());
}
Json::Array(data)
}
@ -5025,24 +5025,21 @@ fn make_item_keywords(it: &clean::Item) -> String {
}
fn get_index_search_type(item: &clean::Item) -> Option<IndexItemFunctionType> {
let (decl, all_types) = match item.inner {
clean::FunctionItem(ref f) => (&f.decl, &f.all_types),
clean::MethodItem(ref m) => (&m.decl, &m.all_types),
clean::TyMethodItem(ref m) => (&m.decl, &m.all_types),
let (all_types, ret_types) = match item.inner {
clean::FunctionItem(ref f) => (&f.all_types, &f.ret_types),
clean::MethodItem(ref m) => (&m.all_types, &m.ret_types),
clean::TyMethodItem(ref m) => (&m.all_types, &m.ret_types),
_ => return None,
};
let inputs = all_types.iter().map(|arg| {
get_index_type(&arg)
}).collect();
let output = match decl.output {
clean::FunctionRetTy::Return(ref return_type) => {
Some(get_index_type(return_type))
},
_ => None,
};
let output = ret_types.iter().map(|arg| {
get_index_type(&arg)
}).collect();
Some(IndexItemFunctionType { inputs: inputs, output: output })
Some(IndexItemFunctionType { inputs, output })
}
fn get_index_type(clean_type: &clean::Type) -> Type {