From e823c578c9f6886fe9db9767cb81e75a6c56bf15 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 28 Nov 2019 16:00:03 +0300 Subject: Use InFile for AstId --- crates/ra_hir_expand/src/lib.rs | 39 ++++----------------------------------- 1 file changed, 4 insertions(+), 35 deletions(-) (limited to 'crates/ra_hir_expand/src') diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs index 2c5b6b2bb..fb88d2ac2 100644 --- a/crates/ra_hir_expand/src/lib.rs +++ b/crates/ra_hir_expand/src/lib.rs @@ -13,7 +13,7 @@ pub mod diagnostics; pub mod builtin_macro; pub mod quote; -use std::hash::{Hash, Hasher}; +use std::hash::Hash; use std::sync::Arc; use ra_db::{salsa, CrateId, FileId}; @@ -70,7 +70,7 @@ impl HirFileId { HirFileIdRepr::FileId(file_id) => file_id, HirFileIdRepr::MacroFile(macro_file) => { let loc = db.lookup_intern_macro(macro_file.macro_call_id); - loc.ast_id.file_id().original_file(db) + loc.ast_id.file_id.original_file(db) } } } @@ -214,43 +214,12 @@ impl ExpansionInfo { /// /// It is stable across reparses, and can be used as salsa key/value. // FIXME: isn't this just a `Source>` ? -#[derive(Debug)] -pub struct AstId { - file_id: HirFileId, - file_ast_id: FileAstId, -} - -impl Clone for AstId { - fn clone(&self) -> AstId { - *self - } -} -impl Copy for AstId {} - -impl PartialEq for AstId { - fn eq(&self, other: &Self) -> bool { - (self.file_id, self.file_ast_id) == (other.file_id, other.file_ast_id) - } -} -impl Eq for AstId {} -impl Hash for AstId { - fn hash(&self, hasher: &mut H) { - (self.file_id, self.file_ast_id).hash(hasher); - } -} +pub type AstId = InFile>; impl AstId { - pub fn new(file_id: HirFileId, file_ast_id: FileAstId) -> AstId { - AstId { file_id, file_ast_id } - } - - pub fn file_id(&self) -> HirFileId { - self.file_id - } - pub fn to_node(&self, db: &dyn db::AstDatabase) -> N { let root = db.parse_or_expand(self.file_id).unwrap(); - db.ast_id_map(self.file_id).get(self.file_ast_id).to_node(&root) + db.ast_id_map(self.file_id).get(self.value).to_node(&root) } } -- cgit v1.2.3