1
Fork 0

Reduce boilerplate with the matches! macro

Replaces simple bool `match`es of the form

    match $expr {
        $pattern => true
        _ => false
    }

and their inverse with invocations of the matches! macro.
This commit is contained in:
LingMan 2020-09-21 04:53:44 +02:00
parent 0f9f0b384a
commit a6ff925f8b
13 changed files with 140 additions and 269 deletions

View file

@ -2675,15 +2675,15 @@ impl<'tcx> ClosureKind {
/// Returns `true` if this a type that impls this closure kind
/// must also implement `other`.
pub fn extends(self, other: ty::ClosureKind) -> bool {
match (self, other) {
(ClosureKind::Fn, ClosureKind::Fn) => true,
(ClosureKind::Fn, ClosureKind::FnMut) => true,
(ClosureKind::Fn, ClosureKind::FnOnce) => true,
(ClosureKind::FnMut, ClosureKind::FnMut) => true,
(ClosureKind::FnMut, ClosureKind::FnOnce) => true,
(ClosureKind::FnOnce, ClosureKind::FnOnce) => true,
_ => false,
}
matches!(
(self, other),
(ClosureKind::Fn, ClosureKind::Fn)
| (ClosureKind::Fn, ClosureKind::FnMut)
| (ClosureKind::Fn, ClosureKind::FnOnce)
| (ClosureKind::FnMut, ClosureKind::FnMut)
| (ClosureKind::FnMut, ClosureKind::FnOnce)
| (ClosureKind::FnOnce, ClosureKind::FnOnce)
)
}
/// Returns the representative scalar type for this closure kind.
@ -2809,15 +2809,15 @@ impl<'tcx> TyCtxt<'tcx> {
pub fn opt_associated_item(self, def_id: DefId) -> Option<&'tcx AssocItem> {
let is_associated_item = if let Some(def_id) = def_id.as_local() {
match self.hir().get(self.hir().local_def_id_to_hir_id(def_id)) {
Node::TraitItem(_) | Node::ImplItem(_) => true,
_ => false,
}
matches!(
self.hir().get(self.hir().local_def_id_to_hir_id(def_id)),
Node::TraitItem(_) | Node::ImplItem(_)
)
} else {
match self.def_kind(def_id) {
DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy => true,
_ => false,
}
matches!(
self.def_kind(def_id),
DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy
)
};
is_associated_item.then(|| self.associated_item(def_id))