From 693ac892f2db5db1ce7cf86db7bf6207b3515c42 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 13 Jul 2020 16:16:53 +0200 Subject: Don't copy-paste `impl_froms` into every crate --- crates/ra_hir/src/code_model.rs | 23 +++++++++++++---------- crates/ra_hir/src/lib.rs | 19 ------------------- crates/ra_hir/src/semantics/source_to_def.rs | 5 +++-- 3 files changed, 16 insertions(+), 31 deletions(-) (limited to 'crates/ra_hir/src') 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::{ AstNode, }; use rustc_hash::FxHashSet; +use stdx::impl_from; use crate::{ db::{DefDatabase, HirDatabase}, @@ -142,8 +143,8 @@ pub enum ModuleDef { TypeAlias(TypeAlias), BuiltinType(BuiltinType), } -impl_froms!( - ModuleDef: Module, +impl_from!( + Module, Function, Adt(Struct, Enum, Union), EnumVariant, @@ -152,6 +153,7 @@ impl_froms!( Trait, TypeAlias, BuiltinType + for ModuleDef ); impl ModuleDef { @@ -541,7 +543,7 @@ pub enum Adt { Union(Union), Enum(Enum), } -impl_froms!(Adt: Struct, Union, Enum); +impl_from!(Struct, Union, Enum for Adt); impl Adt { pub fn has_non_default_type_params(self, db: &dyn HirDatabase) -> bool { @@ -584,7 +586,7 @@ pub enum VariantDef { Union(Union), EnumVariant(EnumVariant), } -impl_froms!(VariantDef: Struct, Union, EnumVariant); +impl_from!(Struct, Union, EnumVariant for VariantDef); impl VariantDef { pub fn fields(self, db: &dyn HirDatabase) -> Vec { @@ -627,8 +629,7 @@ pub enum DefWithBody { Static(Static), Const(Const), } - -impl_froms!(DefWithBody: Function, Const, Static); +impl_from!(Function, Const, Static for DefWithBody); impl DefWithBody { pub fn module(self, db: &dyn HirDatabase) -> Module { @@ -930,14 +931,15 @@ pub enum GenericDef { // consts can have type parameters from their parents (i.e. associated consts of traits) Const(Const), } -impl_froms!( - GenericDef: Function, +impl_from!( + Function, Adt(Struct, Enum, Union), Trait, TypeAlias, ImplDef, EnumVariant, Const + for GenericDef ); impl GenericDef { @@ -1578,8 +1580,8 @@ pub enum AttrDef { MacroDef(MacroDef), } -impl_froms!( - AttrDef: Module, +impl_from!( + Module, Field, Adt(Struct, Enum, Union), EnumVariant, @@ -1589,6 +1591,7 @@ impl_froms!( Trait, TypeAlias, MacroDef + for AttrDef ); pub 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 @@ #![recursion_limit = "512"] -macro_rules! impl_froms { - ($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)) - } - } - )*)? - )* - } -} - mod semantics; pub mod db; mod 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::{ match_ast, AstNode, SyntaxNode, }; use rustc_hash::FxHashMap; +use stdx::impl_from; use crate::{db::HirDatabase, InFile, MacroDefId}; @@ -255,8 +256,7 @@ pub(crate) enum ChildContainer { /// here the children generic parameters, and not, eg enum variants. GenericDefId(GenericDefId), } -impl_froms! { - ChildContainer: +impl_from! { DefWithBodyId, ModuleId, TraitId, @@ -265,6 +265,7 @@ impl_froms! { VariantId, TypeAliasId, GenericDefId + for ChildContainer } impl ChildContainer { -- cgit v1.2.3