aboutsummaryrefslogtreecommitdiff
path: root/crates/hir/src/code_model.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir/src/code_model.rs')
-rw-r--r--crates/hir/src/code_model.rs34
1 files changed, 28 insertions, 6 deletions
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 {
708 Some(SelfParam { func: self.id }) 708 Some(SelfParam { func: self.id })
709 } 709 }
710 710
711 pub fn params(self, db: &dyn HirDatabase) -> Vec<Param> { 711 pub fn params(self, db: &dyn HirDatabase) -> Vec<Type> {
712 let resolver = self.id.resolver(db.upcast());
713 let ctx = hir_ty::TyLoweringContext::new(db, &resolver);
714 let environment = TraitEnvironment::lower(db, &resolver);
712 db.function_data(self.id) 715 db.function_data(self.id)
713 .params 716 .params
714 .iter() 717 .iter()
715 .skip(if self.self_param(db).is_some() { 1 } else { 0 }) 718 .skip(if self.self_param(db).is_some() { 1 } else { 0 })
716 .map(|_| Param { _ty: () }) 719 .map(|type_ref| {
720 let ty = Type {
721 krate: self.id.lookup(db.upcast()).container.module(db.upcast()).krate,
722 ty: InEnvironment {
723 value: Ty::from_hir_ext(&ctx, type_ref).0,
724 environment: environment.clone(),
725 },
726 };
727 ty
728 })
717 .collect() 729 .collect()
718 } 730 }
719 731
@@ -747,10 +759,6 @@ pub struct SelfParam {
747 func: FunctionId, 759 func: FunctionId,
748} 760}
749 761
750pub struct Param {
751 _ty: (),
752}
753
754impl SelfParam { 762impl SelfParam {
755 pub fn access(self, db: &dyn HirDatabase) -> Access { 763 pub fn access(self, db: &dyn HirDatabase) -> Access {
756 let func_data = db.function_data(self.func); 764 let func_data = db.function_data(self.func);
@@ -1100,6 +1108,12 @@ impl Local {
1100 ast.map_left(|it| it.cast().unwrap().to_node(&root)).map_right(|it| it.to_node(&root)) 1108 ast.map_left(|it| it.cast().unwrap().to_node(&root)).map_right(|it| it.to_node(&root))
1101 }) 1109 })
1102 } 1110 }
1111
1112 pub fn can_unify(self, other: Type, db: &dyn HirDatabase) -> bool {
1113 let def = DefWithBodyId::from(self.parent);
1114 let infer = db.infer(def);
1115 db.can_unify(def, infer[self.pat_id].clone(), other.ty.value)
1116 }
1103} 1117}
1104 1118
1105#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] 1119#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
@@ -1276,6 +1290,14 @@ impl Type {
1276 ) 1290 )
1277 } 1291 }
1278 1292
1293 pub fn remove_ref(&self) -> Option<Type> {
1294 if let Ty::Apply(ApplicationTy { ctor: TypeCtor::Ref(_), .. }) = self.ty.value {
1295 self.ty.value.substs().map(|substs| self.derived(substs[0].clone()))
1296 } else {
1297 None
1298 }
1299 }
1300
1279 pub fn is_unknown(&self) -> bool { 1301 pub fn is_unknown(&self) -> bool {
1280 matches!(self.ty.value, Ty::Unknown) 1302 matches!(self.ty.value, Ty::Unknown)
1281 } 1303 }