Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve rustdoc source code a bit #70990

Merged
merged 1 commit into from
Apr 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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