]> git.lizzy.rs Git - rust.git/commitdiff
hir_def: various cleanups
authorcynecx <me@cynecx.net>
Sun, 18 Apr 2021 16:35:45 +0000 (18:35 +0200)
committercynecx <me@cynecx.net>
Sun, 18 Apr 2021 16:35:45 +0000 (18:35 +0200)
crates/hir_def/src/data.rs
crates/hir_def/src/item_tree.rs
crates/hir_def/src/type_ref.rs

index 8732b1e3ed6de4145988cbec70caf827f1a452aa..135a6698e15273411ad785be078c6bc50c2eb67f 100644 (file)
@@ -123,11 +123,10 @@ pub(crate) fn type_alias_data_query(
         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 @@ pub(crate) fn impl_data_query(db: &dyn DefDatabase, id: ImplId) -> Arc<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,
index fed28550521e8729b397b69d3db14103628c3e26..16a94a058844706cb80f76f2ed2e857674fa91ff 100644 (file)
@@ -104,10 +104,10 @@ pub(crate) fn file_item_tree_query(db: &dyn DefDatabase, file_id: HirFileId) ->
                     // 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
index cf8a584ab67732bc14f873f12ca3268b5670984a..e18712d2460ff3ba0746282315b6abe64690f336 100644 (file)
@@ -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<TypeBound>),
     DynTrait(Vec<TypeBound>),
-    Macro(InFile<FileAstId<ast::MacroCall>>),
+    Macro(AstId<ast::MacroCall>),
     Error,
 }