7989: Remove `ItemTree::source` r=jonas-schievink a=jonas-schievink

`HasSource` should be used instead

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
This commit is contained in:
bors[bot] 2021-03-12 22:55:02 +00:00 committed by GitHub
commit 5368e2c103
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 18 deletions

View File

@ -209,18 +209,6 @@ pub fn inner_items_of_block(&self, block: FileAstId<ast::BlockExpr>) -> &[ModIte
}
}
pub fn source<S: ItemTreeNode>(&self, db: &dyn DefDatabase, of: ItemTreeId<S>) -> S::Source {
// This unwrap cannot fail, since it has either succeeded above, or resulted in an empty
// ItemTree (in which case there is no valid `FileItemTreeId` to call this method with).
let root =
db.parse_or_expand(of.file_id).expect("parse_or_expand failed on constructed ItemTree");
let id = self[of.value].ast_id();
let map = db.ast_id_map(of.file_id);
let ptr = map.get(id);
ptr.to_node(&root)
}
fn data(&self) -> &ItemTreeData {
self.data.as_ref().expect("attempted to access data of empty ItemTree")
}

View File

@ -19,6 +19,7 @@
item_scope::ItemScope,
keys,
nameres::DefMap,
src::HasSource,
AssocItemId, DefWithBodyId, LocalModuleId, Lookup, ModuleDefId,
};
use hir_expand::{db::AstDatabase, InFile};
@ -195,18 +196,15 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String {
defs.sort_by_key(|def| match def {
DefWithBodyId::FunctionId(it) => {
let loc = it.lookup(&db);
let tree = db.item_tree(loc.id.file_id);
tree.source(&db, loc.id).syntax().text_range().start()
loc.source(&db).value.syntax().text_range().start()
}
DefWithBodyId::ConstId(it) => {
let loc = it.lookup(&db);
let tree = db.item_tree(loc.id.file_id);
tree.source(&db, loc.id).syntax().text_range().start()
loc.source(&db).value.syntax().text_range().start()
}
DefWithBodyId::StaticId(it) => {
let loc = it.lookup(&db);
let tree = db.item_tree(loc.id.file_id);
tree.source(&db, loc.id).syntax().text_range().start()
loc.source(&db).value.syntax().text_range().start()
}
});
for def in defs {