aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-12-20 12:58:55 +0000
committerGitHub <[email protected]>2019-12-20 12:58:55 +0000
commita2ce8ab27526f544aca4acd019394d57aa735812 (patch)
treecf981bd010fef6c104f9829265efa65ab725d087 /crates
parentfbc2cf2b6999b9c694e03993e62531cf9ef3d9b0 (diff)
parent2d8a001465de8857090807f39fe667d98b05da30 (diff)
Merge #2610
2610: Reduce copy-paste some more r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir_def/src/lib.rs14
-rw-r--r--crates/ra_hir_def/src/src.rs82
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 {
366 } 366 }
367} 367}
368 368
369impl HasModule for FunctionLoc { 369impl<N: AstNode> HasModule for AssocItemLoc<N> {
370 fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
371 self.container.module(db)
372 }
373}
374
375impl HasModule for TypeAliasLoc {
376 fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
377 self.container.module(db)
378 }
379}
380
381impl HasModule for ConstLoc {
382 fn module(&self, db: &impl db::DefDatabase) -> ModuleId { 370 fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
383 self.container.module(db) 371 self.container.module(db)
384 } 372 }
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 @@
2 2
3use hir_expand::InFile; 3use hir_expand::InFile;
4use ra_arena::map::ArenaMap; 4use ra_arena::map::ArenaMap;
5use ra_syntax::ast; 5use ra_syntax::AstNode;
6 6
7use crate::{ 7use crate::{db::DefDatabase, AssocItemLoc, ItemLoc};
8 db::DefDatabase, ConstLoc, EnumLoc, FunctionLoc, ImplLoc, StaticLoc, StructLoc, TraitLoc,
9 TypeAliasLoc, UnionLoc,
10};
11 8
12pub trait HasSource { 9pub trait HasSource {
13 type Value; 10 type Value;
14 fn source(&self, db: &impl DefDatabase) -> InFile<Self::Value>; 11 fn source(&self, db: &impl DefDatabase) -> InFile<Self::Value>;
15} 12}
16 13
17impl HasSource for FunctionLoc { 14impl<N: AstNode> HasSource for AssocItemLoc<N> {
18 type Value = ast::FnDef; 15 type Value = N;
19 16
20 fn source(&self, db: &impl DefDatabase) -> InFile<ast::FnDef> { 17 fn source(&self, db: &impl DefDatabase) -> InFile<N> {
21 let node = self.ast_id.to_node(db); 18 let node = self.ast_id.to_node(db);
22 InFile::new(self.ast_id.file_id, node) 19 InFile::new(self.ast_id.file_id, node)
23 } 20 }
24} 21}
25 22
26impl HasSource for TypeAliasLoc { 23impl<N: AstNode> HasSource for ItemLoc<N> {
27 type Value = ast::TypeAliasDef; 24 type Value = N;
28 25
29 fn source(&self, db: &impl DefDatabase) -> InFile<ast::TypeAliasDef> { 26 fn source(&self, db: &impl DefDatabase) -> InFile<N> {
30 let node = self.ast_id.to_node(db);
31 InFile::new(self.ast_id.file_id, node)
32 }
33}
34
35impl HasSource for ConstLoc {
36 type Value = ast::ConstDef;
37
38 fn source(&self, db: &impl DefDatabase) -> InFile<ast::ConstDef> {
39 let node = self.ast_id.to_node(db);
40 InFile::new(self.ast_id.file_id, node)
41 }
42}
43
44impl HasSource for StaticLoc {
45 type Value = ast::StaticDef;
46
47 fn source(&self, db: &impl DefDatabase) -> InFile<ast::StaticDef> {
48 let node = self.ast_id.to_node(db);
49 InFile::new(self.ast_id.file_id, node)
50 }
51}
52
53impl HasSource for ImplLoc {
54 type Value = ast::ImplBlock;
55
56 fn source(&self, db: &impl DefDatabase) -> InFile<ast::ImplBlock> {
57 let node = self.ast_id.to_node(db);
58 InFile::new(self.ast_id.file_id, node)
59 }
60}
61
62impl HasSource for TraitLoc {
63 type Value = ast::TraitDef;
64
65 fn source(&self, db: &impl DefDatabase) -> InFile<ast::TraitDef> {
66 let node = self.ast_id.to_node(db);
67 InFile::new(self.ast_id.file_id, node)
68 }
69}
70
71impl HasSource for StructLoc {
72 type Value = ast::StructDef;
73
74 fn source(&self, db: &impl DefDatabase) -> InFile<ast::StructDef> {
75 let node = self.ast_id.to_node(db);
76 InFile::new(self.ast_id.file_id, node)
77 }
78}
79
80impl HasSource for UnionLoc {
81 type Value = ast::UnionDef;
82
83 fn source(&self, db: &impl DefDatabase) -> InFile<ast::UnionDef> {
84 let node = self.ast_id.to_node(db);
85 InFile::new(self.ast_id.file_id, node)
86 }
87}
88
89impl HasSource for EnumLoc {
90 type Value = ast::EnumDef;
91
92 fn source(&self, db: &impl DefDatabase) -> InFile<ast::EnumDef> {
93 let node = self.ast_id.to_node(db); 27 let node = self.ast_id.to_node(db);
94 InFile::new(self.ast_id.file_id, node) 28 InFile::new(self.ast_id.file_id, node)
95 } 29 }