diff options
author | adamrk <[email protected]> | 2020-09-02 21:33:54 +0100 |
---|---|---|
committer | adamrk <[email protected]> | 2020-09-02 21:33:54 +0100 |
commit | e11cd8fe35fbb4fcaf7859f4cef2dbd94ff7d230 (patch) | |
tree | 151d1188da4ce2a5a41d730bcc64ffd42e5447aa | |
parent | d9bb86ad7dfd17543e6e1c9ef184337f828b1027 (diff) |
Remove exposing unification
-rw-r--r-- | crates/hir/src/code_model.rs | 6 | ||||
-rw-r--r-- | crates/hir_ty/src/db.rs | 3 | ||||
-rw-r--r-- | crates/hir_ty/src/infer.rs | 13 | ||||
-rw-r--r-- | crates/ide/src/completion/presentation.rs | 2 |
4 files changed, 1 insertions, 23 deletions
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index afbf78b3b..dc3a1699f 100644 --- a/crates/hir/src/code_model.rs +++ b/crates/hir/src/code_model.rs | |||
@@ -1118,12 +1118,6 @@ impl Local { | |||
1118 | ast.map_left(|it| it.cast().unwrap().to_node(&root)).map_right(|it| it.to_node(&root)) | 1118 | ast.map_left(|it| it.cast().unwrap().to_node(&root)).map_right(|it| it.to_node(&root)) |
1119 | }) | 1119 | }) |
1120 | } | 1120 | } |
1121 | |||
1122 | pub fn can_unify(self, other: Type, db: &dyn HirDatabase) -> bool { | ||
1123 | let def = DefWithBodyId::from(self.parent); | ||
1124 | let infer = db.infer(def); | ||
1125 | db.can_unify(def, infer[self.pat_id].clone(), other.ty.value) | ||
1126 | } | ||
1127 | } | 1121 | } |
1128 | 1122 | ||
1129 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | 1123 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] |
diff --git a/crates/hir_ty/src/db.rs b/crates/hir_ty/src/db.rs index 57e60c53b..25cf9eb7f 100644 --- a/crates/hir_ty/src/db.rs +++ b/crates/hir_ty/src/db.rs | |||
@@ -26,9 +26,6 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> { | |||
26 | #[salsa::invoke(crate::infer::infer_query)] | 26 | #[salsa::invoke(crate::infer::infer_query)] |
27 | fn infer_query(&self, def: DefWithBodyId) -> Arc<InferenceResult>; | 27 | fn infer_query(&self, def: DefWithBodyId) -> Arc<InferenceResult>; |
28 | 28 | ||
29 | #[salsa::invoke(crate::infer::can_unify)] | ||
30 | fn can_unify(&self, def: DefWithBodyId, ty1: Ty, ty2: Ty) -> bool; | ||
31 | |||
32 | #[salsa::invoke(crate::lower::ty_query)] | 29 | #[salsa::invoke(crate::lower::ty_query)] |
33 | #[salsa::cycle(crate::lower::ty_recover)] | 30 | #[salsa::cycle(crate::lower::ty_recover)] |
34 | fn ty(&self, def: TyDefId) -> Binders<Ty>; | 31 | fn ty(&self, def: TyDefId) -> Binders<Ty>; |
diff --git a/crates/hir_ty/src/infer.rs b/crates/hir_ty/src/infer.rs index d461e077b..2db05ae78 100644 --- a/crates/hir_ty/src/infer.rs +++ b/crates/hir_ty/src/infer.rs | |||
@@ -78,19 +78,6 @@ pub(crate) fn infer_query(db: &dyn HirDatabase, def: DefWithBodyId) -> Arc<Infer | |||
78 | Arc::new(ctx.resolve_all()) | 78 | Arc::new(ctx.resolve_all()) |
79 | } | 79 | } |
80 | 80 | ||
81 | pub(crate) fn can_unify(db: &dyn HirDatabase, def: DefWithBodyId, ty1: Ty, ty2: Ty) -> bool { | ||
82 | let resolver = def.resolver(db.upcast()); | ||
83 | let mut ctx = InferenceContext::new(db, def, resolver); | ||
84 | |||
85 | let ty1 = ctx.canonicalizer().canonicalize_ty(ty1).value; | ||
86 | let ty2 = ctx.canonicalizer().canonicalize_ty(ty2).value; | ||
87 | let mut kinds = Vec::from(ty1.kinds.to_vec()); | ||
88 | kinds.extend_from_slice(ty2.kinds.as_ref()); | ||
89 | let tys = crate::Canonical::new((ty1.value, ty2.value), kinds); | ||
90 | |||
91 | unify(&tys).is_some() | ||
92 | } | ||
93 | |||
94 | #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] | 81 | #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] |
95 | enum ExprOrPatId { | 82 | enum ExprOrPatId { |
96 | ExprId(ExprId), | 83 | ExprId(ExprId), |
diff --git a/crates/ide/src/completion/presentation.rs b/crates/ide/src/completion/presentation.rs index 059fdfdc9..c7d460465 100644 --- a/crates/ide/src/completion/presentation.rs +++ b/crates/ide/src/completion/presentation.rs | |||
@@ -194,7 +194,7 @@ impl Completions { | |||
194 | fn add_arg(arg: &str, ty: &Type, ctx: &CompletionContext) -> String { | 194 | fn add_arg(arg: &str, ty: &Type, ctx: &CompletionContext) -> String { |
195 | if let Some(derefed_ty) = ty.remove_ref() { | 195 | if let Some(derefed_ty) = ty.remove_ref() { |
196 | for (name, local) in ctx.locals.iter() { | 196 | for (name, local) in ctx.locals.iter() { |
197 | if name == arg && local.can_unify(derefed_ty.clone(), ctx.db) { | 197 | if name == arg && local.ty(ctx.db) == derefed_ty { |
198 | return (if ty.is_mutable_reference() { "&mut " } else { "&" }).to_string() | 198 | return (if ty.is_mutable_reference() { "&mut " } else { "&" }).to_string() |
199 | + &arg.to_string(); | 199 | + &arg.to_string(); |
200 | } | 200 | } |