From a4021f6ed5d807e4af98178e4cd2bcf66d8c977f Mon Sep 17 00:00:00 2001 From: Shoyu Vanilla Date: Tue, 27 Feb 2024 00:38:53 +0900 Subject: [PATCH] Use lang-item instead of db lookup for `FnTrait` kind --- crates/hir-ty/src/infer/closure.rs | 10 +--------- crates/hir-ty/src/traits.rs | 9 +++++++++ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/crates/hir-ty/src/infer/closure.rs b/crates/hir-ty/src/infer/closure.rs index 62740f354c..32845ac2e3 100644 --- a/crates/hir-ty/src/infer/closure.rs +++ b/crates/hir-ty/src/infer/closure.rs @@ -177,15 +177,7 @@ impl InferenceContext<'_> { } fn fn_trait_kind_from_trait_id(&self, trait_id: hir_def::TraitId) -> Option { - utils::fn_traits(self.db.upcast(), self.owner.module(self.db.upcast()).krate()) - .enumerate() - .find_map(|(i, t)| (t == trait_id).then_some(i)) - .map(|i| match i { - 0 => FnTrait::Fn, - 1 => FnTrait::FnMut, - 2 => FnTrait::FnOnce, - _ => unreachable!(), - }) + FnTrait::from_lang_item(self.db.lang_attr(trait_id.into())?) } } diff --git a/crates/hir-ty/src/traits.rs b/crates/hir-ty/src/traits.rs index b2232b920a..8b692a1cc1 100644 --- a/crates/hir-ty/src/traits.rs +++ b/crates/hir-ty/src/traits.rs @@ -217,6 +217,15 @@ impl FnTrait { } } + pub const fn from_lang_item(lang_item: LangItem) -> Option { + match lang_item { + LangItem::FnOnce => Some(FnTrait::FnOnce), + LangItem::FnMut => Some(FnTrait::FnMut), + LangItem::Fn => Some(FnTrait::Fn), + _ => None, + } + } + pub const fn to_chalk_ir(self) -> rust_ir::ClosureKind { match self { FnTrait::FnOnce => rust_ir::ClosureKind::FnOnce,