diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 026753c9f6..a10e795ce3 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -139,7 +139,7 @@ pub enum ModuleDef { impl_froms!( ModuleDef: Module, Function, - AdtDef, + AdtDef(Struct, Enum, Union), EnumVariant, Const, Static, @@ -148,24 +148,6 @@ impl_froms!( BuiltinType ); -impl From for ModuleDef { - fn from(it: Struct) -> ModuleDef { - ModuleDef::AdtDef(AdtDef::Struct(it)) - } -} - -impl From for ModuleDef { - fn from(it: Enum) -> ModuleDef { - ModuleDef::AdtDef(AdtDef::Enum(it)) - } -} - -impl From for ModuleDef { - fn from(it: Union) -> ModuleDef { - ModuleDef::AdtDef(AdtDef::Union(it)) - } -} - pub enum ModuleSource { SourceFile(ast::SourceFile), Module(ast::Module), diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs index 0e89941f34..74435c20a9 100644 --- a/crates/ra_hir/src/generics.rs +++ b/crates/ra_hir/src/generics.rs @@ -55,25 +55,14 @@ pub enum GenericDef { // can, and this makes some code easier to write EnumVariant(EnumVariant), } -impl_froms!(GenericDef: Function, AdtDef, Trait, TypeAlias, ImplBlock, EnumVariant); - -impl From for GenericDef { - fn from(it: Struct) -> GenericDef { - GenericDef::AdtDef(AdtDef::Struct(it)) - } -} - -impl From for GenericDef { - fn from(it: Enum) -> GenericDef { - GenericDef::AdtDef(AdtDef::Enum(it)) - } -} - -impl From for GenericDef { - fn from(it: Union) -> GenericDef { - GenericDef::AdtDef(AdtDef::Union(it)) - } -} +impl_froms!( + GenericDef: Function, + AdtDef(Struct, Enum, Union), + Trait, + TypeAlias, + ImplBlock, + EnumVariant +); impl GenericParams { pub(crate) fn generic_params_query( diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 2fe1a658ee..639e97c3d1 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -8,13 +8,20 @@ //! applied. So, the relation between syntax and HIR is many-to-one. macro_rules! impl_froms { - ($e:ident: $($v:ident),*) => { + ($e:ident: $($v:ident $(($($sv:ident),*))?),*) => { $( impl From<$v> for $e { fn from(it: $v) -> $e { $e::$v(it) } } + $($( + impl From<$sv> for $e { + fn from(it: $sv) -> $e { + $e::$v($v::$sv(it)) + } + } + )*)? )* } } diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs index 587dc12ee8..105c893f07 100644 --- a/crates/ra_hir/src/ty/lower.rs +++ b/crates/ra_hir/src/ty/lower.rs @@ -611,25 +611,15 @@ pub enum TypableDef { Static(Static), BuiltinType(BuiltinType), } -impl_froms!(TypableDef: Function, AdtDef, EnumVariant, TypeAlias, Const, Static, BuiltinType); - -impl From for TypableDef { - fn from(it: Struct) -> TypableDef { - TypableDef::AdtDef(AdtDef::Struct(it)) - } -} - -impl From for TypableDef { - fn from(it: Enum) -> TypableDef { - TypableDef::AdtDef(AdtDef::Enum(it)) - } -} - -impl From for TypableDef { - fn from(it: Union) -> TypableDef { - TypableDef::AdtDef(AdtDef::Union(it)) - } -} +impl_froms!( + TypableDef: Function, + AdtDef(Struct, Enum, Union), + EnumVariant, + TypeAlias, + Const, + Static, + BuiltinType +); impl From for Option { fn from(def: ModuleDef) -> Option {