diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-09-17 22:16:28 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2019-09-17 22:16:28 +0100 |
commit | 54379ec6f8f82a470a275771e70825634d3d553b (patch) | |
tree | 498719aafe633f9eb9cb65ba65932076981e4632 /crates/ra_hir/src/code_model.rs | |
parent | d505ee968b2a99eed65dfe7be27940ad9b2647c1 (diff) | |
parent | c2f9558e1af8dbf73ff86eeffcb9ea6940947dd6 (diff) |
Merge #1862
1862: Assoc item resolution refactoring (again) r=flodiebold a=flodiebold
This is #1849, with the associated type selection code removed for now. Handling cycles there will need some more thought.
Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/code_model.rs')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 84e15385c..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 | } |
@@ -749,6 +749,10 @@ impl Const { | |||
749 | db.const_data(self) | 749 | db.const_data(self) |
750 | } | 750 | } |
751 | 751 | ||
752 | pub fn name(&self, db: &impl HirDatabase) -> Option<Name> { | ||
753 | self.data(db).name().cloned() | ||
754 | } | ||
755 | |||
752 | pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> { | 756 | pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> { |
753 | db.infer(self.into()) | 757 | db.infer(self.into()) |
754 | } | 758 | } |
@@ -849,7 +853,7 @@ impl Trait { | |||
849 | self.trait_data(db).name().clone() | 853 | self.trait_data(db).name().clone() |
850 | } | 854 | } |
851 | 855 | ||
852 | pub fn items(self, db: &impl DefDatabase) -> Vec<TraitItem> { | 856 | pub fn items(self, db: &impl DefDatabase) -> Vec<AssocItem> { |
853 | self.trait_data(db).items().to_vec() | 857 | self.trait_data(db).items().to_vec() |
854 | } | 858 | } |
855 | 859 | ||
@@ -902,7 +906,7 @@ impl Trait { | |||
902 | .items() | 906 | .items() |
903 | .iter() | 907 | .iter() |
904 | .filter_map(|item| match item { | 908 | .filter_map(|item| match item { |
905 | TraitItem::TypeAlias(t) => Some(*t), | 909 | AssocItem::TypeAlias(t) => Some(*t), |
906 | _ => None, | 910 | _ => None, |
907 | }) | 911 | }) |
908 | .find(|t| &t.name(db) == name) | 912 | .find(|t| &t.name(db) == name) |
@@ -1019,3 +1023,15 @@ impl Container { | |||
1019 | } | 1023 | } |
1020 | } | 1024 | } |
1021 | } | 1025 | } |
1026 | |||
1027 | #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] | ||
1028 | pub enum AssocItem { | ||
1029 | Function(Function), | ||
1030 | Const(Const), | ||
1031 | TypeAlias(TypeAlias), | ||
1032 | } | ||
1033 | // FIXME: not every function, ... is actually an assoc item. maybe we should make | ||
1034 | // sure that you can only turn actual assoc items into AssocItems. This would | ||
1035 | // require not implementing From, and instead having some checked way of | ||
1036 | // casting them, and somehow making the constructors private, which would be annoying. | ||
1037 | impl_froms!(AssocItem: Function, Const, TypeAlias); | ||