Apply review comments and improve code

This commit is contained in:
Guillaume Gomez 2021-01-21 21:54:14 +01:00
parent 19630ead41
commit 6a36b3f49d
2 changed files with 20 additions and 24 deletions

View File

@ -1410,34 +1410,30 @@ impl Type {
impl Type {
fn inner_def_id(&self, cache: Option<&Cache>) -> Option<DefId> {
fn inner<T: GetDefId>(t: &T, cache: Option<&Cache>) -> Option<DefId> {
match cache {
Some(c) => t.def_id_full(c),
None => t.def_id(),
}
}
match *self {
ResolvedPath { did, .. } => Some(did),
Primitive(p) => cache.and_then(|c| c.primitive_locations.get(&p).cloned()),
BorrowedRef { type_: box Generic(..), .. } => {
inner(&Primitive(PrimitiveType::Reference), cache)
}
BorrowedRef { ref type_, .. } => inner(&**type_, cache),
let t: &dyn GetDefId = match *self {
ResolvedPath { did, .. } => return Some(did),
Primitive(p) => return cache.and_then(|c| c.primitive_locations.get(&p).cloned()),
BorrowedRef { type_: box Generic(..), .. } => &Primitive(PrimitiveType::Reference),
BorrowedRef { ref type_, .. } => return type_.inner_def_id(cache),
Tuple(ref tys) => {
if tys.is_empty() {
inner(&Primitive(PrimitiveType::Unit), cache)
&Primitive(PrimitiveType::Unit)
} else {
inner(&Primitive(PrimitiveType::Tuple), cache)
&Primitive(PrimitiveType::Tuple)
}
}
BareFunction(..) => inner(&Primitive(PrimitiveType::Fn), cache),
Never => inner(&Primitive(PrimitiveType::Never), cache),
Slice(..) => inner(&Primitive(PrimitiveType::Slice), cache),
Array(..) => inner(&Primitive(PrimitiveType::Array), cache),
RawPointer(..) => inner(&Primitive(PrimitiveType::RawPointer), cache),
QPath { ref self_type, .. } => inner(&**self_type, cache),
_ => None,
BareFunction(..) => &Primitive(PrimitiveType::Fn),
Never => &Primitive(PrimitiveType::Never),
Slice(..) => &Primitive(PrimitiveType::Slice),
Array(..) => &Primitive(PrimitiveType::Array),
RawPointer(..) => &Primitive(PrimitiveType::RawPointer),
QPath { ref self_type, .. } => return self_type.inner_def_id(cache),
// FIXME: remove this wildcard
_ => return None,
};
match cache {
Some(c) => t.def_id_full(c),
None => t.def_id(),
}
}
}

View File

@ -78,7 +78,7 @@ crate fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
desc: item.doc_value().map_or_else(String::new, |s| short_markdown_summary(&s)),
parent: Some(did),
parent_idx: None,
search_type: get_index_search_type(&item, Some(cache)),
search_type: get_index_search_type(&item, None),
});
for alias in item.attrs.get_doc_aliases() {
cache