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.rs40
1 files changed, 33 insertions, 7 deletions
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs
index 7a9747fc7..a2a166e0a 100644
--- a/crates/hir/src/code_model.rs
+++ b/crates/hir/src/code_model.rs
@@ -709,11 +709,23 @@ impl Function {
709 } 709 }
710 710
711 pub fn params(self, db: &dyn HirDatabase) -> Vec<Param> { 711 pub fn params(self, db: &dyn HirDatabase) -> Vec<Param> {
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 Param { ty }
728 })
717 .collect() 729 .collect()
718 } 730 }
719 731
@@ -742,15 +754,21 @@ impl From<Mutability> for Access {
742 } 754 }
743} 755}
744 756
757pub struct Param {
758 ty: Type,
759}
760
761impl Param {
762 pub fn ty(&self) -> &Type {
763 &self.ty
764 }
765}
766
745#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 767#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
746pub struct SelfParam { 768pub struct SelfParam {
747 func: FunctionId, 769 func: FunctionId,
748} 770}
749 771
750pub struct Param {
751 _ty: (),
752}
753
754impl SelfParam { 772impl SelfParam {
755 pub fn access(self, db: &dyn HirDatabase) -> Access { 773 pub fn access(self, db: &dyn HirDatabase) -> Access {
756 let func_data = db.function_data(self.func); 774 let func_data = db.function_data(self.func);
@@ -908,12 +926,12 @@ impl MacroDef {
908 926
909 /// Indicate it is a proc-macro 927 /// Indicate it is a proc-macro
910 pub fn is_proc_macro(&self) -> bool { 928 pub fn is_proc_macro(&self) -> bool {
911 matches!(self.id.kind, MacroDefKind::CustomDerive(_)) 929 matches!(self.id.kind, MacroDefKind::ProcMacro(_))
912 } 930 }
913 931
914 /// Indicate it is a derive macro 932 /// Indicate it is a derive macro
915 pub fn is_derive_macro(&self) -> bool { 933 pub fn is_derive_macro(&self) -> bool {
916 matches!(self.id.kind, MacroDefKind::CustomDerive(_) | MacroDefKind::BuiltInDerive(_)) 934 matches!(self.id.kind, MacroDefKind::ProcMacro(_) | MacroDefKind::BuiltInDerive(_))
917 } 935 }
918} 936}
919 937
@@ -1276,6 +1294,14 @@ impl Type {
1276 ) 1294 )
1277 } 1295 }
1278 1296
1297 pub fn remove_ref(&self) -> Option<Type> {
1298 if let Ty::Apply(ApplicationTy { ctor: TypeCtor::Ref(_), .. }) = self.ty.value {
1299 self.ty.value.substs().map(|substs| self.derived(substs[0].clone()))
1300 } else {
1301 None
1302 }
1303 }
1304
1279 pub fn is_unknown(&self) -> bool { 1305 pub fn is_unknown(&self) -> bool {
1280 matches!(self.ty.value, Ty::Unknown) 1306 matches!(self.ty.value, Ty::Unknown)
1281 } 1307 }