Skip to content

Commit 63b2f55

Browse files
is_{some,ok}_and for rustdoc
1 parent fe3038f commit 63b2f55

File tree

6 files changed

+12
-14
lines changed

6 files changed

+12
-14
lines changed

src/librustdoc/clean/types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ impl Item {
498498
}
499499

500500
pub(crate) fn is_crate(&self) -> bool {
501-
self.is_mod() && self.def_id().map_or(false, |did| did.is_crate_root())
501+
self.is_mod() && self.def_id().is_some_and(|did| did.is_crate_root())
502502
}
503503
pub(crate) fn is_mod(&self) -> bool {
504504
self.type_() == ItemType::Module
@@ -2487,7 +2487,7 @@ impl Import {
24872487
}
24882488

24892489
pub(crate) fn imported_item_is_doc_hidden(&self, tcx: TyCtxt<'_>) -> bool {
2490-
self.source.did.map_or(false, |did| tcx.is_doc_hidden(did))
2490+
self.source.did.is_some_and(|did| tcx.is_doc_hidden(did))
24912491
}
24922492
}
24932493

src/librustdoc/clean/utils.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -573,9 +573,8 @@ pub(crate) fn find_nearest_parent_module(tcx: TyCtxt<'_>, def_id: DefId) -> Opti
573573
/// This function exists because it runs on `hir::Attributes` whereas the other is a
574574
/// `clean::Attributes` method.
575575
pub(crate) fn has_doc_flag(tcx: TyCtxt<'_>, did: DefId, flag: Symbol) -> bool {
576-
tcx.get_attrs(did, sym::doc).any(|attr| {
577-
attr.meta_item_list().map_or(false, |l| rustc_attr::list_contains_name(&l, flag))
578-
})
576+
tcx.get_attrs(did, sym::doc)
577+
.any(|attr| attr.meta_item_list().is_some_and(|l| rustc_attr::list_contains_name(&l, flag)))
579578
}
580579

581580
/// A link to `doc.rust-lang.org` that includes the channel name. Use this instead of manual links

src/librustdoc/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ impl Options {
798798

799799
/// Returns `true` if the file given as `self.input` is a Markdown file.
800800
pub(crate) fn markdown_input(&self) -> bool {
801-
self.input.extension().map_or(false, |e| e == "md" || e == "markdown")
801+
self.input.extension().is_some_and(|e| e == "md" || e == "markdown")
802802
}
803803
}
804804

src/librustdoc/formats/cache.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,10 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
234234
&& (self.cache.masked_crates.contains(&item.item_id.krate())
235235
|| i.trait_
236236
.as_ref()
237-
.map_or(false, |t| is_from_private_dep(self.tcx, self.cache, t.def_id()))
237+
.is_some_and(|t| is_from_private_dep(self.tcx, self.cache, t.def_id()))
238238
|| i.for_
239239
.def_id(self.cache)
240-
.map_or(false, |d| is_from_private_dep(self.tcx, self.cache, d)))
240+
.is_some_and(|d| is_from_private_dep(self.tcx, self.cache, d)))
241241
{
242242
return None;
243243
}
@@ -279,7 +279,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
279279
.cache
280280
.parent_stack
281281
.last()
282-
.map_or(false, |parent| parent.is_trait_impl()) =>
282+
.is_some_and(|parent| parent.is_trait_impl()) =>
283283
{
284284
// skip associated items in trait impls
285285
((None, None), false)
@@ -341,7 +341,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
341341
// A crate has a module at its root, containing all items,
342342
// which should not be indexed. The crate-item itself is
343343
// inserted later on when serializing the search-index.
344-
if item.item_id.as_def_id().map_or(false, |idx| !idx.is_crate_root())
344+
if item.item_id.as_def_id().is_some_and(|idx| !idx.is_crate_root())
345345
&& let ty = item.type_()
346346
&& (ty != ItemType::StructField
347347
|| u16::from_str_radix(s.as_str(), 10).is_err())

src/librustdoc/html/render/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1381,8 +1381,7 @@ pub(crate) fn notable_traits_button(ty: &clean::Type, cx: &mut Context<'_>) -> O
13811381
if let Some(trait_) = &impl_.trait_ {
13821382
let trait_did = trait_.def_id();
13831383

1384-
if cx.cache().traits.get(&trait_did).map_or(false, |t| t.is_notable_trait(cx.tcx()))
1385-
{
1384+
if cx.cache().traits.get(&trait_did).is_some_and(|t| t.is_notable_trait(cx.tcx())) {
13861385
has_notable_trait = true;
13871386
}
13881387
}
@@ -1417,7 +1416,7 @@ fn notable_traits_decl(ty: &clean::Type, cx: &Context<'_>) -> (String, String) {
14171416
if let Some(trait_) = &impl_.trait_ {
14181417
let trait_did = trait_.def_id();
14191418

1420-
if cx.cache().traits.get(&trait_did).map_or(false, |t| t.is_notable_trait(cx.tcx())) {
1419+
if cx.cache().traits.get(&trait_did).is_some_and(|t| t.is_notable_trait(cx.tcx())) {
14211420
if out.is_empty() {
14221421
write!(
14231422
&mut out,

src/librustdoc/passes/collect_trait_impls.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) ->
198198
cleaner.keep_impl(
199199
for_,
200200
trait_.as_ref().map(|t| t.def_id()) == tcx.lang_items().deref_trait(),
201-
) || trait_.as_ref().map_or(false, |t| cleaner.keep_impl_with_def_id(t.def_id().into()))
201+
) || trait_.as_ref().is_some_and(|t| cleaner.keep_impl_with_def_id(t.def_id().into()))
202202
|| kind.is_blanket()
203203
} else {
204204
true

0 commit comments

Comments
 (0)