is_{some,ok}_and for rustdoc

This commit is contained in:
Michael Goulet 2023-11-25 17:17:25 +00:00
parent fe3038f263
commit 63b2f55e83
6 changed files with 12 additions and 14 deletions

View File

@ -498,7 +498,7 @@ pub(crate) fn link_names(&self, cache: &Cache) -> Vec<RenderedLink> {
} }
pub(crate) fn is_crate(&self) -> bool { pub(crate) fn is_crate(&self) -> bool {
self.is_mod() && self.def_id().map_or(false, |did| did.is_crate_root()) self.is_mod() && self.def_id().is_some_and(|did| did.is_crate_root())
} }
pub(crate) fn is_mod(&self) -> bool { pub(crate) fn is_mod(&self) -> bool {
self.type_() == ItemType::Module self.type_() == ItemType::Module
@ -2487,7 +2487,7 @@ pub(crate) fn new_glob(source: ImportSource, should_be_displayed: bool) -> Self
} }
pub(crate) fn imported_item_is_doc_hidden(&self, tcx: TyCtxt<'_>) -> bool { pub(crate) fn imported_item_is_doc_hidden(&self, tcx: TyCtxt<'_>) -> bool {
self.source.did.map_or(false, |did| tcx.is_doc_hidden(did)) self.source.did.is_some_and(|did| tcx.is_doc_hidden(did))
} }
} }

View File

@ -573,9 +573,8 @@ pub(crate) fn find_nearest_parent_module(tcx: TyCtxt<'_>, def_id: DefId) -> Opti
/// This function exists because it runs on `hir::Attributes` whereas the other is a /// This function exists because it runs on `hir::Attributes` whereas the other is a
/// `clean::Attributes` method. /// `clean::Attributes` method.
pub(crate) fn has_doc_flag(tcx: TyCtxt<'_>, did: DefId, flag: Symbol) -> bool { pub(crate) fn has_doc_flag(tcx: TyCtxt<'_>, did: DefId, flag: Symbol) -> bool {
tcx.get_attrs(did, sym::doc).any(|attr| { tcx.get_attrs(did, sym::doc)
attr.meta_item_list().map_or(false, |l| rustc_attr::list_contains_name(&l, flag)) .any(|attr| attr.meta_item_list().is_some_and(|l| rustc_attr::list_contains_name(&l, flag)))
})
} }
/// A link to `doc.rust-lang.org` that includes the channel name. Use this instead of manual links /// A link to `doc.rust-lang.org` that includes the channel name. Use this instead of manual links

View File

@ -798,7 +798,7 @@ fn println_condition(condition: Condition) {
/// Returns `true` if the file given as `self.input` is a Markdown file. /// Returns `true` if the file given as `self.input` is a Markdown file.
pub(crate) fn markdown_input(&self) -> bool { pub(crate) fn markdown_input(&self) -> bool {
self.input.extension().map_or(false, |e| e == "md" || e == "markdown") self.input.extension().is_some_and(|e| e == "md" || e == "markdown")
} }
} }

View File

@ -234,10 +234,10 @@ fn is_from_private_dep(tcx: TyCtxt<'_>, cache: &Cache, def_id: DefId) -> bool {
&& (self.cache.masked_crates.contains(&item.item_id.krate()) && (self.cache.masked_crates.contains(&item.item_id.krate())
|| i.trait_ || i.trait_
.as_ref() .as_ref()
.map_or(false, |t| is_from_private_dep(self.tcx, self.cache, t.def_id())) .is_some_and(|t| is_from_private_dep(self.tcx, self.cache, t.def_id()))
|| i.for_ || i.for_
.def_id(self.cache) .def_id(self.cache)
.map_or(false, |d| is_from_private_dep(self.tcx, self.cache, d))) .is_some_and(|d| is_from_private_dep(self.tcx, self.cache, d)))
{ {
return None; return None;
} }
@ -279,7 +279,7 @@ fn is_from_private_dep(tcx: TyCtxt<'_>, cache: &Cache, def_id: DefId) -> bool {
.cache .cache
.parent_stack .parent_stack
.last() .last()
.map_or(false, |parent| parent.is_trait_impl()) => .is_some_and(|parent| parent.is_trait_impl()) =>
{ {
// skip associated items in trait impls // skip associated items in trait impls
((None, None), false) ((None, None), false)
@ -341,7 +341,7 @@ fn is_from_private_dep(tcx: TyCtxt<'_>, cache: &Cache, def_id: DefId) -> bool {
// A crate has a module at its root, containing all items, // A crate has a module at its root, containing all items,
// which should not be indexed. The crate-item itself is // which should not be indexed. The crate-item itself is
// inserted later on when serializing the search-index. // inserted later on when serializing the search-index.
if item.item_id.as_def_id().map_or(false, |idx| !idx.is_crate_root()) if item.item_id.as_def_id().is_some_and(|idx| !idx.is_crate_root())
&& let ty = item.type_() && let ty = item.type_()
&& (ty != ItemType::StructField && (ty != ItemType::StructField
|| u16::from_str_radix(s.as_str(), 10).is_err()) || u16::from_str_radix(s.as_str(), 10).is_err())

View File

@ -1381,8 +1381,7 @@ pub(crate) fn notable_traits_button(ty: &clean::Type, cx: &mut Context<'_>) -> O
if let Some(trait_) = &impl_.trait_ { if let Some(trait_) = &impl_.trait_ {
let trait_did = trait_.def_id(); let trait_did = trait_.def_id();
if cx.cache().traits.get(&trait_did).map_or(false, |t| t.is_notable_trait(cx.tcx())) if cx.cache().traits.get(&trait_did).is_some_and(|t| t.is_notable_trait(cx.tcx())) {
{
has_notable_trait = true; has_notable_trait = true;
} }
} }
@ -1417,7 +1416,7 @@ fn notable_traits_decl(ty: &clean::Type, cx: &Context<'_>) -> (String, String) {
if let Some(trait_) = &impl_.trait_ { if let Some(trait_) = &impl_.trait_ {
let trait_did = trait_.def_id(); let trait_did = trait_.def_id();
if cx.cache().traits.get(&trait_did).map_or(false, |t| t.is_notable_trait(cx.tcx())) { if cx.cache().traits.get(&trait_did).is_some_and(|t| t.is_notable_trait(cx.tcx())) {
if out.is_empty() { if out.is_empty() {
write!( write!(
&mut out, &mut out,

View File

@ -198,7 +198,7 @@ fn add_deref_target(
cleaner.keep_impl( cleaner.keep_impl(
for_, for_,
trait_.as_ref().map(|t| t.def_id()) == tcx.lang_items().deref_trait(), trait_.as_ref().map(|t| t.def_id()) == tcx.lang_items().deref_trait(),
) || trait_.as_ref().map_or(false, |t| cleaner.keep_impl_with_def_id(t.def_id().into())) ) || trait_.as_ref().is_some_and(|t| cleaner.keep_impl_with_def_id(t.def_id().into()))
|| kind.is_blanket() || kind.is_blanket()
} else { } else {
true true