Skip to content

Commit 6ae73e2

Browse files
Improve bounds search
1 parent d611301 commit 6ae73e2

File tree

2 files changed

+11
-52
lines changed

2 files changed

+11
-52
lines changed

src/librustdoc/clean/mod.rs

Lines changed: 6 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,35 +1755,24 @@ pub fn get_real_types(
17551755
generics: &Generics,
17561756
arg: &Type,
17571757
cx: &DocContext<'_, '_, '_>,
1758-
debug: bool,
17591758
) -> Option<Vec<Type>> {
17601759
let mut res = Vec::new();
1761-
if arg.to_string() == "W" || arg.to_string() == "Z" || debug {
1762-
println!("0. {:?}", arg);
1763-
}
17641760
if let Some(where_pred) = generics.where_predicates.iter().find(|g| {
17651761
match g {
17661762
&WherePredicate::BoundPredicate { ref ty, .. } => ty.def_id() == arg.def_id(),
17671763
_ => false,
17681764
}
17691765
}) {
1770-
if arg.to_string() == "W" || arg.to_string() == "Z" || debug {
1771-
println!("1. {:?} => {:?}", arg, where_pred);
1772-
}
17731766
let bounds = where_pred.get_bounds().unwrap_or_else(|| &[]);
17741767
for bound in bounds.iter() {
17751768
match *bound {
17761769
GenericBound::TraitBound(ref poly_trait, _) => {
1777-
if arg.to_string() == "W" || arg.to_string() == "Z" || debug {
1778-
println!(" {:?}", poly_trait.trait_);
1779-
}
17801770
for x in poly_trait.generic_params.iter() {
17811771
if !x.is_type() {
17821772
continue
17831773
}
17841774
if let Some(ty) = x.get_type(cx) {
1785-
if let Some(mut adds) = get_real_types(generics, &ty, cx,
1786-
arg.to_string() == "W" || arg.to_string() == "Z" || debug) {
1775+
if let Some(mut adds) = get_real_types(generics, &ty, cx) {
17871776
res.append(&mut adds);
17881777
} else if !ty.is_full_generic() {
17891778
res.push(ty);
@@ -1799,51 +1788,25 @@ pub fn get_real_types(
17991788
if let Some(bound) = generics.params.iter().find(|g| {
18001789
g.is_type() && g.name == arg_s
18011790
}) {
1802-
if arg.to_string() == "W" || arg.to_string() == "Z" || debug {
1803-
println!("2. {:?} => {:?}", arg, bound);
1804-
}
18051791
for bound in bound.get_bounds().unwrap_or_else(|| &[]) {
18061792
if let Some(ty) = bound.get_trait_type() {
1807-
if let Some(mut adds) = get_real_types(generics, &ty, cx,
1808-
arg.to_string() == "W" || arg.to_string() == "Z" || debug) {
1809-
if arg.to_string() == "W" || arg.to_string() == "Z" || debug {
1810-
println!("3. {:?}", adds);
1811-
}
1793+
if let Some(mut adds) = get_real_types(generics, &ty, cx) {
18121794
res.append(&mut adds);
18131795
} else {
1814-
if arg.to_string() == "W" || arg.to_string() == "Z" || debug {
1815-
println!("4. {:?}", ty);
1816-
}
18171796
if !ty.is_full_generic() {
18181797
res.push(ty.clone());
18191798
}
18201799
}
18211800
}
18221801
}
1823-
/*if let Some(ty) = bound.get_type(cx) {
1824-
if let Some(mut adds) = get_real_types(generics, &ty, cx, level + 1) {
1825-
res.append(&mut adds);
1826-
} else {
1827-
res.push(ty);
1828-
}
1829-
} else {
1830-
res.push(arg.clone());
1831-
}*/
18321802
} else if let Some(gens) = arg.generics() {
18331803
res.push(arg.clone());
18341804
for gen in gens.iter() {
18351805
if gen.is_full_generic() {
1836-
if let Some(mut adds) = get_real_types(generics, gen, cx,
1837-
arg.to_string() == "W" || arg.to_string() == "Z" || debug) {
1838-
if arg.to_string() == "W" || arg.to_string() == "Z" || debug {
1839-
println!("5. {:?}", adds);
1840-
}
1806+
if let Some(mut adds) = get_real_types(generics, gen, cx) {
18411807
res.append(&mut adds);
18421808
}
18431809
} else {
1844-
if arg.to_string() == "W" || arg.to_string() == "Z" || debug {
1845-
println!("6. {:?}", gen);
1846-
}
18471810
res.push(gen.clone());
18481811
}
18491812
}
@@ -1852,9 +1815,6 @@ pub fn get_real_types(
18521815
if res.is_empty() && !arg.is_full_generic() {
18531816
res.push(arg.clone());
18541817
}
1855-
if arg.to_string() == "W" || arg.to_string() == "Z" || debug {
1856-
println!("7. /!\\ {:?}", res);
1857-
}
18581818
Some(res)
18591819
}
18601820

@@ -1868,17 +1828,15 @@ pub fn get_all_types(
18681828
if arg.type_.is_self_type() {
18691829
continue;
18701830
}
1871-
if let Some(mut args) = get_real_types(generics, &arg.type_, cx, false) {
1831+
if let Some(mut args) = get_real_types(generics, &arg.type_, cx) {
18721832
all_types.append(&mut args);
18731833
} else {
18741834
all_types.push(arg.type_.clone());
18751835
}
18761836
}
1877-
all_types.sort_unstable_by(|a, b| a.to_string().partial_cmp(&b.to_string()).expect("a") );
1837+
// FIXME: use a HashSet instead?
1838+
all_types.sort_unstable_by(|a, b| a.to_string().partial_cmp(&b.to_string()).unwrap());
18781839
all_types.dedup();
1879-
if decl.inputs.values.iter().any(|s| s.type_.to_string() == "W" || s.type_.to_string() == "Z") {
1880-
println!("||||> {:?}", all_types);
1881-
}
18821840
all_types
18831841
}
18841842

src/librustdoc/html/render.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5029,16 +5029,17 @@ fn get_index_search_type(item: &clean::Item) -> Option<IndexItemFunctionType> {
50295029
clean::FunctionItem(ref f) => (&f.decl, &f.all_types),
50305030
clean::MethodItem(ref m) => (&m.decl, &m.all_types),
50315031
clean::TyMethodItem(ref m) => (&m.decl, &m.all_types),
5032-
_ => return None
5032+
_ => return None,
50335033
};
50345034

5035-
println!("====> {:?}", all_types);
50365035
let inputs = all_types.iter().map(|arg| {
50375036
get_index_type(&arg)
50385037
}).collect();
50395038
let output = match decl.output {
5040-
clean::FunctionRetTy::Return(ref return_type) => Some(get_index_type(return_type)),
5041-
_ => None
5039+
clean::FunctionRetTy::Return(ref return_type) => {
5040+
Some(get_index_type(return_type))
5041+
},
5042+
_ => None,
50425043
};
50435044

50445045
Some(IndexItemFunctionType { inputs: inputs, output: output })

0 commit comments

Comments
 (0)