Rollup merge of #76995 - LingMan:middle_matches, r=varkor
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. Limited to rustc_middle for now to get my feet wet.
This commit is contained in:
commit
d50349ba8d
13 changed files with 140 additions and 269 deletions
|
@ -2681,15 +2681,15 @@ impl<'tcx> ClosureKind {
|
|||
/// Returns `true` if 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.
|
||||
|
@ -2815,15 +2815,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))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue