Skip to content

Commit 2c7f6b5

Browse files
bors[bot]matklad
andauthored
Merge #2441
2441: Use InFile for AstId r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 1603052 + e823c57 commit 2c7f6b5

File tree

6 files changed

+16
-47
lines changed

6 files changed

+16
-47
lines changed

crates/ra_hir/src/code_model/src.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl HasSource for TypeAlias {
105105
impl HasSource for MacroDef {
106106
type Ast = ast::MacroCall;
107107
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) }
109109
}
110110
}
111111
impl HasSource for ImplBlock {

crates/ra_hir_def/src/attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ where
157157
N: ast::AttrsOwner,
158158
D: DefDatabase,
159159
{
160-
let src = InFile::new(src.file_id(), src.to_node(db));
160+
let src = InFile::new(src.file_id, src.to_node(db));
161161
Attrs::from_attrs_owner(db, src.as_ref().map(|it| it as &dyn AttrsOwner))
162162
}
163163

crates/ra_hir_def/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ pub trait AstItemDef<N: AstNode>: salsa::InternKey + Clone {
108108
fn source(self, db: &(impl AstDatabase + InternDatabase)) -> InFile<N> {
109109
let loc = self.lookup_intern(db);
110110
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 }
112112
}
113113
fn module(self, db: &impl InternDatabase) -> ModuleId {
114114
let loc = self.lookup_intern(db);
@@ -525,7 +525,7 @@ impl HasSource for FunctionLoc {
525525

526526
fn source(&self, db: &impl db::DefDatabase) -> InFile<ast::FnDef> {
527527
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)
529529
}
530530
}
531531

@@ -534,7 +534,7 @@ impl HasSource for TypeAliasLoc {
534534

535535
fn source(&self, db: &impl db::DefDatabase) -> InFile<ast::TypeAliasDef> {
536536
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)
538538
}
539539
}
540540

@@ -543,7 +543,7 @@ impl HasSource for ConstLoc {
543543

544544
fn source(&self, db: &impl db::DefDatabase) -> InFile<ast::ConstDef> {
545545
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)
547547
}
548548
}
549549

@@ -552,7 +552,7 @@ impl HasSource for StaticLoc {
552552

553553
fn source(&self, db: &impl db::DefDatabase) -> InFile<ast::StaticDef> {
554554
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)
556556
}
557557
}
558558

crates/ra_hir_def/src/nameres.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,15 +267,15 @@ impl ModuleData {
267267
return InFile::new(file_id.into(), Either::A(sf));
268268
}
269269
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)))
271271
}
272272

273273
/// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`.
274274
/// `None` for the crate root.
275275
pub fn declaration_source(&self, db: &impl DefDatabase) -> Option<InFile<ast::Module>> {
276276
let decl = self.declaration?;
277277
let value = decl.to_node(db);
278-
Some(InFile { file_id: decl.file_id(), value })
278+
Some(InFile { file_id: decl.file_id, value })
279279
}
280280
}
281281

@@ -309,7 +309,7 @@ mod diagnostics {
309309
}
310310
let decl = declaration.to_node(db);
311311
sink.push(UnresolvedModule {
312-
file: declaration.file_id(),
312+
file: declaration.file_id,
313313
decl: AstPtr::new(&decl),
314314
candidate: candidate.clone(),
315315
})

crates/ra_hir_def/src/nameres/tests/mod_resolution.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -668,15 +668,15 @@ fn unresolved_module_diagnostics() {
668668
module: LocalModuleId(
669669
0,
670670
),
671-
declaration: AstId {
671+
declaration: InFile {
672672
file_id: HirFileId(
673673
FileId(
674674
FileId(
675675
0,
676676
),
677677
),
678678
),
679-
file_ast_id: FileAstId {
679+
value: FileAstId {
680680
raw: ErasedFileAstId(
681681
1,
682682
),

crates/ra_hir_expand/src/lib.rs

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub mod diagnostics;
1313
pub mod builtin_macro;
1414
pub mod quote;
1515

16-
use std::hash::{Hash, Hasher};
16+
use std::hash::Hash;
1717
use std::sync::Arc;
1818

1919
use ra_db::{salsa, CrateId, FileId};
@@ -70,7 +70,7 @@ impl HirFileId {
7070
HirFileIdRepr::FileId(file_id) => file_id,
7171
HirFileIdRepr::MacroFile(macro_file) => {
7272
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)
7474
}
7575
}
7676
}
@@ -214,43 +214,12 @@ impl ExpansionInfo {
214214
///
215215
/// It is stable across reparses, and can be used as salsa key/value.
216216
// FIXME: isn't this just a `Source<FileAstId<N>>` ?
217-
#[derive(Debug)]
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-
}
217+
pub type AstId<N> = InFile<FileAstId<N>>;
241218

242219
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-
251220
pub fn to_node(&self, db: &dyn db::AstDatabase) -> N {
252221
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)
254223
}
255224
}
256225

0 commit comments

Comments
 (0)