From dba767802d05c493b7798b0173a2d102dcc73a95 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 29 Oct 2019 15:01:55 +0300 Subject: make file id repr private again --- crates/ra_hir_expand/src/expand.rs | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'crates/ra_hir_expand/src/expand.rs') diff --git a/crates/ra_hir_expand/src/expand.rs b/crates/ra_hir_expand/src/expand.rs index 6517ea84d..3921175cb 100644 --- a/crates/ra_hir_expand/src/expand.rs +++ b/crates/ra_hir_expand/src/expand.rs @@ -39,20 +39,23 @@ macro_rules! impl_intern_key { /// finite (because everything bottoms out at the real `FileId`) and small /// (`MacroCallId` uses the location interner). #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub enum HirFileId { +pub struct HirFileId(HirFileIdRepr); + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +enum HirFileIdRepr { FileId(FileId), MacroFile(MacroFile), } impl From for HirFileId { fn from(id: FileId) -> Self { - HirFileId::FileId(id) + HirFileId(HirFileIdRepr::FileId(id)) } } impl From for HirFileId { fn from(id: MacroFile) -> Self { - HirFileId::MacroFile(id) + HirFileId(HirFileIdRepr::MacroFile(id)) } } @@ -60,9 +63,9 @@ impl HirFileId { /// For macro-expansion files, returns the file original source file the /// expansion originated from. pub fn original_file(self, db: &impl AstDatabase) -> FileId { - match self { - HirFileId::FileId(file_id) => file_id, - HirFileId::MacroFile(macro_file) => { + match self.0 { + 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) } @@ -71,9 +74,9 @@ impl HirFileId { /// Get the crate which the macro lives in, if it is a macro file. pub fn macro_crate(self, db: &impl AstDatabase) -> Option { - match self { - HirFileId::FileId(_) => None, - HirFileId::MacroFile(macro_file) => { + match self.0 { + HirFileIdRepr::FileId(_) => None, + HirFileIdRepr::MacroFile(macro_file) => { let loc = db.lookup_intern_macro(macro_file.macro_call_id); Some(loc.def.krate) } @@ -215,9 +218,11 @@ pub(crate) fn parse_or_expand_query( db: &impl AstDatabase, file_id: HirFileId, ) -> Option { - match file_id { - HirFileId::FileId(file_id) => Some(db.parse(file_id).tree().syntax().clone()), - HirFileId::MacroFile(macro_file) => db.parse_macro(macro_file).map(|it| it.syntax_node()), + match file_id.0 { + HirFileIdRepr::FileId(file_id) => Some(db.parse(file_id).tree().syntax().clone()), + HirFileIdRepr::MacroFile(macro_file) => { + db.parse_macro(macro_file).map(|it| it.syntax_node()) + } } } -- cgit v1.2.3