aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_cli/src/analysis_stats.rs4
-rw-r--r--crates/ra_hir/src/code_model.rs33
-rw-r--r--crates/ra_hir/src/impl_block.rs28
-rw-r--r--crates/ra_hir/src/lib.rs2
-rw-r--r--crates/ra_hir/src/traits.rs23
-rw-r--r--crates/ra_hir/src/ty/infer.rs26
-rw-r--r--crates/ra_hir/src/ty/method_resolution.rs11
-rw-r--r--crates/ra_hir/src/ty/traits/chalk.rs6
-rw-r--r--crates/ra_ide_api/src/completion/complete_path.rs6
9 files changed, 46 insertions, 93 deletions
diff --git a/crates/ra_cli/src/analysis_stats.rs b/crates/ra_cli/src/analysis_stats.rs
index 8f4ce42da..6b1e44a2c 100644
--- a/crates/ra_cli/src/analysis_stats.rs
+++ b/crates/ra_cli/src/analysis_stats.rs
@@ -1,7 +1,7 @@
1use std::{collections::HashSet, fmt::Write, path::Path, time::Instant}; 1use std::{collections::HashSet, fmt::Write, path::Path, time::Instant};
2 2
3use ra_db::SourceDatabase; 3use ra_db::SourceDatabase;
4use ra_hir::{Crate, HasBodySource, HasSource, HirDisplay, ImplItem, ModuleDef, Ty, TypeWalk}; 4use ra_hir::{AssocItem, Crate, HasBodySource, HasSource, HirDisplay, ModuleDef, Ty, TypeWalk};
5use ra_syntax::AstNode; 5use ra_syntax::AstNode;
6 6
7use crate::{Result, Verbosity}; 7use crate::{Result, Verbosity};
@@ -47,7 +47,7 @@ pub fn run(
47 for impl_block in module.impl_blocks(db) { 47 for impl_block in module.impl_blocks(db) {
48 for item in impl_block.items(db) { 48 for item in impl_block.items(db) {
49 num_decls += 1; 49 num_decls += 1;
50 if let ImplItem::Method(f) = item { 50 if let AssocItem::Function(f) = item {
51 funcs.push(f); 51 funcs.push(f);
52 } 52 }
53 } 53 }
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 892208c1a..706d24c32 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -23,7 +23,7 @@ use crate::{
23 }, 23 },
24 nameres::{CrateModuleId, ImportId, ModuleScope, Namespace}, 24 nameres::{CrateModuleId, ImportId, ModuleScope, Namespace},
25 resolve::{Resolver, TypeNs}, 25 resolve::{Resolver, TypeNs},
26 traits::{TraitData, TraitItem}, 26 traits::TraitData,
27 ty::{ 27 ty::{
28 primitive::{FloatBitness, FloatTy, IntBitness, IntTy, Signedness}, 28 primitive::{FloatBitness, FloatTy, IntBitness, IntTy, Signedness},
29 InferenceResult, TraitRef, 29 InferenceResult, TraitRef,
@@ -269,7 +269,7 @@ impl Module {
269 269
270 for impl_block in self.impl_blocks(db) { 270 for impl_block in self.impl_blocks(db) {
271 for item in impl_block.items(db) { 271 for item in impl_block.items(db) {
272 if let crate::ImplItem::Method(f) = item { 272 if let AssocItem::Function(f) = item {
273 f.diagnostics(db, sink); 273 f.diagnostics(db, sink);
274 } 274 }
275 } 275 }
@@ -853,7 +853,7 @@ impl Trait {
853 self.trait_data(db).name().clone() 853 self.trait_data(db).name().clone()
854 } 854 }
855 855
856 pub fn items(self, db: &impl DefDatabase) -> Vec<TraitItem> { 856 pub fn items(self, db: &impl DefDatabase) -> Vec<AssocItem> {
857 self.trait_data(db).items().to_vec() 857 self.trait_data(db).items().to_vec()
858 } 858 }
859 859
@@ -906,7 +906,7 @@ impl Trait {
906 .items() 906 .items()
907 .iter() 907 .iter()
908 .filter_map(|item| match item { 908 .filter_map(|item| match item {
909 TraitItem::TypeAlias(t) => Some(*t), 909 AssocItem::TypeAlias(t) => Some(*t),
910 _ => None, 910 _ => None,
911 }) 911 })
912 .find(|t| &t.name(db) == name) 912 .find(|t| &t.name(db) == name)
@@ -1030,23 +1030,8 @@ pub enum AssocItem {
1030 Const(Const), 1030 Const(Const),
1031 TypeAlias(TypeAlias), 1031 TypeAlias(TypeAlias),
1032} 1032}
1033 1033// FIXME: not every function, ... is actually an assoc item. maybe we should make
1034impl From<TraitItem> for AssocItem { 1034// sure that you can only turn actual assoc items into AssocItems. This would
1035 fn from(t: TraitItem) -> Self { 1035// require not implementing From, and instead having some checked way of
1036 match t { 1036// casting them, and somehow making the constructors private, which would be annoying.
1037 TraitItem::Function(f) => AssocItem::Function(f), 1037impl_froms!(AssocItem: Function, Const, TypeAlias);
1038 TraitItem::Const(c) => AssocItem::Const(c),
1039 TraitItem::TypeAlias(t) => AssocItem::TypeAlias(t),
1040 }
1041 }
1042}
1043
1044impl From<crate::ImplItem> for AssocItem {
1045 fn from(i: crate::ImplItem) -> Self {
1046 match i {
1047 crate::ImplItem::Method(f) => AssocItem::Function(f),
1048 crate::ImplItem::Const(c) => AssocItem::Const(c),
1049 crate::ImplItem::TypeAlias(t) => AssocItem::TypeAlias(t),
1050 }
1051 }
1052}
diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs
index d26a024ed..c463d351c 100644
--- a/crates/ra_hir/src/impl_block.rs
+++ b/crates/ra_hir/src/impl_block.rs
@@ -15,7 +15,7 @@ use crate::{
15 resolve::Resolver, 15 resolve::Resolver,
16 ty::Ty, 16 ty::Ty,
17 type_ref::TypeRef, 17 type_ref::TypeRef,
18 Const, Function, HasSource, HirFileId, Source, TraitRef, TypeAlias, 18 AssocItem, Const, Function, HasSource, HirFileId, Source, TraitRef, TypeAlias,
19}; 19};
20 20
21#[derive(Debug, Default, PartialEq, Eq)] 21#[derive(Debug, Default, PartialEq, Eq)]
@@ -56,7 +56,7 @@ impl HasSource for ImplBlock {
56impl ImplBlock { 56impl ImplBlock {
57 pub(crate) fn containing( 57 pub(crate) fn containing(
58 module_impl_blocks: Arc<ModuleImplBlocks>, 58 module_impl_blocks: Arc<ModuleImplBlocks>,
59 item: ImplItem, 59 item: AssocItem,
60 ) -> Option<ImplBlock> { 60 ) -> Option<ImplBlock> {
61 let impl_id = *module_impl_blocks.impls_by_def.get(&item)?; 61 let impl_id = *module_impl_blocks.impls_by_def.get(&item)?;
62 Some(ImplBlock { module: module_impl_blocks.module, impl_id }) 62 Some(ImplBlock { module: module_impl_blocks.module, impl_id })
@@ -91,7 +91,7 @@ impl ImplBlock {
91 TraitRef::from_hir(db, &self.resolver(db), &self.target_trait(db)?, Some(target_ty)) 91 TraitRef::from_hir(db, &self.resolver(db), &self.target_trait(db)?, Some(target_ty))
92 } 92 }
93 93
94 pub fn items(&self, db: &impl DefDatabase) -> Vec<ImplItem> { 94 pub fn items(&self, db: &impl DefDatabase) -> Vec<AssocItem> {
95 db.impls_in_module(self.module).impls[self.impl_id].items().to_vec() 95 db.impls_in_module(self.module).impls[self.impl_id].items().to_vec()
96 } 96 }
97 97
@@ -113,7 +113,7 @@ impl ImplBlock {
113pub struct ImplData { 113pub struct ImplData {
114 target_trait: Option<TypeRef>, 114 target_trait: Option<TypeRef>,
115 target_type: TypeRef, 115 target_type: TypeRef,
116 items: Vec<ImplItem>, 116 items: Vec<AssocItem>,
117 negative: bool, 117 negative: bool,
118} 118}
119 119
@@ -151,27 +151,11 @@ impl ImplData {
151 &self.target_type 151 &self.target_type
152 } 152 }
153 153
154 pub fn items(&self) -> &[ImplItem] { 154 pub fn items(&self) -> &[AssocItem] {
155 &self.items 155 &self.items
156 } 156 }
157} 157}
158 158
159#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
160//FIXME: rename to ImplDef?
161pub enum ImplItem {
162 Method(Function),
163 Const(Const),
164 TypeAlias(TypeAlias),
165 // Existential
166}
167impl_froms!(ImplItem: Const, TypeAlias);
168
169impl From<Function> for ImplItem {
170 fn from(func: Function) -> ImplItem {
171 ImplItem::Method(func)
172 }
173}
174
175#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] 159#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
176pub struct ImplId(pub RawId); 160pub struct ImplId(pub RawId);
177impl_arena_id!(ImplId); 161impl_arena_id!(ImplId);
@@ -185,7 +169,7 @@ impl_arena_id!(ImplId);
185pub struct ModuleImplBlocks { 169pub struct ModuleImplBlocks {
186 pub(crate) module: Module, 170 pub(crate) module: Module,
187 pub(crate) impls: Arena<ImplId, ImplData>, 171 pub(crate) impls: Arena<ImplId, ImplData>,
188 impls_by_def: FxHashMap<ImplItem, ImplId>, 172 impls_by_def: FxHashMap<AssocItem, ImplId>,
189} 173}
190 174
191impl ModuleImplBlocks { 175impl ModuleImplBlocks {
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index db82a463c..e7a576aa0 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -69,7 +69,7 @@ pub use self::{
69 expr::ExprScopes, 69 expr::ExprScopes,
70 generics::{GenericParam, GenericParams, HasGenericParams}, 70 generics::{GenericParam, GenericParams, HasGenericParams},
71 ids::{HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroFile}, 71 ids::{HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroFile},
72 impl_block::{ImplBlock, ImplItem}, 72 impl_block::ImplBlock,
73 name::Name, 73 name::Name,
74 nameres::{ImportId, Namespace, PerNs}, 74 nameres::{ImportId, Namespace, PerNs},
75 path::{Path, PathKind}, 75 path::{Path, PathKind},
diff --git a/crates/ra_hir/src/traits.rs b/crates/ra_hir/src/traits.rs
index 4c2f7980d..e39511518 100644
--- a/crates/ra_hir/src/traits.rs
+++ b/crates/ra_hir/src/traits.rs
@@ -9,13 +9,13 @@ use crate::{
9 db::{AstDatabase, DefDatabase}, 9 db::{AstDatabase, DefDatabase},
10 ids::LocationCtx, 10 ids::LocationCtx,
11 name::AsName, 11 name::AsName,
12 Const, Function, HasSource, Module, Name, Trait, TypeAlias, 12 AssocItem, Const, Function, HasSource, Module, Name, Trait, TypeAlias,
13}; 13};
14 14
15#[derive(Debug, Clone, PartialEq, Eq)] 15#[derive(Debug, Clone, PartialEq, Eq)]
16pub struct TraitData { 16pub struct TraitData {
17 name: Option<Name>, 17 name: Option<Name>,
18 items: Vec<TraitItem>, 18 items: Vec<AssocItem>,
19 auto: bool, 19 auto: bool,
20} 20}
21 21
@@ -48,7 +48,7 @@ impl TraitData {
48 &self.name 48 &self.name
49 } 49 }
50 50
51 pub(crate) fn items(&self) -> &[TraitItem] { 51 pub(crate) fn items(&self) -> &[AssocItem] {
52 &self.items 52 &self.items
53 } 53 }
54 54
@@ -57,22 +57,9 @@ impl TraitData {
57 } 57 }
58} 58}
59 59
60#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
61pub enum TraitItem {
62 Function(Function),
63 Const(Const),
64 TypeAlias(TypeAlias),
65 // Existential
66}
67// FIXME: not every function, ... is actually a trait item. maybe we should make
68// sure that you can only turn actual trait items into TraitItems. This would
69// require not implementing From, and instead having some checked way of
70// casting them.
71impl_froms!(TraitItem: Function, Const, TypeAlias);
72
73#[derive(Debug, Clone, PartialEq, Eq)] 60#[derive(Debug, Clone, PartialEq, Eq)]
74pub struct TraitItemsIndex { 61pub struct TraitItemsIndex {
75 traits_by_def: FxHashMap<TraitItem, Trait>, 62 traits_by_def: FxHashMap<AssocItem, Trait>,
76} 63}
77 64
78impl TraitItemsIndex { 65impl TraitItemsIndex {
@@ -88,7 +75,7 @@ impl TraitItemsIndex {
88 index 75 index
89 } 76 }
90 77
91 pub(crate) fn get_parent_trait(&self, item: TraitItem) -> Option<Trait> { 78 pub(crate) fn get_parent_trait(&self, item: AssocItem) -> Option<Trait> {
92 self.traits_by_def.get(&item).cloned() 79 self.traits_by_def.get(&item).cloned()
93 } 80 }
94} 81}
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs
index 181be0fcc..70da7f311 100644
--- a/crates/ra_hir/src/ty/infer.rs
+++ b/crates/ra_hir/src/ty/infer.rs
@@ -576,34 +576,32 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
576 576
577 // Find impl 577 // Find impl
578 // FIXME: consider trait candidates 578 // FIXME: consider trait candidates
579 let def = ty.clone().iterate_impl_items(self.db, krate, |item| match item { 579 let item = ty.clone().iterate_impl_items(self.db, krate, |item| match item {
580 crate::ImplItem::Method(func) => { 580 AssocItem::Function(func) => {
581 if segment.name == func.name(self.db) { 581 if segment.name == func.name(self.db) {
582 Some(ValueNs::Function(func)) 582 Some(AssocItem::Function(func))
583 } else { 583 } else {
584 None 584 None
585 } 585 }
586 } 586 }
587 587
588 crate::ImplItem::Const(konst) => { 588 AssocItem::Const(konst) => {
589 if konst.name(self.db).map_or(false, |n| n == segment.name) { 589 if konst.name(self.db).map_or(false, |n| n == segment.name) {
590 Some(ValueNs::Const(konst)) 590 Some(AssocItem::Const(konst))
591 } else { 591 } else {
592 None 592 None
593 } 593 }
594 } 594 }
595 crate::ImplItem::TypeAlias(_) => None, 595 AssocItem::TypeAlias(_) => None,
596 })?; 596 })?;
597 let def = match item {
598 AssocItem::Function(f) => ValueNs::Function(f),
599 AssocItem::Const(c) => ValueNs::Const(c),
600 AssocItem::TypeAlias(_) => unreachable!(),
601 };
597 let substs = self.find_self_types(&def, ty); 602 let substs = self.find_self_types(&def, ty);
598 603
599 self.write_assoc_resolution( 604 self.write_assoc_resolution(id, item);
600 id,
601 match def {
602 ValueNs::Function(f) => AssocItem::Function(f),
603 ValueNs::Const(c) => AssocItem::Const(c),
604 _ => unreachable!(),
605 },
606 );
607 Some((def, substs)) 605 Some((def, substs))
608 } 606 }
609 607
diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs
index be63806d4..8b46b11a9 100644
--- a/crates/ra_hir/src/ty/method_resolution.rs
+++ b/crates/ra_hir/src/ty/method_resolution.rs
@@ -11,13 +11,12 @@ use super::{autoderef, lower, Canonical, InEnvironment, TraitEnvironment, TraitR
11use crate::{ 11use crate::{
12 db::HirDatabase, 12 db::HirDatabase,
13 generics::HasGenericParams, 13 generics::HasGenericParams,
14 impl_block::{ImplBlock, ImplId, ImplItem}, 14 impl_block::{ImplBlock, ImplId},
15 nameres::CrateModuleId, 15 nameres::CrateModuleId,
16 resolve::Resolver, 16 resolve::Resolver,
17 traits::TraitItem,
18 ty::primitive::{FloatBitness, UncertainFloatTy, UncertainIntTy}, 17 ty::primitive::{FloatBitness, UncertainFloatTy, UncertainIntTy},
19 ty::{Ty, TypeCtor}, 18 ty::{Ty, TypeCtor},
20 Crate, Function, Module, Name, Trait, 19 AssocItem, Crate, Function, Module, Name, Trait,
21}; 20};
22 21
23/// This is used as a key for indexing impls. 22/// This is used as a key for indexing impls.
@@ -232,7 +231,7 @@ fn iterate_trait_method_candidates<T>(
232 // iteration 231 // iteration
233 let mut known_implemented = inherently_implemented; 232 let mut known_implemented = inherently_implemented;
234 for item in data.items() { 233 for item in data.items() {
235 if let TraitItem::Function(m) = *item { 234 if let AssocItem::Function(m) = *item {
236 let data = m.data(db); 235 let data = m.data(db);
237 if name.map_or(true, |name| data.name() == name) && data.has_self_param() { 236 if name.map_or(true, |name| data.name() == name) && data.has_self_param() {
238 if !known_implemented { 237 if !known_implemented {
@@ -264,7 +263,7 @@ fn iterate_inherent_methods<T>(
264 263
265 for impl_block in impls.lookup_impl_blocks(&ty.value) { 264 for impl_block in impls.lookup_impl_blocks(&ty.value) {
266 for item in impl_block.items(db) { 265 for item in impl_block.items(db) {
267 if let ImplItem::Method(f) = item { 266 if let AssocItem::Function(f) = item {
268 let data = f.data(db); 267 let data = f.data(db);
269 if name.map_or(true, |name| data.name() == name) && data.has_self_param() { 268 if name.map_or(true, |name| data.name() == name) && data.has_self_param() {
270 if let Some(result) = callback(&ty.value, f) { 269 if let Some(result) = callback(&ty.value, f) {
@@ -304,7 +303,7 @@ impl Ty {
304 self, 303 self,
305 db: &impl HirDatabase, 304 db: &impl HirDatabase,
306 krate: Crate, 305 krate: Crate,
307 mut callback: impl FnMut(ImplItem) -> Option<T>, 306 mut callback: impl FnMut(AssocItem) -> Option<T>,
308 ) -> Option<T> { 307 ) -> Option<T> {
309 for krate in def_crates(db, krate, &self)? { 308 for krate in def_crates(db, krate, &self)? {
310 let impls = db.impls_in_crate(krate); 309 let impls = db.impls_in_crate(krate);
diff --git a/crates/ra_hir/src/ty/traits/chalk.rs b/crates/ra_hir/src/ty/traits/chalk.rs
index c748e9d84..693d9b28f 100644
--- a/crates/ra_hir/src/ty/traits/chalk.rs
+++ b/crates/ra_hir/src/ty/traits/chalk.rs
@@ -21,7 +21,7 @@ use crate::{
21 ApplicationTy, CallableDef, GenericPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, 21 ApplicationTy, CallableDef, GenericPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor,
22 TypeWalk, 22 TypeWalk,
23 }, 23 },
24 Crate, HasGenericParams, ImplBlock, ImplItem, Trait, TypeAlias, 24 AssocItem, Crate, HasGenericParams, ImplBlock, Trait, TypeAlias,
25}; 25};
26 26
27/// This represents a trait whose name we could not resolve. 27/// This represents a trait whose name we could not resolve.
@@ -496,7 +496,7 @@ pub(crate) fn trait_datum_query(
496 .items(db) 496 .items(db)
497 .into_iter() 497 .into_iter()
498 .filter_map(|trait_item| match trait_item { 498 .filter_map(|trait_item| match trait_item {
499 crate::traits::TraitItem::TypeAlias(type_alias) => Some(type_alias), 499 crate::AssocItem::TypeAlias(type_alias) => Some(type_alias),
500 _ => None, 500 _ => None,
501 }) 501 })
502 .map(|type_alias| type_alias.to_chalk(db)) 502 .map(|type_alias| type_alias.to_chalk(db))
@@ -616,7 +616,7 @@ pub(crate) fn impl_datum_query(
616 .items(db) 616 .items(db)
617 .into_iter() 617 .into_iter()
618 .filter_map(|item| match item { 618 .filter_map(|item| match item {
619 ImplItem::TypeAlias(t) => Some(t), 619 AssocItem::TypeAlias(t) => Some(t),
620 _ => None, 620 _ => None,
621 }) 621 })
622 .filter_map(|t| { 622 .filter_map(|t| {
diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs
index e1c8d6ab0..e9fec54d8 100644
--- a/crates/ra_ide_api/src/completion/complete_path.rs
+++ b/crates/ra_ide_api/src/completion/complete_path.rs
@@ -52,14 +52,14 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
52 if let Some(krate) = krate { 52 if let Some(krate) = krate {
53 ty.iterate_impl_items(ctx.db, krate, |item| { 53 ty.iterate_impl_items(ctx.db, krate, |item| {
54 match item { 54 match item {
55 hir::ImplItem::Method(func) => { 55 hir::AssocItem::Function(func) => {
56 let data = func.data(ctx.db); 56 let data = func.data(ctx.db);
57 if !data.has_self_param() { 57 if !data.has_self_param() {
58 acc.add_function(ctx, func); 58 acc.add_function(ctx, func);
59 } 59 }
60 } 60 }
61 hir::ImplItem::Const(ct) => acc.add_const(ctx, ct), 61 hir::AssocItem::Const(ct) => acc.add_const(ctx, ct),
62 hir::ImplItem::TypeAlias(ty) => acc.add_type_alias(ctx, ty), 62 hir::AssocItem::TypeAlias(ty) => acc.add_type_alias(ctx, ty),
63 } 63 }
64 None::<()> 64 None::<()>
65 }); 65 });