less generics

This commit is contained in:
Aleksey Kladov 2019-10-29 15:20:08 +03:00
parent 6bf7faf315
commit 858dd48af2
2 changed files with 9 additions and 6 deletions

View file

@ -75,17 +75,19 @@ impl AstIdMap {
} }
pub fn ast_id<N: AstNode>(&self, item: &N) -> FileAstId<N> { pub fn ast_id<N: AstNode>(&self, item: &N) -> FileAstId<N> {
let ptr = SyntaxNodePtr::new(item.syntax()); let raw = self.erased_ast_id(item.syntax());
let raw = match self.arena.iter().find(|(_id, i)| **i == ptr) { FileAstId { raw, _ty: PhantomData }
}
fn erased_ast_id(&self, item: &SyntaxNode) -> ErasedFileAstId {
let ptr = SyntaxNodePtr::new(item);
match self.arena.iter().find(|(_id, i)| **i == ptr) {
Some((it, _)) => it, Some((it, _)) => it,
None => panic!( None => panic!(
"Can't find {:?} in AstIdMap:\n{:?}", "Can't find {:?} in AstIdMap:\n{:?}",
item.syntax(), item,
self.arena.iter().map(|(_id, i)| i).collect::<Vec<_>>(), self.arena.iter().map(|(_id, i)| i).collect::<Vec<_>>(),
), ),
}; }
FileAstId { raw, _ty: PhantomData }
} }
fn alloc(&mut self, item: &SyntaxNode) -> ErasedFileAstId { fn alloc(&mut self, item: &SyntaxNode) -> ErasedFileAstId {

View file

@ -10,6 +10,7 @@ use crate::{
HirFileId, HirFileIdRepr, MacroCallId, MacroCallLoc, MacroDefId, MacroFile, MacroFileKind, HirFileId, HirFileIdRepr, MacroCallId, MacroCallLoc, MacroDefId, MacroFile, MacroFileKind,
}; };
// FIXME: rename to ExpandDatabase
#[salsa::query_group(AstDatabaseStorage)] #[salsa::query_group(AstDatabaseStorage)]
pub trait AstDatabase: SourceDatabase { pub trait AstDatabase: SourceDatabase {
fn ast_id_map(&self, file_id: HirFileId) -> Arc<AstIdMap>; fn ast_id_map(&self, file_id: HirFileId) -> Arc<AstIdMap>;