diff options
Diffstat (limited to '')
-rw-r--r-- | compiler/rustc_middle/src/middle/lang_items.rs | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/compiler/rustc_middle/src/middle/lang_items.rs b/compiler/rustc_middle/src/middle/lang_items.rs index 31c20fa14..343ea1f00 100644 --- a/compiler/rustc_middle/src/middle/lang_items.rs +++ b/compiler/rustc_middle/src/middle/lang_items.rs @@ -27,7 +27,10 @@ impl<'tcx> TyCtxt<'tcx> { }) } - pub fn fn_trait_kind_from_lang_item(self, id: DefId) -> Option<ty::ClosureKind> { + /// Given a [`DefId`] of a [`Fn`], [`FnMut`] or [`FnOnce`] traits, + /// returns a corresponding [`ty::ClosureKind`]. + /// For any other [`DefId`] return `None`. + pub fn fn_trait_kind_from_def_id(self, id: DefId) -> Option<ty::ClosureKind> { let items = self.lang_items(); match Some(id) { x if x == items.fn_trait() => Some(ty::ClosureKind::Fn), @@ -37,8 +40,9 @@ impl<'tcx> TyCtxt<'tcx> { } } - pub fn is_weak_lang_item(self, item_def_id: DefId) -> bool { - self.lang_items().is_weak_lang_item(item_def_id) + /// 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() } } |