Skip to content

Commit 7bd2e30

Browse files
committed
Simplify
1 parent c83f14a commit 7bd2e30

File tree

2 files changed

+7
-18
lines changed

2 files changed

+7
-18
lines changed

crates/hir-def/src/body/lower.rs

+5-13
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::{mem, sync::Arc};
55

66
use either::Either;
77
use hir_expand::{
8-
ast_id_map::{AstIdMap, FileAstId},
8+
ast_id_map::AstIdMap,
99
hygiene::Hygiene,
1010
name::{name, AsName, Name},
1111
AstId, ExpandError, HirFileId, InFile,
@@ -62,22 +62,14 @@ impl<'a> LowerCtx<'a> {
6262
&self.hygiene
6363
}
6464

65-
pub(crate) fn file_id(&self) -> HirFileId {
66-
self.ast_id_map.as_ref().unwrap().0
67-
}
68-
6965
pub(crate) fn lower_path(&self, ast: ast::Path) -> Option<Path> {
7066
Path::from_src(ast, self)
7167
}
7268

73-
pub(crate) fn ast_id<N: AstNode>(
74-
&self,
75-
db: &dyn DefDatabase,
76-
item: &N,
77-
) -> Option<FileAstId<N>> {
78-
let (file_id, ast_id_map) = self.ast_id_map.as_ref()?;
79-
let ast_id_map = ast_id_map.get_or_init(|| db.ast_id_map(*file_id));
80-
Some(ast_id_map.ast_id(item))
69+
pub(crate) fn ast_id<N: AstNode>(&self, db: &dyn DefDatabase, item: &N) -> Option<AstId<N>> {
70+
let &(file_id, ref ast_id_map) = self.ast_id_map.as_ref()?;
71+
let ast_id_map = ast_id_map.get_or_init(|| db.ast_id_map(file_id));
72+
Some(InFile::new(file_id, ast_id_map.ast_id(item)))
8173
}
8274
}
8375

crates/hir-def/src/type_ref.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::fmt::Write;
55

66
use hir_expand::{
77
name::{AsName, Name},
8-
AstId, InFile,
8+
AstId,
99
};
1010
use syntax::ast::{self, HasName};
1111

@@ -236,10 +236,7 @@ impl TypeRef {
236236
TypeRef::DynTrait(type_bounds_from_ast(ctx, inner.type_bound_list()))
237237
}
238238
ast::Type::MacroType(mt) => match mt.macro_call() {
239-
Some(mc) => ctx
240-
.ast_id(ctx.db, &mc)
241-
.map(|mc| TypeRef::Macro(InFile::new(ctx.file_id(), mc)))
242-
.unwrap_or(TypeRef::Error),
239+
Some(mc) => ctx.ast_id(ctx.db, &mc).map(TypeRef::Macro).unwrap_or(TypeRef::Error),
243240
None => TypeRef::Error,
244241
},
245242
}

0 commit comments

Comments
 (0)