diff options
author | Aleksey Kladov <[email protected]> | 2019-10-29 12:01:55 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-10-29 12:01:55 +0000 |
commit | dba767802d05c493b7798b0173a2d102dcc73a95 (patch) | |
tree | 758276e45d5eb57f2eaa2460c29b3ddbf6385af8 | |
parent | 5b803055b7b690a57f1c08da8f1640139c739e76 (diff) |
make file id repr private again
-rw-r--r-- | crates/ra_hir_expand/src/expand.rs | 29 |
1 files changed, 17 insertions, 12 deletions
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 { | |||
39 | /// finite (because everything bottoms out at the real `FileId`) and small | 39 | /// finite (because everything bottoms out at the real `FileId`) and small |
40 | /// (`MacroCallId` uses the location interner). | 40 | /// (`MacroCallId` uses the location interner). |
41 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 41 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
42 | pub enum HirFileId { | 42 | pub struct HirFileId(HirFileIdRepr); |
43 | |||
44 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
45 | enum HirFileIdRepr { | ||
43 | FileId(FileId), | 46 | FileId(FileId), |
44 | MacroFile(MacroFile), | 47 | MacroFile(MacroFile), |
45 | } | 48 | } |
46 | 49 | ||
47 | impl From<FileId> for HirFileId { | 50 | impl From<FileId> for HirFileId { |
48 | fn from(id: FileId) -> Self { | 51 | fn from(id: FileId) -> Self { |
49 | HirFileId::FileId(id) | 52 | HirFileId(HirFileIdRepr::FileId(id)) |
50 | } | 53 | } |
51 | } | 54 | } |
52 | 55 | ||
53 | impl From<MacroFile> for HirFileId { | 56 | impl From<MacroFile> for HirFileId { |
54 | fn from(id: MacroFile) -> Self { | 57 | fn from(id: MacroFile) -> Self { |
55 | HirFileId::MacroFile(id) | 58 | HirFileId(HirFileIdRepr::MacroFile(id)) |
56 | } | 59 | } |
57 | } | 60 | } |
58 | 61 | ||
@@ -60,9 +63,9 @@ impl HirFileId { | |||
60 | /// For macro-expansion files, returns the file original source file the | 63 | /// For macro-expansion files, returns the file original source file the |
61 | /// expansion originated from. | 64 | /// expansion originated from. |
62 | pub fn original_file(self, db: &impl AstDatabase) -> FileId { | 65 | pub fn original_file(self, db: &impl AstDatabase) -> FileId { |
63 | match self { | 66 | match self.0 { |
64 | HirFileId::FileId(file_id) => file_id, | 67 | HirFileIdRepr::FileId(file_id) => file_id, |
65 | HirFileId::MacroFile(macro_file) => { | 68 | HirFileIdRepr::MacroFile(macro_file) => { |
66 | let loc = db.lookup_intern_macro(macro_file.macro_call_id); | 69 | let loc = db.lookup_intern_macro(macro_file.macro_call_id); |
67 | loc.ast_id.file_id().original_file(db) | 70 | loc.ast_id.file_id().original_file(db) |
68 | } | 71 | } |
@@ -71,9 +74,9 @@ impl HirFileId { | |||
71 | 74 | ||
72 | /// Get the crate which the macro lives in, if it is a macro file. | 75 | /// Get the crate which the macro lives in, if it is a macro file. |
73 | pub fn macro_crate(self, db: &impl AstDatabase) -> Option<CrateId> { | 76 | pub fn macro_crate(self, db: &impl AstDatabase) -> Option<CrateId> { |
74 | match self { | 77 | match self.0 { |
75 | HirFileId::FileId(_) => None, | 78 | HirFileIdRepr::FileId(_) => None, |
76 | HirFileId::MacroFile(macro_file) => { | 79 | HirFileIdRepr::MacroFile(macro_file) => { |
77 | let loc = db.lookup_intern_macro(macro_file.macro_call_id); | 80 | let loc = db.lookup_intern_macro(macro_file.macro_call_id); |
78 | Some(loc.def.krate) | 81 | Some(loc.def.krate) |
79 | } | 82 | } |
@@ -215,9 +218,11 @@ pub(crate) fn parse_or_expand_query( | |||
215 | db: &impl AstDatabase, | 218 | db: &impl AstDatabase, |
216 | file_id: HirFileId, | 219 | file_id: HirFileId, |
217 | ) -> Option<SyntaxNode> { | 220 | ) -> Option<SyntaxNode> { |
218 | match file_id { | 221 | match file_id.0 { |
219 | HirFileId::FileId(file_id) => Some(db.parse(file_id).tree().syntax().clone()), | 222 | HirFileIdRepr::FileId(file_id) => Some(db.parse(file_id).tree().syntax().clone()), |
220 | HirFileId::MacroFile(macro_file) => db.parse_macro(macro_file).map(|it| it.syntax_node()), | 223 | HirFileIdRepr::MacroFile(macro_file) => { |
224 | db.parse_macro(macro_file).map(|it| it.syntax_node()) | ||
225 | } | ||
221 | } | 226 | } |
222 | } | 227 | } |
223 | 228 | ||