diff options
-rw-r--r-- | crates/hir_def/src/item_tree.rs | 12 | ||||
-rw-r--r-- | crates/hir_ty/src/tests.rs | 10 |
2 files changed, 4 insertions, 18 deletions
diff --git a/crates/hir_def/src/item_tree.rs b/crates/hir_def/src/item_tree.rs index 6bb334573..09bcb10dc 100644 --- a/crates/hir_def/src/item_tree.rs +++ b/crates/hir_def/src/item_tree.rs | |||
@@ -209,18 +209,6 @@ impl ItemTree { | |||
209 | } | 209 | } |
210 | } | 210 | } |
211 | 211 | ||
212 | pub fn source<S: ItemTreeNode>(&self, db: &dyn DefDatabase, of: ItemTreeId<S>) -> S::Source { | ||
213 | // This unwrap cannot fail, since it has either succeeded above, or resulted in an empty | ||
214 | // ItemTree (in which case there is no valid `FileItemTreeId` to call this method with). | ||
215 | let root = | ||
216 | db.parse_or_expand(of.file_id).expect("parse_or_expand failed on constructed ItemTree"); | ||
217 | |||
218 | let id = self[of.value].ast_id(); | ||
219 | let map = db.ast_id_map(of.file_id); | ||
220 | let ptr = map.get(id); | ||
221 | ptr.to_node(&root) | ||
222 | } | ||
223 | |||
224 | fn data(&self) -> &ItemTreeData { | 212 | fn data(&self) -> &ItemTreeData { |
225 | self.data.as_ref().expect("attempted to access data of empty ItemTree") | 213 | self.data.as_ref().expect("attempted to access data of empty ItemTree") |
226 | } | 214 | } |
diff --git a/crates/hir_ty/src/tests.rs b/crates/hir_ty/src/tests.rs index fc770ea60..0a4141e69 100644 --- a/crates/hir_ty/src/tests.rs +++ b/crates/hir_ty/src/tests.rs | |||
@@ -19,6 +19,7 @@ use hir_def::{ | |||
19 | item_scope::ItemScope, | 19 | item_scope::ItemScope, |
20 | keys, | 20 | keys, |
21 | nameres::DefMap, | 21 | nameres::DefMap, |
22 | src::HasSource, | ||
22 | AssocItemId, DefWithBodyId, LocalModuleId, Lookup, ModuleDefId, | 23 | AssocItemId, DefWithBodyId, LocalModuleId, Lookup, ModuleDefId, |
23 | }; | 24 | }; |
24 | use hir_expand::{db::AstDatabase, InFile}; | 25 | use hir_expand::{db::AstDatabase, InFile}; |
@@ -195,18 +196,15 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String { | |||
195 | defs.sort_by_key(|def| match def { | 196 | defs.sort_by_key(|def| match def { |
196 | DefWithBodyId::FunctionId(it) => { | 197 | DefWithBodyId::FunctionId(it) => { |
197 | let loc = it.lookup(&db); | 198 | let loc = it.lookup(&db); |
198 | let tree = db.item_tree(loc.id.file_id); | 199 | loc.source(&db).value.syntax().text_range().start() |
199 | tree.source(&db, loc.id).syntax().text_range().start() | ||
200 | } | 200 | } |
201 | DefWithBodyId::ConstId(it) => { | 201 | DefWithBodyId::ConstId(it) => { |
202 | let loc = it.lookup(&db); | 202 | let loc = it.lookup(&db); |
203 | let tree = db.item_tree(loc.id.file_id); | 203 | loc.source(&db).value.syntax().text_range().start() |
204 | tree.source(&db, loc.id).syntax().text_range().start() | ||
205 | } | 204 | } |
206 | DefWithBodyId::StaticId(it) => { | 205 | DefWithBodyId::StaticId(it) => { |
207 | let loc = it.lookup(&db); | 206 | let loc = it.lookup(&db); |
208 | let tree = db.item_tree(loc.id.file_id); | 207 | loc.source(&db).value.syntax().text_range().start() |
209 | tree.source(&db, loc.id).syntax().text_range().start() | ||
210 | } | 208 | } |
211 | }); | 209 | }); |
212 | for def in defs { | 210 | for def in defs { |