aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/lib.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-11-28 15:05:28 +0000
committerAleksey Kladov <[email protected]>2019-11-28 16:05:21 +0000
commit8f1f5a783a3ffd0afbf5b1fdf22ff9caf7fda928 (patch)
tree38f32326e41d86d8c8a3c598ff4fbe66c557b4bd /crates/ra_hir_def/src/lib.rs
parent2c7f6b573e9b6133cc147a529dd2a23119bb4ae5 (diff)
Move source-related traits to a separate module
Diffstat (limited to 'crates/ra_hir_def/src/lib.rs')
-rw-r--r--crates/ra_hir_def/src/lib.rs54
1 files changed, 3 insertions, 51 deletions
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs
index 6daf7d3a3..cfeacfded 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -29,6 +29,8 @@ pub mod resolver;
29mod trace; 29mod trace;
30pub mod nameres; 30pub mod nameres;
31 31
32pub mod src;
33
32#[cfg(test)] 34#[cfg(test)]
33mod test_db; 35mod test_db;
34#[cfg(test)] 36#[cfg(test)]
@@ -37,7 +39,7 @@ mod marks;
37use std::hash::{Hash, Hasher}; 39use std::hash::{Hash, Hasher};
38 40
39use hir_expand::{ast_id_map::FileAstId, db::AstDatabase, AstId, HirFileId, InFile, MacroDefId}; 41use hir_expand::{ast_id_map::FileAstId, db::AstDatabase, AstId, HirFileId, InFile, MacroDefId};
40use ra_arena::{impl_arena_id, map::ArenaMap, RawId}; 42use ra_arena::{impl_arena_id, RawId};
41use ra_db::{impl_intern_key, salsa, CrateId}; 43use ra_db::{impl_intern_key, salsa, CrateId};
42use ra_syntax::{ast, AstNode}; 44use ra_syntax::{ast, AstNode};
43 45
@@ -514,53 +516,3 @@ impl HasModule for StaticLoc {
514 self.container 516 self.container
515 } 517 }
516} 518}
517
518pub trait HasSource {
519 type Value;
520 fn source(&self, db: &impl db::DefDatabase) -> InFile<Self::Value>;
521}
522
523impl HasSource for FunctionLoc {
524 type Value = ast::FnDef;
525
526 fn source(&self, db: &impl db::DefDatabase) -> InFile<ast::FnDef> {
527 let node = self.ast_id.to_node(db);
528 InFile::new(self.ast_id.file_id, node)
529 }
530}
531
532impl HasSource for TypeAliasLoc {
533 type Value = ast::TypeAliasDef;
534
535 fn source(&self, db: &impl db::DefDatabase) -> InFile<ast::TypeAliasDef> {
536 let node = self.ast_id.to_node(db);
537 InFile::new(self.ast_id.file_id, node)
538 }
539}
540
541impl HasSource for ConstLoc {
542 type Value = ast::ConstDef;
543
544 fn source(&self, db: &impl db::DefDatabase) -> InFile<ast::ConstDef> {
545 let node = self.ast_id.to_node(db);
546 InFile::new(self.ast_id.file_id, node)
547 }
548}
549
550impl HasSource for StaticLoc {
551 type Value = ast::StaticDef;
552
553 fn source(&self, db: &impl db::DefDatabase) -> InFile<ast::StaticDef> {
554 let node = self.ast_id.to_node(db);
555 InFile::new(self.ast_id.file_id, node)
556 }
557}
558
559pub trait HasChildSource {
560 type ChildId;
561 type Value;
562 fn child_source(
563 &self,
564 db: &impl db::DefDatabase,
565 ) -> InFile<ArenaMap<Self::ChildId, Self::Value>>;
566}