about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2022-07-21 02:06:26 +0200
committerLukas Wirth <lukastw97@gmail.com>2022-07-21 02:06:26 +0200
commit7bd2e305d667e53314601ef04435d59b25e65235 (patch)
tree28655ac8043dc4ec8f78dbe1f059ae7efce203c3
parentc83f14a44a6f89f55cdb32bb7dc5c2277d9aafe2 (diff)
downloadrust-7bd2e305d667e53314601ef04435d59b25e65235.tar.gz
rust-7bd2e305d667e53314601ef04435d59b25e65235.zip
Simplify
-rw-r--r--crates/hir-def/src/body/lower.rs18
-rw-r--r--crates/hir-def/src/type_ref.rs7
2 files changed, 7 insertions, 18 deletions
diff --git a/crates/hir-def/src/body/lower.rs b/crates/hir-def/src/body/lower.rs
index 8cef31ed151..c3f26112278 100644
--- a/crates/hir-def/src/body/lower.rs
+++ b/crates/hir-def/src/body/lower.rs
@@ -5,7 +5,7 @@ use std::{mem, sync::Arc};
 
 use either::Either;
 use hir_expand::{
-    ast_id_map::{AstIdMap, FileAstId},
+    ast_id_map::AstIdMap,
     hygiene::Hygiene,
     name::{name, AsName, Name},
     AstId, ExpandError, HirFileId, InFile,
@@ -62,22 +62,14 @@ impl<'a> LowerCtx<'a> {
         &self.hygiene
     }
 
-    pub(crate) fn file_id(&self) -> HirFileId {
-        self.ast_id_map.as_ref().unwrap().0
-    }
-
     pub(crate) fn lower_path(&self, ast: ast::Path) -> Option<Path> {
         Path::from_src(ast, self)
     }
 
-    pub(crate) fn ast_id<N: AstNode>(
-        &self,
-        db: &dyn DefDatabase,
-        item: &N,
-    ) -> Option<FileAstId<N>> {
-        let (file_id, ast_id_map) = self.ast_id_map.as_ref()?;
-        let ast_id_map = ast_id_map.get_or_init(|| db.ast_id_map(*file_id));
-        Some(ast_id_map.ast_id(item))
+    pub(crate) fn ast_id<N: AstNode>(&self, db: &dyn DefDatabase, item: &N) -> Option<AstId<N>> {
+        let &(file_id, ref ast_id_map) = self.ast_id_map.as_ref()?;
+        let ast_id_map = ast_id_map.get_or_init(|| db.ast_id_map(file_id));
+        Some(InFile::new(file_id, ast_id_map.ast_id(item)))
     }
 }
 
diff --git a/crates/hir-def/src/type_ref.rs b/crates/hir-def/src/type_ref.rs
index dd990b0c784..59f0a8458a5 100644
--- a/crates/hir-def/src/type_ref.rs
+++ b/crates/hir-def/src/type_ref.rs
@@ -5,7 +5,7 @@ use std::fmt::Write;
 
 use hir_expand::{
     name::{AsName, Name},
-    AstId, InFile,
+    AstId,
 };
 use syntax::ast::{self, HasName};
 
@@ -236,10 +236,7 @@ impl TypeRef {
                 TypeRef::DynTrait(type_bounds_from_ast(ctx, inner.type_bound_list()))
             }
             ast::Type::MacroType(mt) => match mt.macro_call() {
-                Some(mc) => ctx
-                    .ast_id(ctx.db, &mc)
-                    .map(|mc| TypeRef::Macro(InFile::new(ctx.file_id(), mc)))
-                    .unwrap_or(TypeRef::Error),
+                Some(mc) => ctx.ast_id(ctx.db, &mc).map(TypeRef::Macro).unwrap_or(TypeRef::Error),
                 None => TypeRef::Error,
             },
         }