mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
Remove exposing unification
This commit is contained in:
parent
d9bb86ad7d
commit
e11cd8fe35
4 changed files with 1 additions and 23 deletions
|
@ -1118,12 +1118,6 @@ impl Local {
|
||||||
ast.map_left(|it| it.cast().unwrap().to_node(&root)).map_right(|it| it.to_node(&root))
|
ast.map_left(|it| it.cast().unwrap().to_node(&root)).map_right(|it| it.to_node(&root))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn can_unify(self, other: Type, db: &dyn HirDatabase) -> bool {
|
|
||||||
let def = DefWithBodyId::from(self.parent);
|
|
||||||
let infer = db.infer(def);
|
|
||||||
db.can_unify(def, infer[self.pat_id].clone(), other.ty.value)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||||
|
|
|
@ -26,9 +26,6 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
|
||||||
#[salsa::invoke(crate::infer::infer_query)]
|
#[salsa::invoke(crate::infer::infer_query)]
|
||||||
fn infer_query(&self, def: DefWithBodyId) -> Arc<InferenceResult>;
|
fn infer_query(&self, def: DefWithBodyId) -> Arc<InferenceResult>;
|
||||||
|
|
||||||
#[salsa::invoke(crate::infer::can_unify)]
|
|
||||||
fn can_unify(&self, def: DefWithBodyId, ty1: Ty, ty2: Ty) -> bool;
|
|
||||||
|
|
||||||
#[salsa::invoke(crate::lower::ty_query)]
|
#[salsa::invoke(crate::lower::ty_query)]
|
||||||
#[salsa::cycle(crate::lower::ty_recover)]
|
#[salsa::cycle(crate::lower::ty_recover)]
|
||||||
fn ty(&self, def: TyDefId) -> Binders<Ty>;
|
fn ty(&self, def: TyDefId) -> Binders<Ty>;
|
||||||
|
|
|
@ -78,19 +78,6 @@ pub(crate) fn infer_query(db: &dyn HirDatabase, def: DefWithBodyId) -> Arc<Infer
|
||||||
Arc::new(ctx.resolve_all())
|
Arc::new(ctx.resolve_all())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn can_unify(db: &dyn HirDatabase, def: DefWithBodyId, ty1: Ty, ty2: Ty) -> bool {
|
|
||||||
let resolver = def.resolver(db.upcast());
|
|
||||||
let mut ctx = InferenceContext::new(db, def, resolver);
|
|
||||||
|
|
||||||
let ty1 = ctx.canonicalizer().canonicalize_ty(ty1).value;
|
|
||||||
let ty2 = ctx.canonicalizer().canonicalize_ty(ty2).value;
|
|
||||||
let mut kinds = Vec::from(ty1.kinds.to_vec());
|
|
||||||
kinds.extend_from_slice(ty2.kinds.as_ref());
|
|
||||||
let tys = crate::Canonical::new((ty1.value, ty2.value), kinds);
|
|
||||||
|
|
||||||
unify(&tys).is_some()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
|
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
|
||||||
enum ExprOrPatId {
|
enum ExprOrPatId {
|
||||||
ExprId(ExprId),
|
ExprId(ExprId),
|
||||||
|
|
|
@ -194,7 +194,7 @@ impl Completions {
|
||||||
fn add_arg(arg: &str, ty: &Type, ctx: &CompletionContext) -> String {
|
fn add_arg(arg: &str, ty: &Type, ctx: &CompletionContext) -> String {
|
||||||
if let Some(derefed_ty) = ty.remove_ref() {
|
if let Some(derefed_ty) = ty.remove_ref() {
|
||||||
for (name, local) in ctx.locals.iter() {
|
for (name, local) in ctx.locals.iter() {
|
||||||
if name == arg && local.can_unify(derefed_ty.clone(), ctx.db) {
|
if name == arg && local.ty(ctx.db) == derefed_ty {
|
||||||
return (if ty.is_mutable_reference() { "&mut " } else { "&" }).to_string()
|
return (if ty.is_mutable_reference() { "&mut " } else { "&" }).to_string()
|
||||||
+ &arg.to_string();
|
+ &arg.to_string();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue