From 835173d065dbe1fdd7369ea49336c0b785be8cb8 Mon Sep 17 00:00:00 2001 From: Ekaterina Babshukova Date: Sat, 12 Oct 2019 20:30:53 +0300 Subject: replace trait by a bunch of functions --- crates/ra_hir/src/from_source.rs | 60 ++-------------------------------------- 1 file changed, 2 insertions(+), 58 deletions(-) (limited to 'crates/ra_hir/src') diff --git a/crates/ra_hir/src/from_source.rs b/crates/ra_hir/src/from_source.rs index e09414ca3..f80d8eb5f 100644 --- a/crates/ra_hir/src/from_source.rs +++ b/crates/ra_hir/src/from_source.rs @@ -11,9 +11,8 @@ use crate::{ db::{AstDatabase, DefDatabase, HirDatabase}, ids::{AstItemDef, LocationCtx}, name::AsName, - AssocItem, Const, Crate, Enum, EnumVariant, FieldSource, Function, HasSource, ImplBlock, - Module, ModuleDef, ModuleSource, Source, Static, Struct, StructField, Trait, TypeAlias, Union, - VariantDef, + Const, Crate, Enum, EnumVariant, FieldSource, Function, HasSource, ImplBlock, Module, + ModuleSource, Source, Static, Struct, StructField, Trait, TypeAlias, Union, VariantDef, }; pub trait FromSource: Sized { @@ -130,61 +129,6 @@ impl FromSource for StructField { } } -impl FromSource for AssocItem { - type Ast = ast::ImplItem; - fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source) -> Option { - macro_rules! def { - ($kind:ident, $ast:ident) => { - $kind::from_source(db, Source { file_id: src.file_id, ast: $ast }) - .and_then(|it| Some(AssocItem::from(it))) - }; - } - - match src.ast { - ast::ImplItem::FnDef(f) => def!(Function, f), - ast::ImplItem::ConstDef(c) => def!(Const, c), - ast::ImplItem::TypeAliasDef(a) => def!(TypeAlias, a), - } - } -} - -// not fully matched -impl FromSource for ModuleDef { - type Ast = ast::ModuleItem; - fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source) -> Option { - macro_rules! def { - ($kind:ident, $ast:ident) => { - $kind::from_source(db, Source { file_id: src.file_id, ast: $ast }) - .and_then(|it| Some(ModuleDef::from(it))) - }; - } - - match src.ast { - ast::ModuleItem::FnDef(f) => def!(Function, f), - ast::ModuleItem::ConstDef(c) => def!(Const, c), - ast::ModuleItem::TypeAliasDef(a) => def!(TypeAlias, a), - ast::ModuleItem::TraitDef(t) => def!(Trait, t), - ast::ModuleItem::StaticDef(s) => def!(Static, s), - ast::ModuleItem::StructDef(s) => { - let src = Source { file_id: src.file_id, ast: s }; - let s = Struct::from_source(db, src)?; - Some(ModuleDef::Adt(s.into())) - } - ast::ModuleItem::EnumDef(e) => { - let src = Source { file_id: src.file_id, ast: e }; - let e = Enum::from_source(db, src)?; - Some(ModuleDef::Adt(e.into())) - } - ast::ModuleItem::Module(ref m) if !m.has_semi() => { - let src = Source { file_id: src.file_id, ast: ModuleSource::Module(m.clone()) }; - let module = Module::from_definition(db, src)?; - Some(ModuleDef::Module(module)) - } - _ => None, - } - } -} - // FIXME: simplify it impl ModuleSource { pub fn from_position( -- cgit v1.2.3