diff options
author | Aleksey Kladov <[email protected]> | 2018-12-09 10:18:46 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-12-09 10:18:46 +0000 |
commit | 159525b120121b217f2831869b6ea9a3cf9fe554 (patch) | |
tree | cde35c9e5218afd721a159f46c768641b496dd63 /crates/ra_hir/src/lib.rs | |
parent | 13100da7a2aa97cdbda9ed4bd99896e2ff6d5cf6 (diff) |
Check Fileid in SourceFileMap
Diffstat (limited to 'crates/ra_hir/src/lib.rs')
-rw-r--r-- | crates/ra_hir/src/lib.rs | 20 |
1 files changed, 18 insertions, 2 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)] |
114 | pub struct SourceFileItems { | 114 | pub struct SourceFileItems { |
115 | file_id: FileId, | ||
115 | arena: Arena<SyntaxNode>, | 116 | arena: Arena<SyntaxNode>, |
116 | } | 117 | } |
117 | 118 | ||
118 | impl SourceFileItems { | 119 | impl 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() |