Skip to content

Commit

Permalink
Use lang-item instead of db lookup for FnTrait kind
Browse files Browse the repository at this point in the history
  • Loading branch information
ShoyuVanilla committed Feb 26, 2024
1 parent 46cdce1 commit a4021f6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
10 changes: 1 addition & 9 deletions crates/hir-ty/src/infer/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,7 @@ impl InferenceContext<'_> {
}

fn fn_trait_kind_from_trait_id(&self, trait_id: hir_def::TraitId) -> Option<FnTrait> {
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())?)
}
}

Expand Down
9 changes: 9 additions & 0 deletions crates/hir-ty/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,15 @@ impl FnTrait {
}
}

pub const fn from_lang_item(lang_item: LangItem) -> Option<Self> {
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,
Expand Down

0 comments on commit a4021f6

Please sign in to comment.