aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-12-09 10:18:46 +0000
committerAleksey Kladov <[email protected]>2018-12-09 10:18:46 +0000
commit159525b120121b217f2831869b6ea9a3cf9fe554 (patch)
treecde35c9e5218afd721a159f46c768641b496dd63 /crates
parent13100da7a2aa97cdbda9ed4bd99896e2ff6d5cf6 (diff)
Check Fileid in SourceFileMap
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/lib.rs20
-rw-r--r--crates/ra_hir/src/module.rs2
-rw-r--r--crates/ra_hir/src/module/nameres.rs4
-rw-r--r--crates/ra_hir/src/query_definitions.rs2
-rw-r--r--crates/ra_hir/src/source_binder.rs2
5 files changed, 23 insertions, 7 deletions
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index 983ce99cb..f50b922af 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -110,16 +110,32 @@ pub struct SourceItemId {
110} 110}
111 111
112/// Maps item's `SyntaxNode`s to `SourceFileItemId` and back. 112/// Maps item's `SyntaxNode`s to `SourceFileItemId` and back.
113#[derive(Debug, PartialEq, Eq, Default)] 113#[derive(Debug, PartialEq, Eq)]
114pub struct SourceFileItems { 114pub struct SourceFileItems {
115 file_id: FileId,
115 arena: Arena<SyntaxNode>, 116 arena: Arena<SyntaxNode>,
116} 117}
117 118
118impl SourceFileItems { 119impl SourceFileItems {
120 fn new(file_id: FileId) -> SourceFileItems {
121 SourceFileItems {
122 file_id,
123 arena: Arena::default(),
124 }
125 }
126
119 fn alloc(&mut self, item: SyntaxNode) -> SourceFileItemId { 127 fn alloc(&mut self, item: SyntaxNode) -> SourceFileItemId {
120 self.arena.alloc(item) 128 self.arena.alloc(item)
121 } 129 }
122 pub fn id_of(&self, item: SyntaxNodeRef) -> SourceFileItemId { 130 pub fn id_of(&self, file_id: FileId, item: SyntaxNodeRef) -> SourceFileItemId {
131 assert_eq!(
132 self.file_id, file_id,
133 "SourceFileItems: wrong file, expected {:?}, got {:?}",
134 self.file_id, file_id
135 );
136 self.id_of_unchecked(item)
137 }
138 fn id_of_unchecked(&self, item: SyntaxNodeRef) -> SourceFileItemId {
123 let (id, _item) = self 139 let (id, _item) = self
124 .arena 140 .arena
125 .iter() 141 .iter()
diff --git a/crates/ra_hir/src/module.rs b/crates/ra_hir/src/module.rs
index 580c737c3..e7a49f83a 100644
--- a/crates/ra_hir/src/module.rs
+++ b/crates/ra_hir/src/module.rs
@@ -280,7 +280,7 @@ impl ModuleSource {
280 ) -> ModuleSource { 280 ) -> ModuleSource {
281 assert!(!m.has_semi()); 281 assert!(!m.has_semi());
282 let file_items = db.file_items(file_id); 282 let file_items = db.file_items(file_id);
283 let item_id = file_items.id_of(m.syntax()); 283 let item_id = file_items.id_of(file_id, m.syntax());
284 ModuleSource::new(file_id, item_id) 284 ModuleSource::new(file_id, item_id)
285 } 285 }
286 286
diff --git a/crates/ra_hir/src/module/nameres.rs b/crates/ra_hir/src/module/nameres.rs
index 61a1acfe6..6511359d0 100644
--- a/crates/ra_hir/src/module/nameres.rs
+++ b/crates/ra_hir/src/module/nameres.rs
@@ -168,7 +168,7 @@ impl InputModuleItems {
168 } 168 }
169 169
170 fn add_use_item(&mut self, file_items: &SourceFileItems, item: ast::UseItem) { 170 fn add_use_item(&mut self, file_items: &SourceFileItems, item: ast::UseItem) {
171 let file_item_id = file_items.id_of(item.syntax()); 171 let file_item_id = file_items.id_of_unchecked(item.syntax());
172 let start_offset = item.syntax().range().start(); 172 let start_offset = item.syntax().range().start();
173 Path::expand_use_item(item, |path, range| { 173 Path::expand_use_item(item, |path, range| {
174 let kind = match range { 174 let kind = match range {
@@ -188,7 +188,7 @@ impl ModuleItem {
188 let name = item.name()?.text(); 188 let name = item.name()?.text();
189 let kind = item.syntax().kind(); 189 let kind = item.syntax().kind();
190 let vis = Vis::Other; 190 let vis = Vis::Other;
191 let id = file_items.id_of(item.syntax()); 191 let id = file_items.id_of_unchecked(item.syntax());
192 let res = ModuleItem { 192 let res = ModuleItem {
193 id, 193 id,
194 name, 194 name,
diff --git a/crates/ra_hir/src/query_definitions.rs b/crates/ra_hir/src/query_definitions.rs
index e4d721601..bb4457d07 100644
--- a/crates/ra_hir/src/query_definitions.rs
+++ b/crates/ra_hir/src/query_definitions.rs
@@ -36,7 +36,7 @@ pub(super) fn fn_scopes(db: &impl HirDatabase, fn_id: FnId) -> Arc<FnScopes> {
36} 36}
37 37
38pub(super) fn file_items(db: &impl HirDatabase, file_id: FileId) -> Arc<SourceFileItems> { 38pub(super) fn file_items(db: &impl HirDatabase, file_id: FileId) -> Arc<SourceFileItems> {
39 let mut res = SourceFileItems::default(); 39 let mut res = SourceFileItems::new(file_id);
40 let source_file = db.source_file(file_id); 40 let source_file = db.source_file(file_id);
41 res.alloc(source_file.syntax().owned()); 41 res.alloc(source_file.syntax().owned());
42 let source_file = source_file.borrowed(); 42 let source_file = source_file.borrowed();
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index 479155805..0c16ccc24 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -75,7 +75,7 @@ pub fn function_from_source(
75) -> Cancelable<Option<Function>> { 75) -> Cancelable<Option<Function>> {
76 let module = ctry!(module_from_child_node(db, file_id, fn_def.syntax())?); 76 let module = ctry!(module_from_child_node(db, file_id, fn_def.syntax())?);
77 let file_items = db.file_items(file_id); 77 let file_items = db.file_items(file_id);
78 let item_id = file_items.id_of(fn_def.syntax()); 78 let item_id = file_items.id_of(file_id, fn_def.syntax());
79 let source_item_id = SourceItemId { file_id, item_id }; 79 let source_item_id = SourceItemId { file_id, item_id };
80 let def_loc = DefLoc { 80 let def_loc = DefLoc {
81 kind: DefKind::Function, 81 kind: DefKind::Function,