Use Option::is_some_and
and Result::is_ok_and
in the compiler
This commit is contained in:
parent
70db836922
commit
fb0f74a8c9
87 changed files with 148 additions and 158 deletions
|
@ -410,7 +410,7 @@ impl<'hir> Map<'hir> {
|
|||
/// item (possibly associated), a closure, or a `hir::AnonConst`.
|
||||
pub fn body_owner(self, BodyId { hir_id }: BodyId) -> HirId {
|
||||
let parent = self.parent_id(hir_id);
|
||||
assert!(self.find(parent).map_or(false, |n| is_body_owner(n, hir_id)), "{hir_id:?}");
|
||||
assert!(self.find(parent).is_some_and(|n| is_body_owner(n, hir_id)), "{hir_id:?}");
|
||||
parent
|
||||
}
|
||||
|
||||
|
|
|
@ -115,7 +115,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
/// Returns `true` if this is a foreign item (i.e., linked via `extern { ... }`).
|
||||
pub fn is_foreign_item(self, def_id: impl Into<DefId>) -> bool {
|
||||
self.opt_parent(def_id.into())
|
||||
.map_or(false, |parent| matches!(self.def_kind(parent), DefKind::ForeignMod))
|
||||
.is_some_and(|parent| matches!(self.def_kind(parent), DefKind::ForeignMod))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -94,8 +94,7 @@ pub struct EffectiveVisibilities<Id = LocalDefId> {
|
|||
|
||||
impl EffectiveVisibilities {
|
||||
pub fn is_public_at_level(&self, id: LocalDefId, level: Level) -> bool {
|
||||
self.effective_vis(id)
|
||||
.map_or(false, |effective_vis| effective_vis.is_public_at_level(level))
|
||||
self.effective_vis(id).is_some_and(|effective_vis| effective_vis.is_public_at_level(level))
|
||||
}
|
||||
|
||||
/// See `Level::Reachable`.
|
||||
|
|
|
@ -375,7 +375,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
let parent_def_id = self.hir().get_parent_item(id);
|
||||
let skip = self
|
||||
.lookup_deprecation_entry(parent_def_id.to_def_id())
|
||||
.map_or(false, |parent_depr| parent_depr.same_origin(&depr_entry));
|
||||
.is_some_and(|parent_depr| parent_depr.same_origin(&depr_entry));
|
||||
|
||||
// #[deprecated] doesn't emit a notice if we're not on the
|
||||
// topmost deprecation. For example, if a struct is deprecated,
|
||||
|
|
|
@ -2341,7 +2341,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
}
|
||||
|
||||
pub fn is_late_bound(self, id: HirId) -> bool {
|
||||
self.is_late_bound_map(id.owner).map_or(false, |set| set.contains(&id.local_id))
|
||||
self.is_late_bound_map(id.owner).is_some_and(|set| set.contains(&id.local_id))
|
||||
}
|
||||
|
||||
pub fn late_bound_vars(self, id: HirId) -> &'tcx List<ty::BoundVariableKind> {
|
||||
|
@ -2474,7 +2474,7 @@ pub fn provide(providers: &mut Providers) {
|
|||
|tcx, LocalCrate| attr::contains_name(tcx.hir().krate_attrs(), sym::compiler_builtins);
|
||||
providers.has_panic_handler = |tcx, LocalCrate| {
|
||||
// We want to check if the panic handler was defined in this crate
|
||||
tcx.lang_items().panic_impl().map_or(false, |did| did.is_local())
|
||||
tcx.lang_items().panic_impl().is_some_and(|did| did.is_local())
|
||||
};
|
||||
providers.source_span = |tcx, def_id| tcx.untracked.source_span.get(def_id).unwrap_or(DUMMY_SP);
|
||||
}
|
||||
|
|
|
@ -298,7 +298,7 @@ impl<'tcx> Generics {
|
|||
.iter()
|
||||
.rev()
|
||||
.take_while(|param| {
|
||||
param.default_value(tcx).map_or(false, |default| {
|
||||
param.default_value(tcx).is_some_and(|default| {
|
||||
default.subst(tcx, substs) == substs[param.index as usize]
|
||||
})
|
||||
})
|
||||
|
|
|
@ -659,7 +659,7 @@ fn polymorphize<'tcx>(
|
|||
} else {
|
||||
None
|
||||
};
|
||||
let has_upvars = upvars_ty.map_or(false, |ty| !ty.tuple_fields().is_empty());
|
||||
let has_upvars = upvars_ty.is_some_and(|ty| !ty.tuple_fields().is_empty());
|
||||
debug!("polymorphize: upvars_ty={:?} has_upvars={:?}", upvars_ty, has_upvars);
|
||||
|
||||
struct PolymorphizationFolder<'tcx> {
|
||||
|
|
|
@ -2220,8 +2220,8 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
let impl_trait_ref2 = self.impl_trait_ref(def_id2);
|
||||
// If either trait impl references an error, they're allowed to overlap,
|
||||
// as one of them essentially doesn't exist.
|
||||
if impl_trait_ref1.map_or(false, |tr| tr.subst_identity().references_error())
|
||||
|| impl_trait_ref2.map_or(false, |tr| tr.subst_identity().references_error())
|
||||
if impl_trait_ref1.is_some_and(|tr| tr.subst_identity().references_error())
|
||||
|| impl_trait_ref2.is_some_and(|tr| tr.subst_identity().references_error())
|
||||
{
|
||||
return Some(ImplOverlapKind::Permitted { marker: false });
|
||||
}
|
||||
|
@ -2242,7 +2242,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
|
||||
let is_marker_overlap = {
|
||||
let is_marker_impl = |trait_ref: Option<EarlyBinder<TraitRef<'_>>>| -> bool {
|
||||
trait_ref.map_or(false, |tr| self.trait_def(tr.skip_binder().def_id).is_marker)
|
||||
trait_ref.is_some_and(|tr| self.trait_def(tr.skip_binder().def_id).is_marker)
|
||||
};
|
||||
is_marker_impl(impl_trait_ref1) && is_marker_impl(impl_trait_ref2)
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue