aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/ty.rs')
-rw-r--r--crates/ra_hir/src/ty.rs38
1 files changed, 31 insertions, 7 deletions
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs
index 719b3f7cd..c762ec606 100644
--- a/crates/ra_hir/src/ty.rs
+++ b/crates/ra_hir/src/ty.rs
@@ -918,22 +918,46 @@ pub fn infer(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<InferenceRe
918 let node = syntax.borrowed(); 918 let node = syntax.borrowed();
919 919
920 if let Some(param_list) = node.param_list() { 920 if let Some(param_list) = node.param_list() {
921 if let Some(self_param) = param_list.self_param() {
922 let self_type = if let Some(impl_block) = function.impl_block(db)? {
923 if let Some(type_ref) = self_param.type_ref() {
924 let ty = Ty::from_ast(db, &ctx.module, type_ref)?;
925 ctx.insert_type_vars(ty)
926 } else {
927 let ty = Ty::from_hir(db, &ctx.module, impl_block.target())?;
928 let ty = match self_param.flavor() {
929 ast::SelfParamFlavor::Owned => ty,
930 ast::SelfParamFlavor::Ref => Ty::Ref(Arc::new(ty), Mutability::Shared),
931 ast::SelfParamFlavor::MutRef => Ty::Ref(Arc::new(ty), Mutability::Mut),
932 };
933 ctx.insert_type_vars(ty)
934 }
935 } else {
936 log::debug!(
937 "No impl block found, but self param for function {:?}",
938 def_id
939 );
940 ctx.new_type_var()
941 };
942 if let Some(self_kw) = self_param.self_kw() {
943 ctx.type_of
944 .insert(LocalSyntaxPtr::new(self_kw.syntax()), self_type);
945 }
946 }
921 for param in param_list.params() { 947 for param in param_list.params() {
922 let pat = if let Some(pat) = param.pat() { 948 let pat = if let Some(pat) = param.pat() {
923 pat 949 pat
924 } else { 950 } else {
925 continue; 951 continue;
926 }; 952 };
927 if let Some(type_ref) = param.type_ref() { 953 let ty = if let Some(type_ref) = param.type_ref() {
928 let ty = Ty::from_ast(db, &ctx.module, type_ref)?; 954 let ty = Ty::from_ast(db, &ctx.module, type_ref)?;
929 let ty = ctx.insert_type_vars(ty); 955 ctx.insert_type_vars(ty)
930 ctx.type_of.insert(LocalSyntaxPtr::new(pat.syntax()), ty);
931 } else { 956 } else {
932 // TODO self param 957 // missing type annotation
933 let type_var = ctx.new_type_var(); 958 ctx.new_type_var()
934 ctx.type_of
935 .insert(LocalSyntaxPtr::new(pat.syntax()), type_var);
936 }; 959 };
960 ctx.type_of.insert(LocalSyntaxPtr::new(pat.syntax()), ty);
937 } 961 }
938 } 962 }
939 963