aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-11-22 14:10:51 +0000
committerAleksey Kladov <[email protected]>2019-11-22 14:18:04 +0000
commit78f3b0627cf4a5d34aaf63c7b5a2e1b744a11b14 (patch)
tree0c0e07fefce4b4175e8162bcd586aaca17512bb8
parenta132cc715ed05cab83fd058156eb152f0be96982 (diff)
Move FunctionData to hir_def
-rw-r--r--crates/ra_hir/src/code_model.rs87
-rw-r--r--crates/ra_hir/src/db.rs13
-rw-r--r--crates/ra_hir/src/lib.rs6
-rw-r--r--crates/ra_hir/src/ty/infer.rs13
-rw-r--r--crates/ra_hir/src/ty/lower.rs6
-rw-r--r--crates/ra_hir/src/ty/method_resolution.rs6
-rw-r--r--crates/ra_hir_def/src/db.rs7
-rw-r--r--crates/ra_hir_def/src/function.rs61
-rw-r--r--crates/ra_hir_def/src/lib.rs1
-rw-r--r--crates/ra_ide_api/src/call_info.rs4
-rw-r--r--crates/ra_ide_api/src/change.rs2
-rw-r--r--crates/ra_ide_api/src/completion/complete_dot.rs3
-rw-r--r--crates/ra_ide_api/src/completion/complete_path.rs6
-rw-r--r--crates/ra_ide_api/src/completion/presentation.rs15
14 files changed, 114 insertions, 116 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 72c9b466f..f426f8c9f 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -13,7 +13,7 @@ use hir_def::{
13 nameres::per_ns::PerNs, 13 nameres::per_ns::PerNs,
14 resolver::{HasResolver, TypeNs}, 14 resolver::{HasResolver, TypeNs},
15 traits::TraitData, 15 traits::TraitData,
16 type_ref::{Mutability, TypeRef}, 16 type_ref::TypeRef,
17 ContainerId, CrateModuleId, HasModule, ImplId, LocalEnumVariantId, LocalStructFieldId, Lookup, 17 ContainerId, CrateModuleId, HasModule, ImplId, LocalEnumVariantId, LocalStructFieldId, Lookup,
18 ModuleId, UnionId, 18 ModuleId, UnionId,
19}; 19};
@@ -561,77 +561,6 @@ pub struct Function {
561 pub(crate) id: FunctionId, 561 pub(crate) id: FunctionId,
562} 562}
563 563
564#[derive(Debug, Clone, PartialEq, Eq)]
565pub struct FnData {
566 pub(crate) name: Name,
567 pub(crate) params: Vec<TypeRef>,
568 pub(crate) ret_type: TypeRef,
569 /// True if the first param is `self`. This is relevant to decide whether this
570 /// can be called as a method.
571 pub(crate) has_self_param: bool,
572}
573
574impl FnData {
575 pub(crate) fn fn_data_query(
576 db: &(impl DefDatabase + AstDatabase),
577 func: Function,
578 ) -> Arc<FnData> {
579 let src = func.source(db);
580 let name = src.value.name().map(|n| n.as_name()).unwrap_or_else(Name::missing);
581 let mut params = Vec::new();
582 let mut has_self_param = false;
583 if let Some(param_list) = src.value.param_list() {
584 if let Some(self_param) = param_list.self_param() {
585 let self_type = if let Some(type_ref) = self_param.ascribed_type() {
586 TypeRef::from_ast(type_ref)
587 } else {
588 let self_type = TypeRef::Path(name::SELF_TYPE.into());
589 match self_param.kind() {
590 ast::SelfParamKind::Owned => self_type,
591 ast::SelfParamKind::Ref => {
592 TypeRef::Reference(Box::new(self_type), Mutability::Shared)
593 }
594 ast::SelfParamKind::MutRef => {
595 TypeRef::Reference(Box::new(self_type), Mutability::Mut)
596 }
597 }
598 };
599 params.push(self_type);
600 has_self_param = true;
601 }
602 for param in param_list.params() {
603 let type_ref = TypeRef::from_ast_opt(param.ascribed_type());
604 params.push(type_ref);
605 }
606 }
607 let ret_type = if let Some(type_ref) = src.value.ret_type().and_then(|rt| rt.type_ref()) {
608 TypeRef::from_ast(type_ref)
609 } else {
610 TypeRef::unit()
611 };
612
613 let sig = FnData { name, params, ret_type, has_self_param };
614 Arc::new(sig)
615 }
616 pub fn name(&self) -> &Name {
617 &self.name
618 }
619
620 pub fn params(&self) -> &[TypeRef] {
621 &self.params
622 }
623
624 pub fn ret_type(&self) -> &TypeRef {
625 &self.ret_type
626 }
627
628 /// True if the first arg is `self`. This is relevant to decide whether this
629 /// can be called as a method.
630 pub fn has_self_param(&self) -> bool {
631 self.has_self_param
632 }
633}
634
635impl Function { 564impl Function {
636 pub fn module(self, db: &impl DefDatabase) -> Module { 565 pub fn module(self, db: &impl DefDatabase) -> Module {
637 self.id.lookup(db).module(db).into() 566 self.id.lookup(db).module(db).into()
@@ -642,7 +571,15 @@ impl Function {
642 } 571 }
643 572
644 pub fn name(self, db: &impl HirDatabase) -> Name { 573 pub fn name(self, db: &impl HirDatabase) -> Name {
645 self.data(db).name.clone() 574 db.function_data(self.id).name.clone()
575 }
576
577 pub fn has_self_param(self, db: &impl HirDatabase) -> bool {
578 db.function_data(self.id).has_self_param
579 }
580
581 pub fn params(self, db: &impl HirDatabase) -> Vec<TypeRef> {
582 db.function_data(self.id).params.clone()
646 } 583 }
647 584
648 pub(crate) fn body_source_map(self, db: &impl HirDatabase) -> Arc<BodySourceMap> { 585 pub(crate) fn body_source_map(self, db: &impl HirDatabase) -> Arc<BodySourceMap> {
@@ -657,10 +594,6 @@ impl Function {
657 db.type_for_def(self.into(), Namespace::Values) 594 db.type_for_def(self.into(), Namespace::Values)
658 } 595 }
659 596
660 pub fn data(self, db: &impl HirDatabase) -> Arc<FnData> {
661 db.fn_data(self)
662 }
663
664 pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> { 597 pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> {
665 db.infer(self.into()) 598 db.infer(self.into())
666 } 599 }
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs
index 1cfcb2fd2..8b9af0565 100644
--- a/crates/ra_hir/src/db.rs
+++ b/crates/ra_hir/src/db.rs
@@ -16,15 +16,15 @@ use crate::{
16 CallableDef, FnSig, GenericPredicate, InferenceResult, Namespace, Substs, Ty, TypableDef, 16 CallableDef, FnSig, GenericPredicate, InferenceResult, Namespace, Substs, Ty, TypableDef,
17 TypeCtor, 17 TypeCtor,
18 }, 18 },
19 Const, ConstData, Crate, DefWithBody, FnData, Function, GenericDef, ImplBlock, Module, Static, 19 Const, ConstData, Crate, DefWithBody, GenericDef, ImplBlock, Module, Static, StructField,
20 StructField, Trait, 20 Trait,
21}; 21};
22 22
23pub use hir_def::db::{ 23pub use hir_def::db::{
24 BodyQuery, BodyWithSourceMapQuery, CrateDefMapQuery, DefDatabase2, DefDatabase2Storage, 24 BodyQuery, BodyWithSourceMapQuery, CrateDefMapQuery, DefDatabase2, DefDatabase2Storage,
25 EnumDataQuery, ExprScopesQuery, GenericParamsQuery, ImplDataQuery, InternDatabase, 25 EnumDataQuery, ExprScopesQuery, FunctionDataQuery, GenericParamsQuery, ImplDataQuery,
26 InternDatabaseStorage, RawItemsQuery, RawItemsWithSourceMapQuery, StructDataQuery, 26 InternDatabase, InternDatabaseStorage, RawItemsQuery, RawItemsWithSourceMapQuery,
27 TraitDataQuery, TypeAliasDataQuery, 27 StructDataQuery, TraitDataQuery, TypeAliasDataQuery,
28}; 28};
29pub use hir_expand::db::{ 29pub use hir_expand::db::{
30 AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery, 30 AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery,
@@ -35,9 +35,6 @@ pub use hir_expand::db::{
35#[salsa::query_group(DefDatabaseStorage)] 35#[salsa::query_group(DefDatabaseStorage)]
36#[salsa::requires(AstDatabase)] 36#[salsa::requires(AstDatabase)]
37pub trait DefDatabase: HirDebugDatabase + DefDatabase2 { 37pub trait DefDatabase: HirDebugDatabase + DefDatabase2 {
38 #[salsa::invoke(FnData::fn_data_query)]
39 fn fn_data(&self, func: Function) -> Arc<FnData>;
40
41 #[salsa::invoke(ConstData::const_data_query)] 38 #[salsa::invoke(ConstData::const_data_query)]
42 fn const_data(&self, konst: Const) -> Arc<ConstData>; 39 fn const_data(&self, konst: Const) -> Arc<ConstData>;
43 40
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index 8535629ca..d29cc9258 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -55,9 +55,9 @@ pub use crate::{
55 docs::{DocDef, Docs, Documentation}, 55 docs::{DocDef, Docs, Documentation},
56 src::{HasBodySource, HasSource}, 56 src::{HasBodySource, HasSource},
57 Adt, AssocItem, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum, 57 Adt, AssocItem, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum,
58 EnumVariant, FieldSource, FnData, Function, GenericDef, GenericParam, HasBody, ImplBlock, 58 EnumVariant, FieldSource, Function, GenericDef, GenericParam, HasBody, ImplBlock, Local,
59 Local, MacroDef, Module, ModuleDef, ModuleSource, ScopeDef, Static, Struct, StructField, 59 MacroDef, Module, ModuleDef, ModuleSource, ScopeDef, Static, Struct, StructField, Trait,
60 Trait, TypeAlias, Union, VariantDef, 60 TypeAlias, Union, VariantDef,
61 }, 61 },
62 expr::ExprScopes, 62 expr::ExprScopes,
63 from_source::FromSource, 63 from_source::FromSource,
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs
index 69b13baef..41a51283d 100644
--- a/crates/ra_hir/src/ty/infer.rs
+++ b/crates/ra_hir/src/ty/infer.rs
@@ -22,6 +22,7 @@ use ena::unify::{InPlaceUnificationTable, NoError, UnifyKey, UnifyValue};
22use rustc_hash::FxHashMap; 22use rustc_hash::FxHashMap;
23 23
24use hir_def::{ 24use hir_def::{
25 function::FunctionData,
25 path::known, 26 path::known,
26 resolver::{HasResolver, Resolver, TypeNs}, 27 resolver::{HasResolver, Resolver, TypeNs},
27 type_ref::{Mutability, TypeRef}, 28 type_ref::{Mutability, TypeRef},
@@ -43,8 +44,8 @@ use crate::{
43 db::HirDatabase, 44 db::HirDatabase,
44 expr::{BindingAnnotation, Body, ExprId, PatId}, 45 expr::{BindingAnnotation, Body, ExprId, PatId},
45 ty::infer::diagnostics::InferenceDiagnostic, 46 ty::infer::diagnostics::InferenceDiagnostic,
46 Adt, AssocItem, ConstData, DefWithBody, FloatTy, FnData, Function, HasBody, IntTy, Path, 47 Adt, AssocItem, ConstData, DefWithBody, FloatTy, Function, HasBody, IntTy, Path, StructField,
47 StructField, Trait, VariantDef, 48 Trait, VariantDef,
48}; 49};
49 50
50macro_rules! ty_app { 51macro_rules! ty_app {
@@ -70,7 +71,7 @@ pub fn infer_query(db: &impl HirDatabase, def: DefWithBody) -> Arc<InferenceResu
70 71
71 match def { 72 match def {
72 DefWithBody::Const(ref c) => ctx.collect_const(&c.data(db)), 73 DefWithBody::Const(ref c) => ctx.collect_const(&c.data(db)),
73 DefWithBody::Function(ref f) => ctx.collect_fn(&f.data(db)), 74 DefWithBody::Function(ref f) => ctx.collect_fn(&db.function_data(f.id)),
74 DefWithBody::Static(ref s) => ctx.collect_const(&s.data(db)), 75 DefWithBody::Static(ref s) => ctx.collect_const(&s.data(db)),
75 } 76 }
76 77
@@ -562,14 +563,14 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
562 self.return_ty = self.make_ty(data.type_ref()); 563 self.return_ty = self.make_ty(data.type_ref());
563 } 564 }
564 565
565 fn collect_fn(&mut self, data: &FnData) { 566 fn collect_fn(&mut self, data: &FunctionData) {
566 let body = Arc::clone(&self.body); // avoid borrow checker problem 567 let body = Arc::clone(&self.body); // avoid borrow checker problem
567 for (type_ref, pat) in data.params().iter().zip(body.params()) { 568 for (type_ref, pat) in data.params.iter().zip(body.params()) {
568 let ty = self.make_ty(type_ref); 569 let ty = self.make_ty(type_ref);
569 570
570 self.infer_pat(*pat, &ty, BindingMode::default()); 571 self.infer_pat(*pat, &ty, BindingMode::default());
571 } 572 }
572 self.return_ty = self.make_ty(data.ret_type()); 573 self.return_ty = self.make_ty(&data.ret_type);
573 } 574 }
574 575
575 fn infer_body(&mut self) { 576 fn infer_body(&mut self) {
diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs
index 75c552569..42daa9cb9 100644
--- a/crates/ra_hir/src/ty/lower.rs
+++ b/crates/ra_hir/src/ty/lower.rs
@@ -622,10 +622,10 @@ pub(crate) fn generic_defaults_query(db: &impl HirDatabase, def: GenericDef) ->
622} 622}
623 623
624fn fn_sig_for_fn(db: &impl HirDatabase, def: Function) -> FnSig { 624fn fn_sig_for_fn(db: &impl HirDatabase, def: Function) -> FnSig {
625 let data = def.data(db); 625 let data = db.function_data(def.id);
626 let resolver = def.id.resolver(db); 626 let resolver = def.id.resolver(db);
627 let params = data.params().iter().map(|tr| Ty::from_hir(db, &resolver, tr)).collect::<Vec<_>>(); 627 let params = data.params.iter().map(|tr| Ty::from_hir(db, &resolver, tr)).collect::<Vec<_>>();
628 let ret = Ty::from_hir(db, &resolver, data.ret_type()); 628 let ret = Ty::from_hir(db, &resolver, &data.ret_type);
629 FnSig::from_params_and_return(params, ret) 629 FnSig::from_params_and_return(params, ret)
630} 630}
631 631
diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs
index 64adb814d..f84aae26e 100644
--- a/crates/ra_hir/src/ty/method_resolution.rs
+++ b/crates/ra_hir/src/ty/method_resolution.rs
@@ -291,9 +291,9 @@ fn is_valid_candidate(
291) -> bool { 291) -> bool {
292 match item { 292 match item {
293 AssocItem::Function(m) => { 293 AssocItem::Function(m) => {
294 let data = m.data(db); 294 let data = db.function_data(m.id);
295 name.map_or(true, |name| data.name() == name) 295 name.map_or(true, |name| data.name == *name)
296 && (data.has_self_param() || mode == LookupMode::Path) 296 && (data.has_self_param || mode == LookupMode::Path)
297 } 297 }
298 AssocItem::Const(c) => { 298 AssocItem::Const(c) => {
299 name.map_or(true, |name| Some(name) == c.name(db).as_ref()) 299 name.map_or(true, |name| Some(name) == c.name(db).as_ref())
diff --git a/crates/ra_hir_def/src/db.rs b/crates/ra_hir_def/src/db.rs
index 5bbdaa4b2..02e649cc7 100644
--- a/crates/ra_hir_def/src/db.rs
+++ b/crates/ra_hir_def/src/db.rs
@@ -8,6 +8,7 @@ use ra_syntax::ast;
8use crate::{ 8use crate::{
9 adt::{EnumData, StructData}, 9 adt::{EnumData, StructData},
10 body::{scope::ExprScopes, Body, BodySourceMap}, 10 body::{scope::ExprScopes, Body, BodySourceMap},
11 function::FunctionData,
11 generics::GenericParams, 12 generics::GenericParams,
12 impls::ImplData, 13 impls::ImplData,
13 nameres::{ 14 nameres::{
@@ -16,7 +17,8 @@ use crate::{
16 }, 17 },
17 traits::TraitData, 18 traits::TraitData,
18 type_alias::TypeAliasData, 19 type_alias::TypeAliasData,
19 DefWithBodyId, EnumId, GenericDefId, ImplId, ItemLoc, StructOrUnionId, TraitId, TypeAliasId, 20 DefWithBodyId, EnumId, FunctionId, GenericDefId, ImplId, ItemLoc, StructOrUnionId, TraitId,
21 TypeAliasId,
20}; 22};
21 23
22#[salsa::query_group(InternDatabaseStorage)] 24#[salsa::query_group(InternDatabaseStorage)]
@@ -68,6 +70,9 @@ pub trait DefDatabase2: InternDatabase + AstDatabase {
68 #[salsa::invoke(TypeAliasData::type_alias_data_query)] 70 #[salsa::invoke(TypeAliasData::type_alias_data_query)]
69 fn type_alias_data(&self, e: TypeAliasId) -> Arc<TypeAliasData>; 71 fn type_alias_data(&self, e: TypeAliasId) -> Arc<TypeAliasData>;
70 72
73 #[salsa::invoke(FunctionData::fn_data_query)]
74 fn function_data(&self, func: FunctionId) -> Arc<FunctionData>;
75
71 #[salsa::invoke(Body::body_with_source_map_query)] 76 #[salsa::invoke(Body::body_with_source_map_query)]
72 fn body_with_source_map(&self, def: DefWithBodyId) -> (Arc<Body>, Arc<BodySourceMap>); 77 fn body_with_source_map(&self, def: DefWithBodyId) -> (Arc<Body>, Arc<BodySourceMap>);
73 78
diff --git a/crates/ra_hir_def/src/function.rs b/crates/ra_hir_def/src/function.rs
new file mode 100644
index 000000000..33265275e
--- /dev/null
+++ b/crates/ra_hir_def/src/function.rs
@@ -0,0 +1,61 @@
1use std::sync::Arc;
2
3use hir_expand::name::{self, AsName, Name};
4use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner};
5
6use crate::{
7 db::DefDatabase2,
8 type_ref::{Mutability, TypeRef},
9 FunctionId, HasSource, Lookup,
10};
11
12#[derive(Debug, Clone, PartialEq, Eq)]
13pub struct FunctionData {
14 pub name: Name,
15 pub params: Vec<TypeRef>,
16 pub ret_type: TypeRef,
17 /// True if the first param is `self`. This is relevant to decide whether this
18 /// can be called as a method.
19 pub has_self_param: bool,
20}
21
22impl FunctionData {
23 pub(crate) fn fn_data_query(db: &impl DefDatabase2, func: FunctionId) -> Arc<FunctionData> {
24 let src = func.lookup(db).source(db);
25 let name = src.value.name().map(|n| n.as_name()).unwrap_or_else(Name::missing);
26 let mut params = Vec::new();
27 let mut has_self_param = false;
28 if let Some(param_list) = src.value.param_list() {
29 if let Some(self_param) = param_list.self_param() {
30 let self_type = if let Some(type_ref) = self_param.ascribed_type() {
31 TypeRef::from_ast(type_ref)
32 } else {
33 let self_type = TypeRef::Path(name::SELF_TYPE.into());
34 match self_param.kind() {
35 ast::SelfParamKind::Owned => self_type,
36 ast::SelfParamKind::Ref => {
37 TypeRef::Reference(Box::new(self_type), Mutability::Shared)
38 }
39 ast::SelfParamKind::MutRef => {
40 TypeRef::Reference(Box::new(self_type), Mutability::Mut)
41 }
42 }
43 };
44 params.push(self_type);
45 has_self_param = true;
46 }
47 for param in param_list.params() {
48 let type_ref = TypeRef::from_ast_opt(param.ascribed_type());
49 params.push(type_ref);
50 }
51 }
52 let ret_type = if let Some(type_ref) = src.value.ret_type().and_then(|rt| rt.type_ref()) {
53 TypeRef::from_ast(type_ref)
54 } else {
55 TypeRef::unit()
56 };
57
58 let sig = FunctionData { name, params, ret_type, has_self_param };
59 Arc::new(sig)
60 }
61}
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs
index 268144462..14ccad043 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -21,6 +21,7 @@ pub mod generics;
21pub mod traits; 21pub mod traits;
22pub mod resolver; 22pub mod resolver;
23pub mod type_alias; 23pub mod type_alias;
24pub mod function;
24 25
25#[cfg(test)] 26#[cfg(test)]
26mod test_db; 27mod test_db;
diff --git a/crates/ra_ide_api/src/call_info.rs b/crates/ra_ide_api/src/call_info.rs
index 41ee81511..7c367230e 100644
--- a/crates/ra_ide_api/src/call_info.rs
+++ b/crates/ra_ide_api/src/call_info.rs
@@ -30,7 +30,7 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<Cal
30 let (callable_def, _subst) = analyzer.type_of(db, &expr.expr()?)?.as_callable()?; 30 let (callable_def, _subst) = analyzer.type_of(db, &expr.expr()?)?.as_callable()?;
31 match callable_def { 31 match callable_def {
32 hir::CallableDef::Function(it) => { 32 hir::CallableDef::Function(it) => {
33 (CallInfo::with_fn(db, it), it.data(db).has_self_param()) 33 (CallInfo::with_fn(db, it), it.has_self_param(db))
34 } 34 }
35 hir::CallableDef::Struct(it) => (CallInfo::with_struct(db, it)?, false), 35 hir::CallableDef::Struct(it) => (CallInfo::with_struct(db, it)?, false),
36 hir::CallableDef::EnumVariant(it) => (CallInfo::with_enum_variant(db, it)?, false), 36 hir::CallableDef::EnumVariant(it) => (CallInfo::with_enum_variant(db, it)?, false),
@@ -38,7 +38,7 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<Cal
38 } 38 }
39 FnCallNode::MethodCallExpr(expr) => { 39 FnCallNode::MethodCallExpr(expr) => {
40 let function = analyzer.resolve_method_call(&expr)?; 40 let function = analyzer.resolve_method_call(&expr)?;
41 (CallInfo::with_fn(db, function), function.data(db).has_self_param()) 41 (CallInfo::with_fn(db, function), function.has_self_param(db))
42 } 42 }
43 FnCallNode::MacroCallExpr(expr) => { 43 FnCallNode::MacroCallExpr(expr) => {
44 let macro_def = analyzer.resolve_macro_call(db, &expr)?; 44 let macro_def = analyzer.resolve_macro_call(db, &expr)?;
diff --git a/crates/ra_ide_api/src/change.rs b/crates/ra_ide_api/src/change.rs
index 3c607d5b5..8a05b287f 100644
--- a/crates/ra_ide_api/src/change.rs
+++ b/crates/ra_ide_api/src/change.rs
@@ -313,7 +313,7 @@ impl RootDatabase {
313 hir::db::RawItemsQuery 313 hir::db::RawItemsQuery
314 hir::db::CrateDefMapQuery 314 hir::db::CrateDefMapQuery
315 hir::db::GenericParamsQuery 315 hir::db::GenericParamsQuery
316 hir::db::FnDataQuery 316 hir::db::FunctionDataQuery
317 hir::db::TypeAliasDataQuery 317 hir::db::TypeAliasDataQuery
318 hir::db::ConstDataQuery 318 hir::db::ConstDataQuery
319 hir::db::StaticDataQuery 319 hir::db::StaticDataQuery
diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs
index 4e2c497e1..5a3f9b5f6 100644
--- a/crates/ra_ide_api/src/completion/complete_dot.rs
+++ b/crates/ra_ide_api/src/completion/complete_dot.rs
@@ -59,8 +59,7 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty)
59fn complete_methods(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) { 59fn complete_methods(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) {
60 let mut seen_methods = FxHashSet::default(); 60 let mut seen_methods = FxHashSet::default();
61 ctx.analyzer.iterate_method_candidates(ctx.db, receiver, None, |_ty, func| { 61 ctx.analyzer.iterate_method_candidates(ctx.db, receiver, None, |_ty, func| {
62 let data = func.data(ctx.db); 62 if func.has_self_param(ctx.db) && seen_methods.insert(func.name(ctx.db)) {
63 if data.has_self_param() && seen_methods.insert(data.name().clone()) {
64 acc.add_function(ctx, func); 63 acc.add_function(ctx, func);
65 } 64 }
66 None::<()> 65 None::<()>
diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs
index 5d974cf6d..802c7701a 100644
--- a/crates/ra_ide_api/src/completion/complete_path.rs
+++ b/crates/ra_ide_api/src/completion/complete_path.rs
@@ -53,8 +53,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
53 ctx.analyzer.iterate_path_candidates(ctx.db, ty.clone(), None, |_ty, item| { 53 ctx.analyzer.iterate_path_candidates(ctx.db, ty.clone(), None, |_ty, item| {
54 match item { 54 match item {
55 hir::AssocItem::Function(func) => { 55 hir::AssocItem::Function(func) => {
56 let data = func.data(ctx.db); 56 if !func.has_self_param(ctx.db) {
57 if !data.has_self_param() {
58 acc.add_function(ctx, func); 57 acc.add_function(ctx, func);
59 } 58 }
60 } 59 }
@@ -80,8 +79,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
80 for item in t.items(ctx.db) { 79 for item in t.items(ctx.db) {
81 match item { 80 match item {
82 hir::AssocItem::Function(func) => { 81 hir::AssocItem::Function(func) => {
83 let data = func.data(ctx.db); 82 if !func.has_self_param(ctx.db) {
84 if !data.has_self_param() {
85 acc.add_function(ctx, func); 83 acc.add_function(ctx, func);
86 } 84 }
87 } 85 }
diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs
index bd464d193..50fdb0043 100644
--- a/crates/ra_ide_api/src/completion/presentation.rs
+++ b/crates/ra_ide_api/src/completion/presentation.rs
@@ -199,14 +199,17 @@ impl Completions {
199 name: Option<String>, 199 name: Option<String>,
200 func: hir::Function, 200 func: hir::Function,
201 ) { 201 ) {
202 let data = func.data(ctx.db); 202 let func_name = func.name(ctx.db);
203 let name = name.unwrap_or_else(|| data.name().to_string()); 203 let has_self_param = func.has_self_param(ctx.db);
204 let params = func.params(ctx.db);
205
206 let name = name.unwrap_or_else(|| func_name.to_string());
204 let ast_node = func.source(ctx.db).value; 207 let ast_node = func.source(ctx.db).value;
205 let detail = function_label(&ast_node); 208 let detail = function_label(&ast_node);
206 209
207 let mut builder = 210 let mut builder =
208 CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.clone()) 211 CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.clone())
209 .kind(if data.has_self_param() { 212 .kind(if has_self_param {
210 CompletionItemKind::Method 213 CompletionItemKind::Method
211 } else { 214 } else {
212 CompletionItemKind::Function 215 CompletionItemKind::Function
@@ -222,10 +225,10 @@ impl Completions {
222 { 225 {
223 tested_by!(inserts_parens_for_function_calls); 226 tested_by!(inserts_parens_for_function_calls);
224 let (snippet, label) = 227 let (snippet, label) =
225 if data.params().is_empty() || data.has_self_param() && data.params().len() == 1 { 228 if params.is_empty() || has_self_param && params.len() == 1 {
226 (format!("{}()$0", data.name()), format!("{}()", name)) 229 (format!("{}()$0", func_name), format!("{}()", name))
227 } else { 230 } else {
228 (format!("{}($0)", data.name()), format!("{}(…)", name)) 231 (format!("{}($0)", func_name), format!("{}(…)", name))
229 }; 232 };
230 builder = builder.lookup_by(name).label(label).insert_snippet(snippet); 233 builder = builder.lookup_by(name).label(label).insert_snippet(snippet);
231 } 234 }