From 3d39e77003c5fe5ed9f8f3ac00a170f3804f8337 Mon Sep 17 00:00:00 2001 From: cynecx Date: Sun, 18 Apr 2021 18:35:45 +0200 Subject: hir_def: various cleanups --- crates/hir_def/src/data.rs | 8 +++----- crates/hir_def/src/item_tree.rs | 8 ++++---- crates/hir_def/src/type_ref.rs | 4 ++-- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/crates/hir_def/src/data.rs b/crates/hir_def/src/data.rs index 8732b1e3e..135a6698e 100644 --- a/crates/hir_def/src/data.rs +++ b/crates/hir_def/src/data.rs @@ -123,11 +123,10 @@ impl TypeAliasData { let loc = typ.lookup(db); let item_tree = loc.id.item_tree(db); let typ = &item_tree[loc.id.value]; - let type_ref = typ.type_ref.clone(); Arc::new(TypeAliasData { name: typ.name.clone(), - type_ref: type_ref, + type_ref: typ.type_ref.clone(), visibility: item_tree[typ.visibility].clone(), is_extern: typ.is_extern, bounds: typ.bounds.to_vec(), @@ -203,13 +202,12 @@ impl ImplData { let item_tree = impl_loc.id.item_tree(db); let impl_def = &item_tree[impl_loc.id.value]; let target_trait = impl_def.target_trait.clone(); + let self_ty = impl_def.self_ty.clone(); let is_negative = impl_def.is_negative; let module_id = impl_loc.container; let container = AssocContainerId::ImplId(id); - let file_id = impl_loc.id.file_id(); - let self_ty = impl_def.self_ty.clone(); + let mut expander = Expander::new(db, impl_loc.id.file_id(), module_id); - let mut expander = Expander::new(db, file_id, module_id); let items = collect_items( db, module_id, diff --git a/crates/hir_def/src/item_tree.rs b/crates/hir_def/src/item_tree.rs index fed285505..16a94a058 100644 --- a/crates/hir_def/src/item_tree.rs +++ b/crates/hir_def/src/item_tree.rs @@ -104,10 +104,10 @@ impl ItemTree { // items and expanded during block DefMap computation return Default::default(); }, - ast::Type(_ty) => { - // FIXME: This occurs because macros in type position are treated as inner - // items and expanded during block DefMap computation - return Default::default(); + ast::Type(ty) => { + // Types can contain inner items. We return an empty item tree in this case, but + // still need to collect inner items. + ctx.lower_inner_items(ty.syntax()) }, ast::Expr(e) => { // Macros can expand to expressions. We return an empty item tree in this case, but diff --git a/crates/hir_def/src/type_ref.rs b/crates/hir_def/src/type_ref.rs index cf8a584ab..e18712d24 100644 --- a/crates/hir_def/src/type_ref.rs +++ b/crates/hir_def/src/type_ref.rs @@ -1,7 +1,7 @@ //! HIR for references to types. Paths in these are not yet resolved. They can //! be directly created from an ast::TypeRef, without further queries. -use hir_expand::{ast_id_map::FileAstId, name::Name, ExpandResult, InFile}; +use hir_expand::{name::Name, AstId, ExpandResult, InFile}; use syntax::ast; use crate::{ @@ -91,7 +91,7 @@ pub enum TypeRef { // For ImplTrait(Vec), DynTrait(Vec), - Macro(InFile>), + Macro(AstId), Error, } -- cgit v1.2.3