diff options
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/code_model_api.rs | 25 | ||||
-rw-r--r-- | crates/ra_hir/src/generics.rs | 19 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 12 | ||||
-rw-r--r-- | crates/ra_hir/src/ty.rs | 39 |
4 files changed, 17 insertions, 78 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index a094268ca..4b79358e4 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs | |||
@@ -70,30 +70,7 @@ pub enum ModuleDef { | |||
70 | Enum(Enum), | 70 | Enum(Enum), |
71 | Def(DefId), | 71 | Def(DefId), |
72 | } | 72 | } |
73 | //FIXME: change to from | 73 | impl_froms!(ModuleDef: Module, Function, Struct, Enum); |
74 | impl From<Module> for ModuleDef { | ||
75 | fn from(it: Module) -> ModuleDef { | ||
76 | ModuleDef::Module(it) | ||
77 | } | ||
78 | } | ||
79 | |||
80 | impl From<Function> for ModuleDef { | ||
81 | fn from(it: Function) -> ModuleDef { | ||
82 | ModuleDef::Function(it) | ||
83 | } | ||
84 | } | ||
85 | |||
86 | impl From<Struct> for ModuleDef { | ||
87 | fn from(it: Struct) -> ModuleDef { | ||
88 | ModuleDef::Struct(it) | ||
89 | } | ||
90 | } | ||
91 | |||
92 | impl From<Enum> for ModuleDef { | ||
93 | fn from(it: Enum) -> ModuleDef { | ||
94 | ModuleDef::Enum(it) | ||
95 | } | ||
96 | } | ||
97 | 74 | ||
98 | impl From<DefId> for ModuleDef { | 75 | impl From<DefId> for ModuleDef { |
99 | fn from(it: DefId) -> ModuleDef { | 76 | fn from(it: DefId) -> ModuleDef { |
diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs index df23871c7..a8cacbb4a 100644 --- a/crates/ra_hir/src/generics.rs +++ b/crates/ra_hir/src/generics.rs | |||
@@ -29,24 +29,7 @@ pub enum GenericDef { | |||
29 | Enum(Enum), | 29 | Enum(Enum), |
30 | Def(DefId), | 30 | Def(DefId), |
31 | } | 31 | } |
32 | 32 | impl_froms!(GenericDef: Function, Struct, Enum); | |
33 | impl From<Function> for GenericDef { | ||
34 | fn from(func: Function) -> GenericDef { | ||
35 | GenericDef::Function(func) | ||
36 | } | ||
37 | } | ||
38 | |||
39 | impl From<Struct> for GenericDef { | ||
40 | fn from(s: Struct) -> GenericDef { | ||
41 | GenericDef::Struct(s) | ||
42 | } | ||
43 | } | ||
44 | |||
45 | impl From<Enum> for GenericDef { | ||
46 | fn from(e: Enum) -> GenericDef { | ||
47 | GenericDef::Enum(e) | ||
48 | } | ||
49 | } | ||
50 | 33 | ||
51 | impl From<DefId> for GenericDef { | 34 | impl From<DefId> for GenericDef { |
52 | fn from(def_id: DefId) -> GenericDef { | 35 | fn from(def_id: DefId) -> GenericDef { |
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 5d6371892..33438509c 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs | |||
@@ -5,6 +5,18 @@ | |||
5 | //! to a particular crate instance. That is, it has cfg flags and features | 5 | //! to a particular crate instance. That is, it has cfg flags and features |
6 | //! applied. So, the relation between syntax and HIR is many-to-one. | 6 | //! applied. So, the relation between syntax and HIR is many-to-one. |
7 | 7 | ||
8 | macro_rules! impl_froms { | ||
9 | ($e:ident: $($v:ident), *) => { | ||
10 | $( | ||
11 | impl From<$v> for $e { | ||
12 | fn from(it: $v) -> $e { | ||
13 | $e::$v(it) | ||
14 | } | ||
15 | } | ||
16 | )* | ||
17 | } | ||
18 | } | ||
19 | |||
8 | pub mod db; | 20 | pub mod db; |
9 | #[cfg(test)] | 21 | #[cfg(test)] |
10 | mod mock; | 22 | mod mock; |
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index b81899661..fcf8a1dbb 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs | |||
@@ -168,18 +168,7 @@ pub enum AdtDef { | |||
168 | Struct(Struct), | 168 | Struct(Struct), |
169 | Enum(Enum), | 169 | Enum(Enum), |
170 | } | 170 | } |
171 | 171 | impl_froms!(AdtDef: Struct, Enum); | |
172 | impl From<Struct> for AdtDef { | ||
173 | fn from(s: Struct) -> AdtDef { | ||
174 | AdtDef::Struct(s) | ||
175 | } | ||
176 | } | ||
177 | |||
178 | impl From<Enum> for AdtDef { | ||
179 | fn from(e: Enum) -> AdtDef { | ||
180 | AdtDef::Enum(e) | ||
181 | } | ||
182 | } | ||
183 | 172 | ||
184 | impl AdtDef { | 173 | impl AdtDef { |
185 | fn krate(self, db: &impl HirDatabase) -> Option<Crate> { | 174 | fn krate(self, db: &impl HirDatabase) -> Option<Crate> { |
@@ -701,24 +690,7 @@ pub enum TypableDef { | |||
701 | Enum(Enum), | 690 | Enum(Enum), |
702 | Def(DefId), | 691 | Def(DefId), |
703 | } | 692 | } |
704 | 693 | impl_froms!(TypableDef: Function, Struct, Enum); | |
705 | impl From<Function> for TypableDef { | ||
706 | fn from(func: Function) -> TypableDef { | ||
707 | TypableDef::Function(func) | ||
708 | } | ||
709 | } | ||
710 | |||
711 | impl From<Struct> for TypableDef { | ||
712 | fn from(s: Struct) -> TypableDef { | ||
713 | TypableDef::Struct(s) | ||
714 | } | ||
715 | } | ||
716 | |||
717 | impl From<Enum> for TypableDef { | ||
718 | fn from(e: Enum) -> TypableDef { | ||
719 | TypableDef::Enum(e) | ||
720 | } | ||
721 | } | ||
722 | 694 | ||
723 | impl From<DefId> for TypableDef { | 695 | impl From<DefId> for TypableDef { |
724 | fn from(func: DefId) -> TypableDef { | 696 | fn from(func: DefId) -> TypableDef { |
@@ -763,12 +735,7 @@ pub enum VariantDef { | |||
763 | Struct(Struct), | 735 | Struct(Struct), |
764 | Def(DefId), // EnumVariant | 736 | Def(DefId), // EnumVariant |
765 | } | 737 | } |
766 | 738 | impl_froms!(VariantDef: Struct); | |
767 | impl From<Struct> for VariantDef { | ||
768 | fn from(struct_: Struct) -> VariantDef { | ||
769 | VariantDef::Struct(struct_) | ||
770 | } | ||
771 | } | ||
772 | 739 | ||
773 | impl From<DefId> for VariantDef { | 740 | impl From<DefId> for VariantDef { |
774 | fn from(def_id: DefId) -> VariantDef { | 741 | fn from(def_id: DefId) -> VariantDef { |