aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/code_model.rs20
-rw-r--r--crates/ra_hir/src/docs.rs2
-rw-r--r--crates/ra_hir/src/expr.rs6
-rw-r--r--crates/ra_hir/src/expr/validation.rs2
-rw-r--r--crates/ra_hir/src/generics.rs2
-rw-r--r--crates/ra_hir/src/ty/infer.rs2
6 files changed, 21 insertions, 13 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 765850488..aa6eb741b 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -603,6 +603,14 @@ pub struct Function {
603 pub(crate) id: FunctionId, 603 pub(crate) id: FunctionId,
604} 604}
605 605
606impl HasSource for Function {
607 type Ast = TreeArc<ast::FnDef>;
608
609 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::FnDef>> {
610 self.id.source(db).into()
611 }
612}
613
606/// The declared signature of a function. 614/// The declared signature of a function.
607#[derive(Debug, Clone, PartialEq, Eq)] 615#[derive(Debug, Clone, PartialEq, Eq)]
608pub struct FnSignature { 616pub struct FnSignature {
@@ -619,11 +627,11 @@ impl FnSignature {
619 db: &(impl DefDatabase + AstDatabase), 627 db: &(impl DefDatabase + AstDatabase),
620 func: Function, 628 func: Function,
621 ) -> Arc<FnSignature> { 629 ) -> Arc<FnSignature> {
622 let (_, node) = func.source(db); 630 let src = func.source(db);
623 let name = node.name().map(|n| n.as_name()).unwrap_or_else(Name::missing); 631 let name = src.ast.name().map(|n| n.as_name()).unwrap_or_else(Name::missing);
624 let mut params = Vec::new(); 632 let mut params = Vec::new();
625 let mut has_self_param = false; 633 let mut has_self_param = false;
626 if let Some(param_list) = node.param_list() { 634 if let Some(param_list) = src.ast.param_list() {
627 if let Some(self_param) = param_list.self_param() { 635 if let Some(self_param) = param_list.self_param() {
628 let self_type = if let Some(type_ref) = self_param.ascribed_type() { 636 let self_type = if let Some(type_ref) = self_param.ascribed_type() {
629 TypeRef::from_ast(type_ref) 637 TypeRef::from_ast(type_ref)
@@ -647,7 +655,7 @@ impl FnSignature {
647 params.push(type_ref); 655 params.push(type_ref);
648 } 656 }
649 } 657 }
650 let ret_type = if let Some(type_ref) = node.ret_type().and_then(|rt| rt.type_ref()) { 658 let ret_type = if let Some(type_ref) = src.ast.ret_type().and_then(|rt| rt.type_ref()) {
651 TypeRef::from_ast(type_ref) 659 TypeRef::from_ast(type_ref)
652 } else { 660 } else {
653 TypeRef::unit() 661 TypeRef::unit()
@@ -676,8 +684,8 @@ impl FnSignature {
676} 684}
677 685
678impl Function { 686impl Function {
679 pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> (HirFileId, TreeArc<ast::FnDef>) { 687 pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::FnDef>> {
680 self.id.source(db) 688 self.id.source(db).into()
681 } 689 }
682 690
683 pub fn module(self, db: &impl DefDatabase) -> Module { 691 pub fn module(self, db: &impl DefDatabase) -> Module {
diff --git a/crates/ra_hir/src/docs.rs b/crates/ra_hir/src/docs.rs
index 70b9d13b2..8d7a5255f 100644
--- a/crates/ra_hir/src/docs.rs
+++ b/crates/ra_hir/src/docs.rs
@@ -81,7 +81,7 @@ pub(crate) fn documentation_query(
81 DocDef::EnumVariant(it) => docs_from_ast(&*it.source(db).ast), 81 DocDef::EnumVariant(it) => docs_from_ast(&*it.source(db).ast),
82 DocDef::Static(it) => docs_from_ast(&*it.source(db).1), 82 DocDef::Static(it) => docs_from_ast(&*it.source(db).1),
83 DocDef::Const(it) => docs_from_ast(&*it.source(db).1), 83 DocDef::Const(it) => docs_from_ast(&*it.source(db).1),
84 DocDef::Function(it) => docs_from_ast(&*it.source(db).1), 84 DocDef::Function(it) => docs_from_ast(&*it.source(db).ast),
85 DocDef::Union(it) => docs_from_ast(&*it.source(db).1), 85 DocDef::Union(it) => docs_from_ast(&*it.source(db).1),
86 DocDef::Trait(it) => docs_from_ast(&*it.source(db).1), 86 DocDef::Trait(it) => docs_from_ast(&*it.source(db).1),
87 DocDef::TypeAlias(it) => docs_from_ast(&*it.source(db).1), 87 DocDef::TypeAlias(it) => docs_from_ast(&*it.source(db).1),
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs
index 012f374ec..46d51e0db 100644
--- a/crates/ra_hir/src/expr.rs
+++ b/crates/ra_hir/src/expr.rs
@@ -1023,9 +1023,9 @@ pub(crate) fn body_with_source_map_query(
1023 collector.collect_const_body(&src) 1023 collector.collect_const_body(&src)
1024 } 1024 }
1025 DefWithBody::Function(ref f) => { 1025 DefWithBody::Function(ref f) => {
1026 let (file_id, src) = f.source(db); 1026 let src = f.source(db);
1027 collector = ExprCollector::new(def, file_id, def.resolver(db), db); 1027 collector = ExprCollector::new(def, src.file_id, def.resolver(db), db);
1028 collector.collect_fn_body(&src) 1028 collector.collect_fn_body(&src.ast)
1029 } 1029 }
1030 DefWithBody::Static(ref s) => { 1030 DefWithBody::Static(ref s) => {
1031 let (file_id, src) = s.source(db); 1031 let (file_id, src) = s.source(db);
diff --git a/crates/ra_hir/src/expr/validation.rs b/crates/ra_hir/src/expr/validation.rs
index a1b2641da..ff5e5f68e 100644
--- a/crates/ra_hir/src/expr/validation.rs
+++ b/crates/ra_hir/src/expr/validation.rs
@@ -71,7 +71,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
71 return; 71 return;
72 } 72 }
73 let source_map = self.func.body_source_map(db); 73 let source_map = self.func.body_source_map(db);
74 let file_id = self.func.source(db).0; 74 let file_id = self.func.source(db).file_id;
75 let source_file = db.parse(file_id.original_file(db)).tree; 75 let source_file = db.parse(file_id.original_file(db)).tree;
76 if let Some(field_list_node) = source_map 76 if let Some(field_list_node) = source_map
77 .expr_syntax(id) 77 .expr_syntax(id)
diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs
index 2a92d5945..fcccd67c8 100644
--- a/crates/ra_hir/src/generics.rs
+++ b/crates/ra_hir/src/generics.rs
@@ -68,7 +68,7 @@ impl GenericParams {
68 generics.parent_params = parent.map(|p| db.generic_params(p)); 68 generics.parent_params = parent.map(|p| db.generic_params(p));
69 let start = generics.parent_params.as_ref().map(|p| p.params.len()).unwrap_or(0) as u32; 69 let start = generics.parent_params.as_ref().map(|p| p.params.len()).unwrap_or(0) as u32;
70 match def { 70 match def {
71 GenericDef::Function(it) => generics.fill(&*it.source(db).1, start), 71 GenericDef::Function(it) => generics.fill(&*it.source(db).ast, start),
72 GenericDef::Struct(it) => generics.fill(&*it.source(db).ast, start), 72 GenericDef::Struct(it) => generics.fill(&*it.source(db).ast, start),
73 GenericDef::Union(it) => generics.fill(&*it.source(db).1, start), 73 GenericDef::Union(it) => generics.fill(&*it.source(db).1, start),
74 GenericDef::Enum(it) => generics.fill(&*it.source(db).ast, start), 74 GenericDef::Enum(it) => generics.fill(&*it.source(db).ast, start),
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs
index 6aa727ea1..a534c2336 100644
--- a/crates/ra_hir/src/ty/infer.rs
+++ b/crates/ra_hir/src/ty/infer.rs
@@ -1432,7 +1432,7 @@ mod diagnostics {
1432 ) { 1432 ) {
1433 match self { 1433 match self {
1434 InferenceDiagnostic::NoSuchField { expr, field } => { 1434 InferenceDiagnostic::NoSuchField { expr, field } => {
1435 let (file, _) = owner.source(db); 1435 let file = owner.source(db).file_id;
1436 let field = owner.body_source_map(db).field_syntax(*expr, *field); 1436 let field = owner.body_source_map(db).field_syntax(*expr, *field);
1437 sink.push(NoSuchField { file, field }) 1437 sink.push(NoSuchField { file, field })
1438 } 1438 }