aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/code_model_api.rs25
-rw-r--r--crates/ra_hir/src/generics.rs19
-rw-r--r--crates/ra_hir/src/lib.rs12
-rw-r--r--crates/ra_hir/src/ty.rs39
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 73impl_froms!(ModuleDef: Module, Function, Struct, Enum);
74impl From<Module> for ModuleDef {
75 fn from(it: Module) -> ModuleDef {
76 ModuleDef::Module(it)
77 }
78}
79
80impl From<Function> for ModuleDef {
81 fn from(it: Function) -> ModuleDef {
82 ModuleDef::Function(it)
83 }
84}
85
86impl From<Struct> for ModuleDef {
87 fn from(it: Struct) -> ModuleDef {
88 ModuleDef::Struct(it)
89 }
90}
91
92impl From<Enum> for ModuleDef {
93 fn from(it: Enum) -> ModuleDef {
94 ModuleDef::Enum(it)
95 }
96}
97 74
98impl From<DefId> for ModuleDef { 75impl 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 32impl_froms!(GenericDef: Function, Struct, Enum);
33impl From<Function> for GenericDef {
34 fn from(func: Function) -> GenericDef {
35 GenericDef::Function(func)
36 }
37}
38
39impl From<Struct> for GenericDef {
40 fn from(s: Struct) -> GenericDef {
41 GenericDef::Struct(s)
42 }
43}
44
45impl From<Enum> for GenericDef {
46 fn from(e: Enum) -> GenericDef {
47 GenericDef::Enum(e)
48 }
49}
50 33
51impl From<DefId> for GenericDef { 34impl 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
8macro_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
8pub mod db; 20pub mod db;
9#[cfg(test)] 21#[cfg(test)]
10mod mock; 22mod 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 171impl_froms!(AdtDef: Struct, Enum);
172impl From<Struct> for AdtDef {
173 fn from(s: Struct) -> AdtDef {
174 AdtDef::Struct(s)
175 }
176}
177
178impl From<Enum> for AdtDef {
179 fn from(e: Enum) -> AdtDef {
180 AdtDef::Enum(e)
181 }
182}
183 172
184impl AdtDef { 173impl 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 693impl_froms!(TypableDef: Function, Struct, Enum);
705impl From<Function> for TypableDef {
706 fn from(func: Function) -> TypableDef {
707 TypableDef::Function(func)
708 }
709}
710
711impl From<Struct> for TypableDef {
712 fn from(s: Struct) -> TypableDef {
713 TypableDef::Struct(s)
714 }
715}
716
717impl From<Enum> for TypableDef {
718 fn from(e: Enum) -> TypableDef {
719 TypableDef::Enum(e)
720 }
721}
722 694
723impl From<DefId> for TypableDef { 695impl 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 738impl_froms!(VariantDef: Struct);
767impl From<Struct> for VariantDef {
768 fn from(struct_: Struct) -> VariantDef {
769 VariantDef::Struct(struct_)
770 }
771}
772 739
773impl From<DefId> for VariantDef { 740impl From<DefId> for VariantDef {
774 fn from(def_id: DefId) -> VariantDef { 741 fn from(def_id: DefId) -> VariantDef {