diff options
-rw-r--r-- | crates/ra_hir/src/code_model/src.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/attr.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/lib.rs | 10 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/tests/mod_resolution.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir_expand/src/lib.rs | 39 |
6 files changed, 16 insertions, 47 deletions
diff --git a/crates/ra_hir/src/code_model/src.rs b/crates/ra_hir/src/code_model/src.rs index 6fd4e7987..9a755704f 100644 --- a/crates/ra_hir/src/code_model/src.rs +++ b/crates/ra_hir/src/code_model/src.rs | |||
@@ -105,7 +105,7 @@ impl HasSource for TypeAlias { | |||
105 | impl HasSource for MacroDef { | 105 | impl HasSource for MacroDef { |
106 | type Ast = ast::MacroCall; | 106 | type Ast = ast::MacroCall; |
107 | fn source(self, db: &impl DefDatabase) -> InFile<ast::MacroCall> { | 107 | fn source(self, db: &impl DefDatabase) -> InFile<ast::MacroCall> { |
108 | InFile { file_id: self.id.ast_id.file_id(), value: self.id.ast_id.to_node(db) } | 108 | InFile { file_id: self.id.ast_id.file_id, value: self.id.ast_id.to_node(db) } |
109 | } | 109 | } |
110 | } | 110 | } |
111 | impl HasSource for ImplBlock { | 111 | impl HasSource for ImplBlock { |
diff --git a/crates/ra_hir_def/src/attr.rs b/crates/ra_hir_def/src/attr.rs index 83783ac7a..346019f88 100644 --- a/crates/ra_hir_def/src/attr.rs +++ b/crates/ra_hir_def/src/attr.rs | |||
@@ -157,7 +157,7 @@ where | |||
157 | N: ast::AttrsOwner, | 157 | N: ast::AttrsOwner, |
158 | D: DefDatabase, | 158 | D: DefDatabase, |
159 | { | 159 | { |
160 | let src = InFile::new(src.file_id(), src.to_node(db)); | 160 | let src = InFile::new(src.file_id, src.to_node(db)); |
161 | Attrs::from_attrs_owner(db, src.as_ref().map(|it| it as &dyn AttrsOwner)) | 161 | Attrs::from_attrs_owner(db, src.as_ref().map(|it| it as &dyn AttrsOwner)) |
162 | } | 162 | } |
163 | 163 | ||
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index 9d89692bf..6daf7d3a3 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs | |||
@@ -108,7 +108,7 @@ pub trait AstItemDef<N: AstNode>: salsa::InternKey + Clone { | |||
108 | fn source(self, db: &(impl AstDatabase + InternDatabase)) -> InFile<N> { | 108 | fn source(self, db: &(impl AstDatabase + InternDatabase)) -> InFile<N> { |
109 | let loc = self.lookup_intern(db); | 109 | let loc = self.lookup_intern(db); |
110 | let value = loc.ast_id.to_node(db); | 110 | let value = loc.ast_id.to_node(db); |
111 | InFile { file_id: loc.ast_id.file_id(), value } | 111 | InFile { file_id: loc.ast_id.file_id, value } |
112 | } | 112 | } |
113 | fn module(self, db: &impl InternDatabase) -> ModuleId { | 113 | fn module(self, db: &impl InternDatabase) -> ModuleId { |
114 | let loc = self.lookup_intern(db); | 114 | let loc = self.lookup_intern(db); |
@@ -525,7 +525,7 @@ impl HasSource for FunctionLoc { | |||
525 | 525 | ||
526 | fn source(&self, db: &impl db::DefDatabase) -> InFile<ast::FnDef> { | 526 | fn source(&self, db: &impl db::DefDatabase) -> InFile<ast::FnDef> { |
527 | let node = self.ast_id.to_node(db); | 527 | let node = self.ast_id.to_node(db); |
528 | InFile::new(self.ast_id.file_id(), node) | 528 | InFile::new(self.ast_id.file_id, node) |
529 | } | 529 | } |
530 | } | 530 | } |
531 | 531 | ||
@@ -534,7 +534,7 @@ impl HasSource for TypeAliasLoc { | |||
534 | 534 | ||
535 | fn source(&self, db: &impl db::DefDatabase) -> InFile<ast::TypeAliasDef> { | 535 | fn source(&self, db: &impl db::DefDatabase) -> InFile<ast::TypeAliasDef> { |
536 | let node = self.ast_id.to_node(db); | 536 | let node = self.ast_id.to_node(db); |
537 | InFile::new(self.ast_id.file_id(), node) | 537 | InFile::new(self.ast_id.file_id, node) |
538 | } | 538 | } |
539 | } | 539 | } |
540 | 540 | ||
@@ -543,7 +543,7 @@ impl HasSource for ConstLoc { | |||
543 | 543 | ||
544 | fn source(&self, db: &impl db::DefDatabase) -> InFile<ast::ConstDef> { | 544 | fn source(&self, db: &impl db::DefDatabase) -> InFile<ast::ConstDef> { |
545 | let node = self.ast_id.to_node(db); | 545 | let node = self.ast_id.to_node(db); |
546 | InFile::new(self.ast_id.file_id(), node) | 546 | InFile::new(self.ast_id.file_id, node) |
547 | } | 547 | } |
548 | } | 548 | } |
549 | 549 | ||
@@ -552,7 +552,7 @@ impl HasSource for StaticLoc { | |||
552 | 552 | ||
553 | fn source(&self, db: &impl db::DefDatabase) -> InFile<ast::StaticDef> { | 553 | fn source(&self, db: &impl db::DefDatabase) -> InFile<ast::StaticDef> { |
554 | let node = self.ast_id.to_node(db); | 554 | let node = self.ast_id.to_node(db); |
555 | InFile::new(self.ast_id.file_id(), node) | 555 | InFile::new(self.ast_id.file_id, node) |
556 | } | 556 | } |
557 | } | 557 | } |
558 | 558 | ||
diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs index 1b369ea11..df42ea84a 100644 --- a/crates/ra_hir_def/src/nameres.rs +++ b/crates/ra_hir_def/src/nameres.rs | |||
@@ -267,7 +267,7 @@ impl ModuleData { | |||
267 | return InFile::new(file_id.into(), Either::A(sf)); | 267 | return InFile::new(file_id.into(), Either::A(sf)); |
268 | } | 268 | } |
269 | let decl = self.declaration.unwrap(); | 269 | let decl = self.declaration.unwrap(); |
270 | InFile::new(decl.file_id(), Either::B(decl.to_node(db))) | 270 | InFile::new(decl.file_id, Either::B(decl.to_node(db))) |
271 | } | 271 | } |
272 | 272 | ||
273 | /// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`. | 273 | /// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`. |
@@ -275,7 +275,7 @@ impl ModuleData { | |||
275 | pub fn declaration_source(&self, db: &impl DefDatabase) -> Option<InFile<ast::Module>> { | 275 | pub fn declaration_source(&self, db: &impl DefDatabase) -> Option<InFile<ast::Module>> { |
276 | let decl = self.declaration?; | 276 | let decl = self.declaration?; |
277 | let value = decl.to_node(db); | 277 | let value = decl.to_node(db); |
278 | Some(InFile { file_id: decl.file_id(), value }) | 278 | Some(InFile { file_id: decl.file_id, value }) |
279 | } | 279 | } |
280 | } | 280 | } |
281 | 281 | ||
@@ -309,7 +309,7 @@ mod diagnostics { | |||
309 | } | 309 | } |
310 | let decl = declaration.to_node(db); | 310 | let decl = declaration.to_node(db); |
311 | sink.push(UnresolvedModule { | 311 | sink.push(UnresolvedModule { |
312 | file: declaration.file_id(), | 312 | file: declaration.file_id, |
313 | decl: AstPtr::new(&decl), | 313 | decl: AstPtr::new(&decl), |
314 | candidate: candidate.clone(), | 314 | candidate: candidate.clone(), |
315 | }) | 315 | }) |
diff --git a/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs b/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs index e11530062..e800cc68e 100644 --- a/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs +++ b/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs | |||
@@ -668,7 +668,7 @@ fn unresolved_module_diagnostics() { | |||
668 | module: LocalModuleId( | 668 | module: LocalModuleId( |
669 | 0, | 669 | 0, |
670 | ), | 670 | ), |
671 | declaration: AstId { | 671 | declaration: InFile { |
672 | file_id: HirFileId( | 672 | file_id: HirFileId( |
673 | FileId( | 673 | FileId( |
674 | FileId( | 674 | FileId( |
@@ -676,7 +676,7 @@ fn unresolved_module_diagnostics() { | |||
676 | ), | 676 | ), |
677 | ), | 677 | ), |
678 | ), | 678 | ), |
679 | file_ast_id: FileAstId { | 679 | value: FileAstId { |
680 | raw: ErasedFileAstId( | 680 | raw: ErasedFileAstId( |
681 | 1, | 681 | 1, |
682 | ), | 682 | ), |
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; | |||
13 | pub mod builtin_macro; | 13 | pub mod builtin_macro; |
14 | pub mod quote; | 14 | pub mod quote; |
15 | 15 | ||
16 | use std::hash::{Hash, Hasher}; | 16 | use std::hash::Hash; |
17 | use std::sync::Arc; | 17 | use std::sync::Arc; |
18 | 18 | ||
19 | use ra_db::{salsa, CrateId, FileId}; | 19 | use ra_db::{salsa, CrateId, FileId}; |
@@ -70,7 +70,7 @@ impl HirFileId { | |||
70 | HirFileIdRepr::FileId(file_id) => file_id, | 70 | HirFileIdRepr::FileId(file_id) => file_id, |
71 | HirFileIdRepr::MacroFile(macro_file) => { | 71 | HirFileIdRepr::MacroFile(macro_file) => { |
72 | let loc = db.lookup_intern_macro(macro_file.macro_call_id); | 72 | let loc = db.lookup_intern_macro(macro_file.macro_call_id); |
73 | loc.ast_id.file_id().original_file(db) | 73 | loc.ast_id.file_id.original_file(db) |
74 | } | 74 | } |
75 | } | 75 | } |
76 | } | 76 | } |
@@ -214,43 +214,12 @@ impl ExpansionInfo { | |||
214 | /// | 214 | /// |
215 | /// It is stable across reparses, and can be used as salsa key/value. | 215 | /// It is stable across reparses, and can be used as salsa key/value. |
216 | // FIXME: isn't this just a `Source<FileAstId<N>>` ? | 216 | // FIXME: isn't this just a `Source<FileAstId<N>>` ? |
217 | #[derive(Debug)] | 217 | pub type AstId<N> = InFile<FileAstId<N>>; |
218 | pub struct AstId<N: AstNode> { | ||
219 | file_id: HirFileId, | ||
220 | file_ast_id: FileAstId<N>, | ||
221 | } | ||
222 | |||
223 | impl<N: AstNode> Clone for AstId<N> { | ||
224 | fn clone(&self) -> AstId<N> { | ||
225 | *self | ||
226 | } | ||
227 | } | ||
228 | impl<N: AstNode> Copy for AstId<N> {} | ||
229 | |||
230 | impl<N: AstNode> PartialEq for AstId<N> { | ||
231 | fn eq(&self, other: &Self) -> bool { | ||
232 | (self.file_id, self.file_ast_id) == (other.file_id, other.file_ast_id) | ||
233 | } | ||
234 | } | ||
235 | impl<N: AstNode> Eq for AstId<N> {} | ||
236 | impl<N: AstNode> Hash for AstId<N> { | ||
237 | fn hash<H: Hasher>(&self, hasher: &mut H) { | ||
238 | (self.file_id, self.file_ast_id).hash(hasher); | ||
239 | } | ||
240 | } | ||
241 | 218 | ||
242 | impl<N: AstNode> AstId<N> { | 219 | impl<N: AstNode> AstId<N> { |
243 | pub fn new(file_id: HirFileId, file_ast_id: FileAstId<N>) -> AstId<N> { | ||
244 | AstId { file_id, file_ast_id } | ||
245 | } | ||
246 | |||
247 | pub fn file_id(&self) -> HirFileId { | ||
248 | self.file_id | ||
249 | } | ||
250 | |||
251 | pub fn to_node(&self, db: &dyn db::AstDatabase) -> N { | 220 | pub fn to_node(&self, db: &dyn db::AstDatabase) -> N { |
252 | let root = db.parse_or_expand(self.file_id).unwrap(); | 221 | let root = db.parse_or_expand(self.file_id).unwrap(); |
253 | db.ast_id_map(self.file_id).get(self.file_ast_id).to_node(&root) | 222 | db.ast_id_map(self.file_id).get(self.value).to_node(&root) |
254 | } | 223 | } |
255 | } | 224 | } |
256 | 225 | ||