]> git.lizzy.rs Git - rust.git/commitdiff
Reduce copy-paste some more
authorAleksey Kladov <aleksey.kladov@gmail.com>
Fri, 20 Dec 2019 12:58:09 +0000 (13:58 +0100)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Fri, 20 Dec 2019 12:58:09 +0000 (13:58 +0100)
crates/ra_hir_def/src/lib.rs
crates/ra_hir_def/src/src.rs

index d11b573e5f5861252f41d50eb00480b6fc872b0c..8ed1599ffb1ea3624b9b776cdad58b0f4b2ba9f7 100644 (file)
@@ -366,19 +366,7 @@ fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
     }
 }
 
-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<N: AstNode> HasModule for AssocItemLoc<N> {
     fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
         self.container.module(db)
     }
index 20200d1db49d0b392ba92833bf32011b8d92684a..499375b803fc2af85f6b82d5421b4df3cb43937e 100644 (file)
@@ -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<Self::Value>;
 }
 
-impl HasSource for FunctionLoc {
-    type Value = ast::FnDef;
+impl<N: AstNode> HasSource for AssocItemLoc<N> {
+    type Value = N;
 
-    fn source(&self, db: &impl DefDatabase) -> InFile<ast::FnDef> {
+    fn source(&self, db: &impl DefDatabase) -> InFile<N> {
         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<N: AstNode> HasSource for ItemLoc<N> {
+    type Value = N;
 
-    fn source(&self, db: &impl DefDatabase) -> InFile<ast::TypeAliasDef> {
-        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<ast::ConstDef> {
-        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<ast::StaticDef> {
-        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<ast::ImplBlock> {
-        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<ast::TraitDef> {
-        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<ast::StructDef> {
-        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<ast::UnionDef> {
-        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<ast::EnumDef> {
+    fn source(&self, db: &impl DefDatabase) -> InFile<N> {
         let node = self.ast_id.to_node(db);
         InFile::new(self.ast_id.file_id, node)
     }