From 111126ed3c4f6358e0c833f80226e5192778f749 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 29 Dec 2018 21:32:07 +0100 Subject: Type the self parameter --- crates/ra_hir/src/ty.rs | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) (limited to 'crates/ra_hir/src/ty.rs') 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 ty, + ast::SelfParamFlavor::Ref => Ty::Ref(Arc::new(ty), Mutability::Shared), + ast::SelfParamFlavor::MutRef => Ty::Ref(Arc::new(ty), Mutability::Mut), + }; + ctx.insert_type_vars(ty) + } + } else { + log::debug!( + "No impl block found, but self param for function {:?}", + def_id + ); + ctx.new_type_var() + }; + if let Some(self_kw) = self_param.self_kw() { + ctx.type_of + .insert(LocalSyntaxPtr::new(self_kw.syntax()), self_type); + } + } for param in param_list.params() { let pat = if let Some(pat) = param.pat() { pat } else { continue; }; - if let Some(type_ref) = param.type_ref() { + let ty = if let Some(type_ref) = param.type_ref() { let ty = Ty::from_ast(db, &ctx.module, type_ref)?; - let ty = ctx.insert_type_vars(ty); - ctx.type_of.insert(LocalSyntaxPtr::new(pat.syntax()), ty); + ctx.insert_type_vars(ty) } else { - // TODO self param - let type_var = ctx.new_type_var(); - ctx.type_of - .insert(LocalSyntaxPtr::new(pat.syntax()), type_var); + // missing type annotation + ctx.new_type_var() }; + ctx.type_of.insert(LocalSyntaxPtr::new(pat.syntax()), ty); } } -- cgit v1.2.3