aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/code_model
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/code_model')
-rw-r--r--crates/ra_hir/src/code_model/src.rs29
1 files changed, 2 insertions, 27 deletions
diff --git a/crates/ra_hir/src/code_model/src.rs b/crates/ra_hir/src/code_model/src.rs
index b9d21bdd7..a0e605603 100644
--- a/crates/ra_hir/src/code_model/src.rs
+++ b/crates/ra_hir/src/code_model/src.rs
@@ -2,11 +2,10 @@
2 2
3use hir_def::{AstItemDef, HasChildSource, HasSource as _, Lookup, VariantId}; 3use hir_def::{AstItemDef, HasChildSource, HasSource as _, Lookup, VariantId};
4use hir_expand::either::Either; 4use hir_expand::either::Either;
5use ra_syntax::ast::{self, AstNode}; 5use ra_syntax::ast;
6 6
7use crate::{ 7use crate::{
8 db::{DefDatabase, HirDatabase}, 8 db::DefDatabase, Const, Enum, EnumVariant, FieldSource, Function, Import, MacroDef, Module,
9 Const, Enum, EnumVariant, FieldSource, Function, HasBody, Import, MacroDef, Module,
10 ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union, 9 ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union,
11}; 10};
12 11
@@ -121,27 +120,3 @@ impl HasSource for Import {
121 src.with_value(ptr.map(|it| it.to_node(&root), |it| it.to_node(&root))) 120 src.with_value(ptr.map(|it| it.to_node(&root), |it| it.to_node(&root)))
122 } 121 }
123} 122}
124
125pub trait HasBodySource: HasBody + HasSource
126where
127 Self::Ast: AstNode,
128{
129 fn expr_source(
130 self,
131 db: &impl HirDatabase,
132 expr_id: crate::expr::ExprId,
133 ) -> Option<Source<Either<ast::Expr, ast::RecordField>>> {
134 let source_map = self.body_source_map(db);
135 let source_ptr = source_map.expr_syntax(expr_id)?;
136 let root = source_ptr.file_syntax(db);
137 let source = source_ptr.map(|ast| ast.map(|it| it.to_node(&root), |it| it.to_node(&root)));
138 Some(source)
139 }
140}
141
142impl<T> HasBodySource for T
143where
144 T: HasBody + HasSource,
145 T::Ast: AstNode,
146{
147}