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.rs24
1 files changed, 14 insertions, 10 deletions
diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs
index a57a0176d..239f35229 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};
@@ -15,9 +15,10 @@ use rustc_hash::FxHashMap;
15use crate::{ 15use crate::{
16 db::DefDatabase, 16 db::DefDatabase,
17 expr::{Expr, ExprId, Pat, PatId}, 17 expr::{Expr, ExprId, Pat, PatId},
18 nameres::CrateDefMap, 18 nameres::{BuiltinShadowMode, 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> {
@@ -82,7 +83,10 @@ impl Expander {
82 } 83 }
83 84
84 fn resolve_path_as_macro(&self, db: &impl DefDatabase, path: &Path) -> Option<MacroDefId> { 85 fn resolve_path_as_macro(&self, db: &impl DefDatabase, path: &Path) -> Option<MacroDefId> {
85 self.crate_def_map.resolve_path(db, self.module.local_id, path).0.take_macros() 86 self.crate_def_map
87 .resolve_path(db, self.module.local_id, path, BuiltinShadowMode::Other)
88 .0
89 .take_macros()
86 } 90 }
87} 91}
88 92
@@ -115,10 +119,10 @@ pub struct Body {
115} 119}
116 120
117pub type ExprPtr = Either<AstPtr<ast::Expr>, AstPtr<ast::RecordField>>; 121pub type ExprPtr = Either<AstPtr<ast::Expr>, AstPtr<ast::RecordField>>;
118pub type ExprSource = Source<ExprPtr>; 122pub type ExprSource = InFile<ExprPtr>;
119 123
120pub type PatPtr = Either<AstPtr<ast::Pat>, AstPtr<ast::SelfParam>>; 124pub type PatPtr = Either<AstPtr<ast::Pat>, AstPtr<ast::SelfParam>>;
121pub type PatSource = Source<PatPtr>; 125pub type PatSource = InFile<PatPtr>;
122 126
123/// An item body together with the mapping from syntax nodes to HIR expression 127/// 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 128/// IDs. This is needed to go from e.g. a position in a file to the HIR
@@ -205,7 +209,7 @@ impl BodySourceMap {
205 self.expr_map_back.get(expr).copied() 209 self.expr_map_back.get(expr).copied()
206 } 210 }
207 211
208 pub fn node_expr(&self, node: Source<&ast::Expr>) -> Option<ExprId> { 212 pub fn node_expr(&self, node: InFile<&ast::Expr>) -> Option<ExprId> {
209 let src = node.map(|it| Either::A(AstPtr::new(it))); 213 let src = node.map(|it| Either::A(AstPtr::new(it)));
210 self.expr_map.get(&src).cloned() 214 self.expr_map.get(&src).cloned()
211 } 215 }
@@ -214,7 +218,7 @@ impl BodySourceMap {
214 self.pat_map_back.get(pat).copied() 218 self.pat_map_back.get(pat).copied()
215 } 219 }
216 220
217 pub fn node_pat(&self, node: Source<&ast::Pat>) -> Option<PatId> { 221 pub fn node_pat(&self, node: InFile<&ast::Pat>) -> Option<PatId> {
218 let src = node.map(|it| Either::A(AstPtr::new(it))); 222 let src = node.map(|it| Either::A(AstPtr::new(it)));
219 self.pat_map.get(&src).cloned() 223 self.pat_map.get(&src).cloned()
220 } 224 }