aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/body.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src/body.rs')
-rw-r--r--crates/ra_hir_def/src/body.rs17
1 files changed, 9 insertions, 8 deletions
diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs
index a57a0176d..69508dd8a 100644
--- a/crates/ra_hir_def/src/body.rs
+++ b/crates/ra_hir_def/src/body.rs
@@ -6,7 +6,7 @@ pub mod scope;
6use std::{ops::Index, sync::Arc}; 6use std::{ops::Index, sync::Arc};
7 7
8use hir_expand::{ 8use hir_expand::{
9 either::Either, hygiene::Hygiene, AstId, HirFileId, MacroDefId, MacroFileKind, Source, 9 either::Either, hygiene::Hygiene, AstId, HirFileId, InFile, MacroDefId, MacroFileKind,
10}; 10};
11use ra_arena::{map::ArenaMap, Arena}; 11use ra_arena::{map::ArenaMap, Arena};
12use ra_syntax::{ast, AstNode, AstPtr}; 12use ra_syntax::{ast, AstNode, AstPtr};
@@ -17,7 +17,8 @@ use crate::{
17 expr::{Expr, ExprId, Pat, PatId}, 17 expr::{Expr, ExprId, Pat, PatId},
18 nameres::CrateDefMap, 18 nameres::CrateDefMap,
19 path::Path, 19 path::Path,
20 DefWithBodyId, HasModule, HasSource, Lookup, ModuleId, 20 src::HasSource,
21 DefWithBodyId, HasModule, Lookup, ModuleId,
21}; 22};
22 23
23struct Expander { 24struct Expander {
@@ -73,8 +74,8 @@ impl Expander {
73 std::mem::forget(mark); 74 std::mem::forget(mark);
74 } 75 }
75 76
76 fn to_source<T>(&self, value: T) -> Source<T> { 77 fn to_source<T>(&self, value: T) -> InFile<T> {
77 Source { file_id: self.current_file_id, value } 78 InFile { file_id: self.current_file_id, value }
78 } 79 }
79 80
80 fn parse_path(&mut self, path: ast::Path) -> Option<Path> { 81 fn parse_path(&mut self, path: ast::Path) -> Option<Path> {
@@ -115,10 +116,10 @@ pub struct Body {
115} 116}
116 117
117pub type ExprPtr = Either<AstPtr<ast::Expr>, AstPtr<ast::RecordField>>; 118pub type ExprPtr = Either<AstPtr<ast::Expr>, AstPtr<ast::RecordField>>;
118pub type ExprSource = Source<ExprPtr>; 119pub type ExprSource = InFile<ExprPtr>;
119 120
120pub type PatPtr = Either<AstPtr<ast::Pat>, AstPtr<ast::SelfParam>>; 121pub type PatPtr = Either<AstPtr<ast::Pat>, AstPtr<ast::SelfParam>>;
121pub type PatSource = Source<PatPtr>; 122pub type PatSource = InFile<PatPtr>;
122 123
123/// An item body together with the mapping from syntax nodes to HIR expression 124/// An item body together with the mapping from syntax nodes to HIR expression
124/// IDs. This is needed to go from e.g. a position in a file to the HIR 125/// IDs. This is needed to go from e.g. a position in a file to the HIR
@@ -205,7 +206,7 @@ impl BodySourceMap {
205 self.expr_map_back.get(expr).copied() 206 self.expr_map_back.get(expr).copied()
206 } 207 }
207 208
208 pub fn node_expr(&self, node: Source<&ast::Expr>) -> Option<ExprId> { 209 pub fn node_expr(&self, node: InFile<&ast::Expr>) -> Option<ExprId> {
209 let src = node.map(|it| Either::A(AstPtr::new(it))); 210 let src = node.map(|it| Either::A(AstPtr::new(it)));
210 self.expr_map.get(&src).cloned() 211 self.expr_map.get(&src).cloned()
211 } 212 }
@@ -214,7 +215,7 @@ impl BodySourceMap {
214 self.pat_map_back.get(pat).copied() 215 self.pat_map_back.get(pat).copied()
215 } 216 }
216 217
217 pub fn node_pat(&self, node: Source<&ast::Pat>) -> Option<PatId> { 218 pub fn node_pat(&self, node: InFile<&ast::Pat>) -> Option<PatId> {
218 let src = node.map(|it| Either::A(AstPtr::new(it))); 219 let src = node.map(|it| Either::A(AstPtr::new(it)));
219 self.pat_map.get(&src).cloned() 220 self.pat_map.get(&src).cloned()
220 } 221 }