aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-11-28 13:04:52 +0000
committerGitHub <[email protected]>2019-11-28 13:04:52 +0000
commit2c7f6b573e9b6133cc147a529dd2a23119bb4ae5 (patch)
tree903f9f2ded4a197c2736b4459cda89c6639dd277 /crates
parent16030528b53d38e24c1e5733aa4cc46058d0bbd1 (diff)
parente823c578c9f6886fe9db9767cb81e75a6c56bf15 (diff)
Merge #2441
2441: Use InFile for AstId r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/code_model/src.rs2
-rw-r--r--crates/ra_hir_def/src/attr.rs2
-rw-r--r--crates/ra_hir_def/src/lib.rs10
-rw-r--r--crates/ra_hir_def/src/nameres.rs6
-rw-r--r--crates/ra_hir_def/src/nameres/tests/mod_resolution.rs4
-rw-r--r--crates/ra_hir_expand/src/lib.rs39
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 {
105impl HasSource for MacroDef { 105impl 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}
111impl HasSource for ImplBlock { 111impl 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;
13pub mod builtin_macro; 13pub mod builtin_macro;
14pub mod quote; 14pub mod quote;
15 15
16use std::hash::{Hash, Hasher}; 16use std::hash::Hash;
17use std::sync::Arc; 17use std::sync::Arc;
18 18
19use ra_db::{salsa, CrateId, FileId}; 19use 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)] 217pub type AstId<N> = InFile<FileAstId<N>>;
218pub struct AstId<N: AstNode> {
219 file_id: HirFileId,
220 file_ast_id: FileAstId<N>,
221}
222
223impl<N: AstNode> Clone for AstId<N> {
224 fn clone(&self) -> AstId<N> {
225 *self
226 }
227}
228impl<N: AstNode> Copy for AstId<N> {}
229
230impl<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}
235impl<N: AstNode> Eq for AstId<N> {}
236impl<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
242impl<N: AstNode> AstId<N> { 219impl<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