Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/traits.rs')
-rw-r--r--crates/hir-ty/src/traits.rs65
1 files changed, 12 insertions, 53 deletions
diff --git a/crates/hir-ty/src/traits.rs b/crates/hir-ty/src/traits.rs
index 2055c3151c..1462f1e317 100644
--- a/crates/hir-ty/src/traits.rs
+++ b/crates/hir-ty/src/traits.rs
@@ -1,12 +1,11 @@
//! Trait solving using next trait solver.
-use core::fmt;
use std::hash::Hash;
use base_db::Crate;
use hir_def::{
AdtId, AssocItemId, BlockId, HasModule, ImplId, Lookup, TraitId,
- lang_item::LangItem,
+ lang_item::LangItems,
nameres::DefMap,
signatures::{ConstFlags, EnumFlags, FnFlags, StructFlags, TraitFlags, TypeAliasFlags},
};
@@ -152,7 +151,7 @@ pub fn next_trait_solve_in_ctxt<'db, 'a>(
res
}
-#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
+#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, salsa::Update)]
pub enum FnTrait {
// Warning: Order is important. If something implements `x` it should also implement
// `y` if `y <= x`.
@@ -165,54 +164,7 @@ pub enum FnTrait {
AsyncFn,
}
-impl fmt::Display for FnTrait {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- match self {
- FnTrait::FnOnce => write!(f, "FnOnce"),
- FnTrait::FnMut => write!(f, "FnMut"),
- FnTrait::Fn => write!(f, "Fn"),
- FnTrait::AsyncFnOnce => write!(f, "AsyncFnOnce"),
- FnTrait::AsyncFnMut => write!(f, "AsyncFnMut"),
- FnTrait::AsyncFn => write!(f, "AsyncFn"),
- }
- }
-}
-
impl FnTrait {
- pub const fn function_name(&self) -> &'static str {
- match self {
- FnTrait::FnOnce => "call_once",
- FnTrait::FnMut => "call_mut",
- FnTrait::Fn => "call",
- FnTrait::AsyncFnOnce => "async_call_once",
- FnTrait::AsyncFnMut => "async_call_mut",
- FnTrait::AsyncFn => "async_call",
- }
- }
-
- const fn lang_item(self) -> LangItem {
- match self {
- FnTrait::FnOnce => LangItem::FnOnce,
- FnTrait::FnMut => LangItem::FnMut,
- FnTrait::Fn => LangItem::Fn,
- FnTrait::AsyncFnOnce => LangItem::AsyncFnOnce,
- FnTrait::AsyncFnMut => LangItem::AsyncFnMut,
- FnTrait::AsyncFn => LangItem::AsyncFn,
- }
- }
-
- 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),
- LangItem::AsyncFnOnce => Some(FnTrait::AsyncFnOnce),
- LangItem::AsyncFnMut => Some(FnTrait::AsyncFnMut),
- LangItem::AsyncFn => Some(FnTrait::AsyncFn),
- _ => None,
- }
- }
-
pub fn method_name(self) -> Name {
match self {
FnTrait::FnOnce => Name::new_symbol_root(sym::call_once),
@@ -224,8 +176,15 @@ impl FnTrait {
}
}
- pub fn get_id(self, db: &dyn HirDatabase, krate: Crate) -> Option<TraitId> {
- self.lang_item().resolve_trait(db, krate)
+ pub fn get_id(self, lang_items: &LangItems) -> Option<TraitId> {
+ match self {
+ FnTrait::FnOnce => lang_items.FnOnce,
+ FnTrait::FnMut => lang_items.FnMut,
+ FnTrait::Fn => lang_items.Fn,
+ FnTrait::AsyncFnOnce => lang_items.AsyncFnOnce,
+ FnTrait::AsyncFnMut => lang_items.AsyncFnMut,
+ FnTrait::AsyncFn => lang_items.AsyncFn,
+ }
}
}
@@ -257,7 +216,7 @@ fn implements_trait_unique_impl<'db>(
trait_: TraitId,
create_args: &mut dyn FnMut(&InferCtxt<'db>) -> GenericArgs<'db>,
) -> bool {
- let interner = DbInterner::new_with(db, Some(env.krate), env.block);
+ let interner = DbInterner::new_with(db, env.krate);
// FIXME(next-solver): I believe this should be `PostAnalysis`.
let infcx = interner.infer_ctxt().build(TypingMode::non_body_analysis());