From 2d8a001465de8857090807f39fe667d98b05da30 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 20 Dec 2019 13:58:09 +0100 Subject: Reduce copy-paste some more --- crates/ra_hir_def/src/lib.rs | 14 +------- crates/ra_hir_def/src/src.rs | 82 +++++--------------------------------------- 2 files changed, 9 insertions(+), 87 deletions(-) diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index d11b573e5..8ed1599ff 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs @@ -366,19 +366,7 @@ impl HasModule for AssocContainerId { } } -impl HasModule for FunctionLoc { - fn module(&self, db: &impl db::DefDatabase) -> ModuleId { - self.container.module(db) - } -} - -impl HasModule for TypeAliasLoc { - fn module(&self, db: &impl db::DefDatabase) -> ModuleId { - self.container.module(db) - } -} - -impl HasModule for ConstLoc { +impl HasModule for AssocItemLoc { fn module(&self, db: &impl db::DefDatabase) -> ModuleId { self.container.module(db) } diff --git a/crates/ra_hir_def/src/src.rs b/crates/ra_hir_def/src/src.rs index 20200d1db..499375b80 100644 --- a/crates/ra_hir_def/src/src.rs +++ b/crates/ra_hir_def/src/src.rs @@ -2,94 +2,28 @@ use hir_expand::InFile; use ra_arena::map::ArenaMap; -use ra_syntax::ast; +use ra_syntax::AstNode; -use crate::{ - db::DefDatabase, ConstLoc, EnumLoc, FunctionLoc, ImplLoc, StaticLoc, StructLoc, TraitLoc, - TypeAliasLoc, UnionLoc, -}; +use crate::{db::DefDatabase, AssocItemLoc, ItemLoc}; pub trait HasSource { type Value; fn source(&self, db: &impl DefDatabase) -> InFile; } -impl HasSource for FunctionLoc { - type Value = ast::FnDef; +impl HasSource for AssocItemLoc { + type Value = N; - fn source(&self, db: &impl DefDatabase) -> InFile { + fn source(&self, db: &impl DefDatabase) -> InFile { let node = self.ast_id.to_node(db); InFile::new(self.ast_id.file_id, node) } } -impl HasSource for TypeAliasLoc { - type Value = ast::TypeAliasDef; +impl HasSource for ItemLoc { + type Value = N; - fn source(&self, db: &impl DefDatabase) -> InFile { - let node = self.ast_id.to_node(db); - InFile::new(self.ast_id.file_id, node) - } -} - -impl HasSource for ConstLoc { - type Value = ast::ConstDef; - - fn source(&self, db: &impl DefDatabase) -> InFile { - let node = self.ast_id.to_node(db); - InFile::new(self.ast_id.file_id, node) - } -} - -impl HasSource for StaticLoc { - type Value = ast::StaticDef; - - fn source(&self, db: &impl DefDatabase) -> InFile { - let node = self.ast_id.to_node(db); - InFile::new(self.ast_id.file_id, node) - } -} - -impl HasSource for ImplLoc { - type Value = ast::ImplBlock; - - fn source(&self, db: &impl DefDatabase) -> InFile { - let node = self.ast_id.to_node(db); - InFile::new(self.ast_id.file_id, node) - } -} - -impl HasSource for TraitLoc { - type Value = ast::TraitDef; - - fn source(&self, db: &impl DefDatabase) -> InFile { - let node = self.ast_id.to_node(db); - InFile::new(self.ast_id.file_id, node) - } -} - -impl HasSource for StructLoc { - type Value = ast::StructDef; - - fn source(&self, db: &impl DefDatabase) -> InFile { - let node = self.ast_id.to_node(db); - InFile::new(self.ast_id.file_id, node) - } -} - -impl HasSource for UnionLoc { - type Value = ast::UnionDef; - - fn source(&self, db: &impl DefDatabase) -> InFile { - let node = self.ast_id.to_node(db); - InFile::new(self.ast_id.file_id, node) - } -} - -impl HasSource for EnumLoc { - type Value = ast::EnumDef; - - fn source(&self, db: &impl DefDatabase) -> InFile { + fn source(&self, db: &impl DefDatabase) -> InFile { let node = self.ast_id.to_node(db); InFile::new(self.ast_id.file_id, node) } -- cgit v1.2.3