Skip to content

Commit

Permalink
Auto merge of rust-lang#17462 - Veykril:sema-attr-macro-res, r=Veykril
Browse files Browse the repository at this point in the history
fix: Fix IDE features breaking in some attr macros

Fixes rust-lang/rust-analyzer#17453, Fixes rust-lang/rust-analyzer#17458
  • Loading branch information
bors committed Jun 20, 2024
2 parents 1d0d439 + 16a28ca commit 48b6f28
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/tools/rust-analyzer/crates/hir-expand/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,8 +710,8 @@ impl ExpansionInfo {
self.expanded.clone()
}

pub fn call_node(&self) -> InFile<Option<SyntaxNode>> {
self.arg.with_value(self.arg.value.as_ref().and_then(SyntaxNode::parent))
pub fn arg(&self) -> InFile<Option<&SyntaxNode>> {
self.arg.as_ref().map(|it| it.as_ref())
}

pub fn call_file(&self) -> HirFileId {
Expand Down
6 changes: 3 additions & 3 deletions src/tools/rust-analyzer/crates/hir/src/semantics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ impl<'db> SemanticsImpl<'db> {
let exp_info = macro_file.expansion_info(self.db.upcast());

let InMacroFile { file_id, value } = exp_info.expanded();
if let InFile { file_id, value: Some(value) } = exp_info.call_node() {
if let InFile { file_id, value: Some(value) } = exp_info.arg() {
self.cache(value.ancestors().last().unwrap(), file_id);
}
self.cache(value, file_id.into());
Expand All @@ -786,7 +786,7 @@ impl<'db> SemanticsImpl<'db> {
// FIXME: uncached parse
// Create the source analyzer for the macro call scope
let Some(sa) = expansion_info
.call_node()
.arg()
.value
.and_then(|it| self.analyze_no_infer(&it.ancestors().last().unwrap()))
else {
Expand Down Expand Up @@ -1145,7 +1145,7 @@ impl<'db> SemanticsImpl<'db> {
.expansion_info_cache
.entry(macro_file)
.or_insert_with(|| macro_file.expansion_info(self.db.upcast()));
expansion_info.call_node().transpose()
expansion_info.arg().map(|node| node?.parent()).transpose()
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ impl SourceToDefCtx<'_, '_> {
.entry(macro_file)
.or_insert_with(|| macro_file.expansion_info(this.db.upcast()));

expansion_info.call_node().map(|node| node?.parent()).transpose()
expansion_info.arg().map(|node| node?.parent()).transpose()
}
};
let mut node = node.cloned();
Expand Down

0 comments on commit 48b6f28

Please sign in to comment.