From c6ddb907144688ae77a6de3666159feef53638e1 Mon Sep 17 00:00:00 2001 From: adamrk Date: Sat, 22 Aug 2020 20:11:37 +0200 Subject: Add references to fn args during completion --- crates/hir/src/code_model.rs | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) (limited to 'crates/hir/src/code_model.rs') diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index c2fc819e7..f182ab228 100644 --- a/crates/hir/src/code_model.rs +++ b/crates/hir/src/code_model.rs @@ -708,12 +708,24 @@ impl Function { Some(SelfParam { func: self.id }) } - pub fn params(self, db: &dyn HirDatabase) -> Vec { + pub fn params(self, db: &dyn HirDatabase) -> Vec { + let resolver = self.id.resolver(db.upcast()); + let ctx = hir_ty::TyLoweringContext::new(db, &resolver); + let environment = TraitEnvironment::lower(db, &resolver); db.function_data(self.id) .params .iter() .skip(if self.self_param(db).is_some() { 1 } else { 0 }) - .map(|_| Param { _ty: () }) + .map(|type_ref| { + let ty = Type { + krate: self.id.lookup(db.upcast()).container.module(db.upcast()).krate, + ty: InEnvironment { + value: Ty::from_hir_ext(&ctx, type_ref).0, + environment: environment.clone(), + }, + }; + ty + }) .collect() } @@ -747,10 +759,6 @@ pub struct SelfParam { func: FunctionId, } -pub struct Param { - _ty: (), -} - impl SelfParam { pub fn access(self, db: &dyn HirDatabase) -> Access { let func_data = db.function_data(self.func); @@ -1100,6 +1108,12 @@ impl Local { 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)] @@ -1276,6 +1290,14 @@ impl Type { ) } + pub fn remove_ref(&self) -> Option { + if let Ty::Apply(ApplicationTy { ctor: TypeCtor::Ref(_), .. }) = self.ty.value { + self.ty.value.substs().map(|substs| self.derived(substs[0].clone())) + } else { + None + } + } + pub fn is_unknown(&self) -> bool { matches!(self.ty.value, Ty::Unknown) } -- cgit v1.2.3 From 04fc937700105951442a9b6fa30591fb48a1e879 Mon Sep 17 00:00:00 2001 From: adamrk Date: Tue, 1 Sep 2020 22:13:12 +0200 Subject: Add back Param struct --- crates/hir/src/code_model.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'crates/hir/src/code_model.rs') diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index f182ab228..afbf78b3b 100644 --- a/crates/hir/src/code_model.rs +++ b/crates/hir/src/code_model.rs @@ -708,7 +708,7 @@ impl Function { Some(SelfParam { func: self.id }) } - pub fn params(self, db: &dyn HirDatabase) -> Vec { + pub fn params(self, db: &dyn HirDatabase) -> Vec { let resolver = self.id.resolver(db.upcast()); let ctx = hir_ty::TyLoweringContext::new(db, &resolver); let environment = TraitEnvironment::lower(db, &resolver); @@ -724,7 +724,7 @@ impl Function { environment: environment.clone(), }, }; - ty + Param { ty } }) .collect() } @@ -754,6 +754,16 @@ impl From for Access { } } +pub struct Param { + ty: Type, +} + +impl Param { + pub fn ty(&self) -> &Type { + &self.ty + } +} + #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct SelfParam { func: FunctionId, -- cgit v1.2.3 From e11cd8fe35fbb4fcaf7859f4cef2dbd94ff7d230 Mon Sep 17 00:00:00 2001 From: adamrk Date: Wed, 2 Sep 2020 22:33:54 +0200 Subject: Remove exposing unification --- crates/hir/src/code_model.rs | 6 ------ 1 file changed, 6 deletions(-) (limited to 'crates/hir/src/code_model.rs') 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 { 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)] -- cgit v1.2.3