Skip to content

Commit 6d62012

Browse files
committed
Auto merge of #13025 - Veykril:simplify2, r=Veykril
Simplify
2 parents 5076f50 + 3f149a6 commit 6d62012

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

crates/hir-expand/src/ast_id_map.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::{
1515
use la_arena::{Arena, Idx};
1616
use profile::Count;
1717
use rustc_hash::FxHasher;
18-
use syntax::{ast, match_ast, AstNode, AstPtr, SyntaxNode, SyntaxNodePtr};
18+
use syntax::{ast, AstNode, AstPtr, SyntaxNode, SyntaxNodePtr};
1919

2020
/// `AstId` points to an AST node in a specific file.
2121
pub struct FileAstId<N: AstNode> {
@@ -92,18 +92,12 @@ impl AstIdMap {
9292
// change parent's id. This means that, say, adding a new function to a
9393
// trait does not change ids of top-level items, which helps caching.
9494
bdfs(node, |it| {
95-
match_ast! {
96-
match it {
97-
ast::Item(module_item) => {
98-
res.alloc(module_item.syntax());
99-
true
100-
},
101-
ast::BlockExpr(block) => {
102-
res.alloc(block.syntax());
103-
true
104-
},
105-
_ => false,
106-
}
95+
let kind = it.kind();
96+
if ast::Item::can_cast(kind) || ast::BlockExpr::can_cast(kind) {
97+
res.alloc(&it);
98+
true
99+
} else {
100+
false
107101
}
108102
});
109103
res.map = hashbrown::HashMap::with_capacity_and_hasher(res.arena.len(), ());
@@ -123,6 +117,7 @@ impl AstIdMap {
123117
let raw = self.erased_ast_id(item.syntax());
124118
FileAstId { raw, _ty: PhantomData }
125119
}
120+
126121
fn erased_ast_id(&self, item: &SyntaxNode) -> ErasedFileAstId {
127122
let ptr = SyntaxNodePtr::new(item);
128123
let hash = hash_ptr(&ptr);

crates/hir-expand/src/db.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,11 @@ fn censor_for_macro_input(loc: &MacroCallLoc, node: &SyntaxNode) -> FxHashSet<Sy
321321
ast::Item::cast(node.clone())?
322322
.attrs()
323323
.take(derive_attr_index as usize + 1)
324-
// FIXME
324+
// FIXME, this resolution should not be done syntactically
325+
// derive is a proper macro now, no longer builtin
326+
// But we do not have resolution at this stage, this means
327+
// we need to know about all macro calls for the given ast item here
328+
// so we require some kind of mapping...
325329
.filter(|attr| attr.simple_name().as_deref() == Some("derive"))
326330
.map(|it| it.syntax().clone())
327331
.collect()

crates/hir-expand/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ pub struct MacroDefId {
130130
pub enum MacroDefKind {
131131
Declarative(AstId<ast::Macro>),
132132
BuiltIn(BuiltinFnLikeExpander, AstId<ast::Macro>),
133-
// FIXME: maybe just Builtin and rename BuiltinFnLikeExpander to BuiltinExpander
134133
BuiltInAttr(BuiltinAttrExpander, AstId<ast::Macro>),
135134
BuiltInDerive(BuiltinDeriveExpander, AstId<ast::Macro>),
136135
BuiltInEager(EagerExpander, AstId<ast::Macro>),

crates/ide/src/hover.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ pub(crate) fn hover(
119119
}
120120

121121
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())));
122+
// prefer descending the same token kind in attribute expansions, in normal macros text
123+
// equivalency is more important
122124
let descended = if in_attr {
123125
[sema.descend_into_macros_with_kind_preference(original_token.clone())].into()
124126
} else {

0 commit comments

Comments
 (0)