Skip to content

Commit

Permalink
Improve rustdoc source code a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Apr 10, 2020
1 parent 1b521f5 commit 12a9548
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 29 deletions.
44 changes: 20 additions & 24 deletions src/librustdoc/clean/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,10 @@ pub fn get_real_types(
if !adds.is_empty() {
res.extend(adds);
} else if !ty.is_full_generic() {
if let Some(did) = ty.def_id() {
if let Some(kind) = cx.tcx.def_kind(did).clean(cx) {
res.insert((ty, kind));
}
if let Some(kind) =
ty.def_id().and_then(|did| cx.tcx.def_kind(did).clean(cx))
{
res.insert((ty, kind));
}
}
}
Expand All @@ -226,20 +226,18 @@ pub fn get_real_types(
if !adds.is_empty() {
res.extend(adds);
} else if !ty.is_full_generic() {
if let Some(did) = ty.def_id() {
if let Some(kind) = cx.tcx.def_kind(did).clean(cx) {
res.insert((ty.clone(), kind));
}
if let Some(kind) =
ty.def_id().and_then(|did| cx.tcx.def_kind(did).clean(cx))
{
res.insert((ty.clone(), kind));
}
}
}
}
}
} else {
if let Some(did) = arg.def_id() {
if let Some(kind) = cx.tcx.def_kind(did).clean(cx) {
res.insert((arg.clone(), kind));
}
if let Some(kind) = arg.def_id().and_then(|did| cx.tcx.def_kind(did).clean(cx)) {
res.insert((arg.clone(), kind));
}
if let Some(gens) = arg.generics() {
for gen in gens.iter() {
Expand All @@ -248,10 +246,10 @@ pub fn get_real_types(
if !adds.is_empty() {
res.extend(adds);
}
} else if let Some(did) = gen.def_id() {
if let Some(kind) = cx.tcx.def_kind(did).clean(cx) {
res.insert((gen.clone(), kind));
}
} else if let Some(kind) =
gen.def_id().and_then(|did| cx.tcx.def_kind(did).clean(cx))
{
res.insert((gen.clone(), kind));
}
}
}
Expand All @@ -277,10 +275,8 @@ pub fn get_all_types(
if !args.is_empty() {
all_types.extend(args);
} else {
if let Some(did) = arg.type_.def_id() {
if let Some(kind) = cx.tcx.def_kind(did).clean(cx) {
all_types.insert((arg.type_.clone(), kind));
}
if let Some(kind) = arg.type_.def_id().and_then(|did| cx.tcx.def_kind(did).clean(cx)) {
all_types.insert((arg.type_.clone(), kind));
}
}
}
Expand All @@ -289,10 +285,10 @@ pub fn get_all_types(
FnRetTy::Return(ref return_type) => {
let mut ret = get_real_types(generics, &return_type, cx, 0);
if ret.is_empty() {
if let Some(did) = return_type.def_id() {
if let Some(kind) = cx.tcx.def_kind(did).clean(cx) {
ret.insert((return_type.clone(), kind));
}
if let Some(kind) =
return_type.def_id().and_then(|did| cx.tcx.def_kind(did).clean(cx))
{
ret.insert((return_type.clone(), kind));
}
}
ret.into_iter().collect()
Expand Down
10 changes: 5 additions & 5 deletions src/librustdoc/html/render/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -697,11 +697,11 @@ fn get_generics(clean_type: &clean::Type) -> Option<Vec<Generic>> {
let r = types
.iter()
.filter_map(|t| {
if let Some(name) = get_index_type_name(t, false) {
Some(Generic { name: name.to_ascii_lowercase(), defid: t.def_id(), idx: None })
} else {
None
}
get_index_type_name(t, false).map(|name| Generic {
name: name.to_ascii_lowercase(),
defid: t.def_id(),
idx: None,
})
})
.collect::<Vec<_>>();
if r.is_empty() { None } else { Some(r) }
Expand Down

0 comments on commit 12a9548

Please sign in to comment.