about summary refs log tree commit diff
path: root/compiler/rustc_middle/src/middle
diff options
context:
space:
mode:
authorOli Scherer <github333195615777966@oli-obk.de>2025-04-22 09:50:49 +0000
committerOli Scherer <github333195615777966@oli-obk.de>2025-04-22 11:02:37 +0000
commit5d2952100f587ee1badfd39280e6c90a28e35c3a (patch)
tree78346d72f5c35cc937f8d08b49cb3a3306363820 /compiler/rustc_middle/src/middle
parent9bfa31f632912180dc742809bcc51a97f2d7079d (diff)
downloadrust-5d2952100f587ee1badfd39280e6c90a28e35c3a.tar.gz
rust-5d2952100f587ee1badfd39280e6c90a28e35c3a.zip
Use `is_lang_item` and `as_lang_item` instead of handrolling their logic
Diffstat (limited to 'compiler/rustc_middle/src/middle')
-rw-r--r--compiler/rustc_middle/src/middle/lang_items.rs18
1 files changed, 8 insertions, 10 deletions
diff --git a/compiler/rustc_middle/src/middle/lang_items.rs b/compiler/rustc_middle/src/middle/lang_items.rs
index 7a91bfad483..0f92c1910f1 100644
--- a/compiler/rustc_middle/src/middle/lang_items.rs
+++ b/compiler/rustc_middle/src/middle/lang_items.rs
@@ -35,11 +35,10 @@ impl<'tcx> TyCtxt<'tcx> {
     /// 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),
-            x if x == items.fn_mut_trait() => Some(ty::ClosureKind::FnMut),
-            x if x == items.fn_once_trait() => Some(ty::ClosureKind::FnOnce),
+        match self.as_lang_item(id)? {
+            LangItem::Fn => Some(ty::ClosureKind::Fn),
+            LangItem::FnMut => Some(ty::ClosureKind::FnMut),
+            LangItem::FnOnce => Some(ty::ClosureKind::FnOnce),
             _ => None,
         }
     }
@@ -48,11 +47,10 @@ impl<'tcx> TyCtxt<'tcx> {
     /// returns a corresponding [`ty::ClosureKind`].
     /// For any other [`DefId`] return `None`.
     pub fn async_fn_trait_kind_from_def_id(self, id: DefId) -> Option<ty::ClosureKind> {
-        let items = self.lang_items();
-        match Some(id) {
-            x if x == items.async_fn_trait() => Some(ty::ClosureKind::Fn),
-            x if x == items.async_fn_mut_trait() => Some(ty::ClosureKind::FnMut),
-            x if x == items.async_fn_once_trait() => Some(ty::ClosureKind::FnOnce),
+        match self.as_lang_item(id)? {
+            LangItem::AsyncFn => Some(ty::ClosureKind::Fn),
+            LangItem::AsyncFnMut => Some(ty::ClosureKind::FnMut),
+            LangItem::AsyncFnOnce => Some(ty::ClosureKind::FnOnce),
             _ => None,
         }
     }