Improve bounds search
This commit is contained in:
parent
d611301e3e
commit
6ae73e2ff6
2 changed files with 11 additions and 52 deletions
|
@ -1755,35 +1755,24 @@ pub fn get_real_types(
|
||||||
generics: &Generics,
|
generics: &Generics,
|
||||||
arg: &Type,
|
arg: &Type,
|
||||||
cx: &DocContext<'_, '_, '_>,
|
cx: &DocContext<'_, '_, '_>,
|
||||||
debug: bool,
|
|
||||||
) -> Option<Vec<Type>> {
|
) -> Option<Vec<Type>> {
|
||||||
let mut res = Vec::new();
|
let mut res = Vec::new();
|
||||||
if arg.to_string() == "W" || arg.to_string() == "Z" || debug {
|
|
||||||
println!("0. {:?}", arg);
|
|
||||||
}
|
|
||||||
if let Some(where_pred) = generics.where_predicates.iter().find(|g| {
|
if let Some(where_pred) = generics.where_predicates.iter().find(|g| {
|
||||||
match g {
|
match g {
|
||||||
&WherePredicate::BoundPredicate { ref ty, .. } => ty.def_id() == arg.def_id(),
|
&WherePredicate::BoundPredicate { ref ty, .. } => ty.def_id() == arg.def_id(),
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}) {
|
}) {
|
||||||
if arg.to_string() == "W" || arg.to_string() == "Z" || debug {
|
|
||||||
println!("1. {:?} => {:?}", arg, where_pred);
|
|
||||||
}
|
|
||||||
let bounds = where_pred.get_bounds().unwrap_or_else(|| &[]);
|
let bounds = where_pred.get_bounds().unwrap_or_else(|| &[]);
|
||||||
for bound in bounds.iter() {
|
for bound in bounds.iter() {
|
||||||
match *bound {
|
match *bound {
|
||||||
GenericBound::TraitBound(ref poly_trait, _) => {
|
GenericBound::TraitBound(ref poly_trait, _) => {
|
||||||
if arg.to_string() == "W" || arg.to_string() == "Z" || debug {
|
|
||||||
println!(" {:?}", poly_trait.trait_);
|
|
||||||
}
|
|
||||||
for x in poly_trait.generic_params.iter() {
|
for x in poly_trait.generic_params.iter() {
|
||||||
if !x.is_type() {
|
if !x.is_type() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if let Some(ty) = x.get_type(cx) {
|
if let Some(ty) = x.get_type(cx) {
|
||||||
if let Some(mut adds) = get_real_types(generics, &ty, cx,
|
if let Some(mut adds) = get_real_types(generics, &ty, cx) {
|
||||||
arg.to_string() == "W" || arg.to_string() == "Z" || debug) {
|
|
||||||
res.append(&mut adds);
|
res.append(&mut adds);
|
||||||
} else if !ty.is_full_generic() {
|
} else if !ty.is_full_generic() {
|
||||||
res.push(ty);
|
res.push(ty);
|
||||||
|
@ -1799,51 +1788,25 @@ pub fn get_real_types(
|
||||||
if let Some(bound) = generics.params.iter().find(|g| {
|
if let Some(bound) = generics.params.iter().find(|g| {
|
||||||
g.is_type() && g.name == arg_s
|
g.is_type() && g.name == arg_s
|
||||||
}) {
|
}) {
|
||||||
if arg.to_string() == "W" || arg.to_string() == "Z" || debug {
|
|
||||||
println!("2. {:?} => {:?}", arg, bound);
|
|
||||||
}
|
|
||||||
for bound in bound.get_bounds().unwrap_or_else(|| &[]) {
|
for bound in bound.get_bounds().unwrap_or_else(|| &[]) {
|
||||||
if let Some(ty) = bound.get_trait_type() {
|
if let Some(ty) = bound.get_trait_type() {
|
||||||
if let Some(mut adds) = get_real_types(generics, &ty, cx,
|
if let Some(mut adds) = get_real_types(generics, &ty, cx) {
|
||||||
arg.to_string() == "W" || arg.to_string() == "Z" || debug) {
|
|
||||||
if arg.to_string() == "W" || arg.to_string() == "Z" || debug {
|
|
||||||
println!("3. {:?}", adds);
|
|
||||||
}
|
|
||||||
res.append(&mut adds);
|
res.append(&mut adds);
|
||||||
} else {
|
} else {
|
||||||
if arg.to_string() == "W" || arg.to_string() == "Z" || debug {
|
|
||||||
println!("4. {:?}", ty);
|
|
||||||
}
|
|
||||||
if !ty.is_full_generic() {
|
if !ty.is_full_generic() {
|
||||||
res.push(ty.clone());
|
res.push(ty.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*if let Some(ty) = bound.get_type(cx) {
|
|
||||||
if let Some(mut adds) = get_real_types(generics, &ty, cx, level + 1) {
|
|
||||||
res.append(&mut adds);
|
|
||||||
} else {
|
|
||||||
res.push(ty);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
res.push(arg.clone());
|
|
||||||
}*/
|
|
||||||
} else if let Some(gens) = arg.generics() {
|
} else if let Some(gens) = arg.generics() {
|
||||||
res.push(arg.clone());
|
res.push(arg.clone());
|
||||||
for gen in gens.iter() {
|
for gen in gens.iter() {
|
||||||
if gen.is_full_generic() {
|
if gen.is_full_generic() {
|
||||||
if let Some(mut adds) = get_real_types(generics, gen, cx,
|
if let Some(mut adds) = get_real_types(generics, gen, cx) {
|
||||||
arg.to_string() == "W" || arg.to_string() == "Z" || debug) {
|
|
||||||
if arg.to_string() == "W" || arg.to_string() == "Z" || debug {
|
|
||||||
println!("5. {:?}", adds);
|
|
||||||
}
|
|
||||||
res.append(&mut adds);
|
res.append(&mut adds);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if arg.to_string() == "W" || arg.to_string() == "Z" || debug {
|
|
||||||
println!("6. {:?}", gen);
|
|
||||||
}
|
|
||||||
res.push(gen.clone());
|
res.push(gen.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1852,9 +1815,6 @@ pub fn get_real_types(
|
||||||
if res.is_empty() && !arg.is_full_generic() {
|
if res.is_empty() && !arg.is_full_generic() {
|
||||||
res.push(arg.clone());
|
res.push(arg.clone());
|
||||||
}
|
}
|
||||||
if arg.to_string() == "W" || arg.to_string() == "Z" || debug {
|
|
||||||
println!("7. /!\\ {:?}", res);
|
|
||||||
}
|
|
||||||
Some(res)
|
Some(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1868,17 +1828,15 @@ pub fn get_all_types(
|
||||||
if arg.type_.is_self_type() {
|
if arg.type_.is_self_type() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if let Some(mut args) = get_real_types(generics, &arg.type_, cx, false) {
|
if let Some(mut args) = get_real_types(generics, &arg.type_, cx) {
|
||||||
all_types.append(&mut args);
|
all_types.append(&mut args);
|
||||||
} else {
|
} else {
|
||||||
all_types.push(arg.type_.clone());
|
all_types.push(arg.type_.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
all_types.sort_unstable_by(|a, b| a.to_string().partial_cmp(&b.to_string()).expect("a") );
|
// FIXME: use a HashSet instead?
|
||||||
|
all_types.sort_unstable_by(|a, b| a.to_string().partial_cmp(&b.to_string()).unwrap());
|
||||||
all_types.dedup();
|
all_types.dedup();
|
||||||
if decl.inputs.values.iter().any(|s| s.type_.to_string() == "W" || s.type_.to_string() == "Z") {
|
|
||||||
println!("||||> {:?}", all_types);
|
|
||||||
}
|
|
||||||
all_types
|
all_types
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5029,16 +5029,17 @@ fn get_index_search_type(item: &clean::Item) -> Option<IndexItemFunctionType> {
|
||||||
clean::FunctionItem(ref f) => (&f.decl, &f.all_types),
|
clean::FunctionItem(ref f) => (&f.decl, &f.all_types),
|
||||||
clean::MethodItem(ref m) => (&m.decl, &m.all_types),
|
clean::MethodItem(ref m) => (&m.decl, &m.all_types),
|
||||||
clean::TyMethodItem(ref m) => (&m.decl, &m.all_types),
|
clean::TyMethodItem(ref m) => (&m.decl, &m.all_types),
|
||||||
_ => return None
|
_ => return None,
|
||||||
};
|
};
|
||||||
|
|
||||||
println!("====> {:?}", all_types);
|
|
||||||
let inputs = all_types.iter().map(|arg| {
|
let inputs = all_types.iter().map(|arg| {
|
||||||
get_index_type(&arg)
|
get_index_type(&arg)
|
||||||
}).collect();
|
}).collect();
|
||||||
let output = match decl.output {
|
let output = match decl.output {
|
||||||
clean::FunctionRetTy::Return(ref return_type) => Some(get_index_type(return_type)),
|
clean::FunctionRetTy::Return(ref return_type) => {
|
||||||
_ => None
|
Some(get_index_type(return_type))
|
||||||
|
},
|
||||||
|
_ => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
Some(IndexItemFunctionType { inputs: inputs, output: output })
|
Some(IndexItemFunctionType { inputs: inputs, output: output })
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue