about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2022-08-15 16:16:59 +0200
committerLukas Wirth <lukastw97@gmail.com>2022-08-15 16:40:10 +0200
commit3f149a63d226cbdedd466d872677da765ada9df8 (patch)
treef8fc106e6868cbd50623afbd834639abdfd37a0e
parentf982c7616196b433bd65a1df1d07ee0d249701c0 (diff)
downloadrust-3f149a63d226cbdedd466d872677da765ada9df8.tar.gz
rust-3f149a63d226cbdedd466d872677da765ada9df8.zip
Simplify
-rw-r--r--crates/hir-expand/src/ast_id_map.rs21
-rw-r--r--crates/hir-expand/src/db.rs6
-rw-r--r--crates/hir-expand/src/lib.rs1
-rw-r--r--crates/ide/src/hover.rs2
4 files changed, 15 insertions, 15 deletions
diff --git a/crates/hir-expand/src/ast_id_map.rs b/crates/hir-expand/src/ast_id_map.rs
index c1ddef03ba3..11c0a6764e9 100644
--- a/crates/hir-expand/src/ast_id_map.rs
+++ b/crates/hir-expand/src/ast_id_map.rs
@@ -15,7 +15,7 @@ use std::{
 use la_arena::{Arena, Idx};
 use profile::Count;
 use rustc_hash::FxHasher;
-use syntax::{ast, match_ast, AstNode, AstPtr, SyntaxNode, SyntaxNodePtr};
+use syntax::{ast, AstNode, AstPtr, SyntaxNode, SyntaxNodePtr};
 
 /// `AstId` points to an AST node in a specific file.
 pub struct FileAstId<N: AstNode> {
@@ -92,18 +92,12 @@ impl AstIdMap {
         // change parent's id. This means that, say, adding a new function to a
         // trait does not change ids of top-level items, which helps caching.
         bdfs(node, |it| {
-            match_ast! {
-                match it {
-                    ast::Item(module_item) => {
-                        res.alloc(module_item.syntax());
-                        true
-                    },
-                    ast::BlockExpr(block) => {
-                        res.alloc(block.syntax());
-                        true
-                    },
-                    _ => false,
-                }
+            let kind = it.kind();
+            if ast::Item::can_cast(kind) || ast::BlockExpr::can_cast(kind) {
+                res.alloc(&it);
+                true
+            } else {
+                false
             }
         });
         res.map = hashbrown::HashMap::with_capacity_and_hasher(res.arena.len(), ());
@@ -123,6 +117,7 @@ impl AstIdMap {
         let raw = self.erased_ast_id(item.syntax());
         FileAstId { raw, _ty: PhantomData }
     }
+
     fn erased_ast_id(&self, item: &SyntaxNode) -> ErasedFileAstId {
         let ptr = SyntaxNodePtr::new(item);
         let hash = hash_ptr(&ptr);
diff --git a/crates/hir-expand/src/db.rs b/crates/hir-expand/src/db.rs
index bd60c3d2686..bc97ee15c7d 100644
--- a/crates/hir-expand/src/db.rs
+++ b/crates/hir-expand/src/db.rs
@@ -321,7 +321,11 @@ fn censor_for_macro_input(loc: &MacroCallLoc, node: &SyntaxNode) -> FxHashSet<Sy
                 ast::Item::cast(node.clone())?
                     .attrs()
                     .take(derive_attr_index as usize + 1)
-                    // FIXME
+                    // FIXME, this resolution should not be done syntactically
+                    // derive is a proper macro now, no longer builtin
+                    // But we do not have resolution at this stage, this means
+                    // we need to know about all macro calls for the given ast item here
+                    // so we require some kind of mapping...
                     .filter(|attr| attr.simple_name().as_deref() == Some("derive"))
                     .map(|it| it.syntax().clone())
                     .collect()
diff --git a/crates/hir-expand/src/lib.rs b/crates/hir-expand/src/lib.rs
index 252293090bb..f6b97fd5405 100644
--- a/crates/hir-expand/src/lib.rs
+++ b/crates/hir-expand/src/lib.rs
@@ -130,7 +130,6 @@ pub struct MacroDefId {
 pub enum MacroDefKind {
     Declarative(AstId<ast::Macro>),
     BuiltIn(BuiltinFnLikeExpander, AstId<ast::Macro>),
-    // FIXME: maybe just Builtin and rename BuiltinFnLikeExpander to BuiltinExpander
     BuiltInAttr(BuiltinAttrExpander, AstId<ast::Macro>),
     BuiltInDerive(BuiltinDeriveExpander, AstId<ast::Macro>),
     BuiltInEager(EagerExpander, AstId<ast::Macro>),
diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs
index 3ada181f1ed..fa2c6f09ab4 100644
--- a/crates/ide/src/hover.rs
+++ b/crates/ide/src/hover.rs
@@ -119,6 +119,8 @@ pub(crate) fn hover(
     }
 
     let in_attr = matches!(original_token.parent().and_then(ast::TokenTree::cast), Some(tt) if tt.syntax().ancestors().any(|it| ast::Meta::can_cast(it.kind())));
+    // prefer descending the same token kind in attribute expansions, in normal macros text
+    // equivalency is more important
     let descended = if in_attr {
         [sema.descend_into_macros_with_kind_preference(original_token.clone())].into()
     } else {