aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/code_model.rs23
-rw-r--r--crates/ra_hir/src/lib.rs19
-rw-r--r--crates/ra_hir/src/semantics/source_to_def.rs5
3 files changed, 16 insertions, 31 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 04fd335fe..9222009fe 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -38,6 +38,7 @@ use ra_syntax::{
38 AstNode, 38 AstNode,
39}; 39};
40use rustc_hash::FxHashSet; 40use rustc_hash::FxHashSet;
41use stdx::impl_from;
41 42
42use crate::{ 43use crate::{
43 db::{DefDatabase, HirDatabase}, 44 db::{DefDatabase, HirDatabase},
@@ -142,8 +143,8 @@ pub enum ModuleDef {
142 TypeAlias(TypeAlias), 143 TypeAlias(TypeAlias),
143 BuiltinType(BuiltinType), 144 BuiltinType(BuiltinType),
144} 145}
145impl_froms!( 146impl_from!(
146 ModuleDef: Module, 147 Module,
147 Function, 148 Function,
148 Adt(Struct, Enum, Union), 149 Adt(Struct, Enum, Union),
149 EnumVariant, 150 EnumVariant,
@@ -152,6 +153,7 @@ impl_froms!(
152 Trait, 153 Trait,
153 TypeAlias, 154 TypeAlias,
154 BuiltinType 155 BuiltinType
156 for ModuleDef
155); 157);
156 158
157impl ModuleDef { 159impl ModuleDef {
@@ -541,7 +543,7 @@ pub enum Adt {
541 Union(Union), 543 Union(Union),
542 Enum(Enum), 544 Enum(Enum),
543} 545}
544impl_froms!(Adt: Struct, Union, Enum); 546impl_from!(Struct, Union, Enum for Adt);
545 547
546impl Adt { 548impl Adt {
547 pub fn has_non_default_type_params(self, db: &dyn HirDatabase) -> bool { 549 pub fn has_non_default_type_params(self, db: &dyn HirDatabase) -> bool {
@@ -584,7 +586,7 @@ pub enum VariantDef {
584 Union(Union), 586 Union(Union),
585 EnumVariant(EnumVariant), 587 EnumVariant(EnumVariant),
586} 588}
587impl_froms!(VariantDef: Struct, Union, EnumVariant); 589impl_from!(Struct, Union, EnumVariant for VariantDef);
588 590
589impl VariantDef { 591impl VariantDef {
590 pub fn fields(self, db: &dyn HirDatabase) -> Vec<Field> { 592 pub fn fields(self, db: &dyn HirDatabase) -> Vec<Field> {
@@ -627,8 +629,7 @@ pub enum DefWithBody {
627 Static(Static), 629 Static(Static),
628 Const(Const), 630 Const(Const),
629} 631}
630 632impl_from!(Function, Const, Static for DefWithBody);
631impl_froms!(DefWithBody: Function, Const, Static);
632 633
633impl DefWithBody { 634impl DefWithBody {
634 pub fn module(self, db: &dyn HirDatabase) -> Module { 635 pub fn module(self, db: &dyn HirDatabase) -> Module {
@@ -930,14 +931,15 @@ pub enum GenericDef {
930 // consts can have type parameters from their parents (i.e. associated consts of traits) 931 // consts can have type parameters from their parents (i.e. associated consts of traits)
931 Const(Const), 932 Const(Const),
932} 933}
933impl_froms!( 934impl_from!(
934 GenericDef: Function, 935 Function,
935 Adt(Struct, Enum, Union), 936 Adt(Struct, Enum, Union),
936 Trait, 937 Trait,
937 TypeAlias, 938 TypeAlias,
938 ImplDef, 939 ImplDef,
939 EnumVariant, 940 EnumVariant,
940 Const 941 Const
942 for GenericDef
941); 943);
942 944
943impl GenericDef { 945impl GenericDef {
@@ -1578,8 +1580,8 @@ pub enum AttrDef {
1578 MacroDef(MacroDef), 1580 MacroDef(MacroDef),
1579} 1581}
1580 1582
1581impl_froms!( 1583impl_from!(
1582 AttrDef: Module, 1584 Module,
1583 Field, 1585 Field,
1584 Adt(Struct, Enum, Union), 1586 Adt(Struct, Enum, Union),
1585 EnumVariant, 1587 EnumVariant,
@@ -1589,6 +1591,7 @@ impl_froms!(
1589 Trait, 1591 Trait,
1590 TypeAlias, 1592 TypeAlias,
1591 MacroDef 1593 MacroDef
1594 for AttrDef
1592); 1595);
1593 1596
1594pub trait HasAttrs { 1597pub trait HasAttrs {
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index 3364a822f..7d9b174b4 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -19,25 +19,6 @@
19 19
20#![recursion_limit = "512"] 20#![recursion_limit = "512"]
21 21
22macro_rules! impl_froms {
23 ($e:ident: $($v:ident $(($($sv:ident),*))?),*$(,)?) => {
24 $(
25 impl From<$v> for $e {
26 fn from(it: $v) -> $e {
27 $e::$v(it)
28 }
29 }
30 $($(
31 impl From<$sv> for $e {
32 fn from(it: $sv) -> $e {
33 $e::$v($v::$sv(it))
34 }
35 }
36 )*)?
37 )*
38 }
39}
40
41mod semantics; 22mod semantics;
42pub mod db; 23pub mod db;
43mod source_analyzer; 24mod source_analyzer;
diff --git a/crates/ra_hir/src/semantics/source_to_def.rs b/crates/ra_hir/src/semantics/source_to_def.rs
index 0e1d92fb3..42e5a1bdb 100644
--- a/crates/ra_hir/src/semantics/source_to_def.rs
+++ b/crates/ra_hir/src/semantics/source_to_def.rs
@@ -16,6 +16,7 @@ use ra_syntax::{
16 match_ast, AstNode, SyntaxNode, 16 match_ast, AstNode, SyntaxNode,
17}; 17};
18use rustc_hash::FxHashMap; 18use rustc_hash::FxHashMap;
19use stdx::impl_from;
19 20
20use crate::{db::HirDatabase, InFile, MacroDefId}; 21use crate::{db::HirDatabase, InFile, MacroDefId};
21 22
@@ -255,8 +256,7 @@ pub(crate) enum ChildContainer {
255 /// here the children generic parameters, and not, eg enum variants. 256 /// here the children generic parameters, and not, eg enum variants.
256 GenericDefId(GenericDefId), 257 GenericDefId(GenericDefId),
257} 258}
258impl_froms! { 259impl_from! {
259 ChildContainer:
260 DefWithBodyId, 260 DefWithBodyId,
261 ModuleId, 261 ModuleId,
262 TraitId, 262 TraitId,
@@ -265,6 +265,7 @@ impl_froms! {
265 VariantId, 265 VariantId,
266 TypeAliasId, 266 TypeAliasId,
267 GenericDefId 267 GenericDefId
268 for ChildContainer
268} 269}
269 270
270impl ChildContainer { 271impl ChildContainer {