Move special methods from ClosureKind back into rustc

This commit is contained in:
Michael Goulet
2023-12-14 19:10:03 +00:00
parent 9f0849f9e0
commit 742f193ef8
8 changed files with 27 additions and 57 deletions

View File

@@ -36,6 +36,17 @@ impl<'tcx> TyCtxt<'tcx> {
}
}
/// Given a [`ty::ClosureKind`], get the [`DefId`] of its corresponding `Fn`-family
/// trait, if it is defined.
pub fn fn_trait_kind_to_def_id(self, kind: ty::ClosureKind) -> Option<DefId> {
let items = self.lang_items();
match kind {
ty::ClosureKind::Fn => items.fn_trait(),
ty::ClosureKind::FnMut => items.fn_mut_trait(),
ty::ClosureKind::FnOnce => items.fn_once_trait(),
}
}
/// Returns `true` if `id` is a `DefId` of [`Fn`], [`FnMut`] or [`FnOnce`] traits.
pub fn is_fn_trait(self, id: DefId) -> bool {
self.fn_trait_kind_from_def_id(id).is_some()