Skip to content

Commit

Permalink
Merge #9196
Browse files Browse the repository at this point in the history
9196: fix: Don't classify attributes on macro-calls are the macro itself r=Veykril a=Veykril

Fixes #9184
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
  • Loading branch information
bors[bot] and Veykril authored Jun 9, 2021
2 parents c6133fe + 26c869d commit 660a896
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
20 changes: 20 additions & 0 deletions crates/ide/src/references.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1380,4 +1380,24 @@ lib::foo!();
"#]],
);
}

#[test]
fn macro_doesnt_reference_attribute_on_call() {
check(
r#"
macro_rules! m {
() => {};
}
#[proc_macro_test::attr_noop]
m$0!();
"#,
expect![[r#"
m Macro FileId(0) 0..32 13..14
FileId(0) 64..65
"#]],
);
}
}
8 changes: 3 additions & 5 deletions crates/ide_db/src/defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,19 +357,17 @@ impl NameRefClass {
}
}

if let Some(macro_call) = parent.ancestors().find_map(ast::MacroCall::cast) {
if let Some(path) = macro_call.path() {
if path.qualifier().is_none() {
if let Some(path) = name_ref.syntax().ancestors().find_map(ast::Path::cast) {
if path.qualifier().is_none() {
if let Some(macro_call) = path.syntax().parent().and_then(ast::MacroCall::cast) {
// Only use this to resolve single-segment macro calls like `foo!()`. Multi-segment
// paths are handled below (allowing `log$0::info!` to resolve to the log crate).
if let Some(macro_def) = sema.resolve_macro_call(&macro_call) {
return Some(NameRefClass::Definition(Definition::Macro(macro_def)));
}
}
}
}

if let Some(path) = name_ref.syntax().ancestors().find_map(ast::Path::cast) {
if let Some(resolved) = sema.resolve_path(&path) {
if path.syntax().parent().and_then(ast::Attr::cast).is_some() {
if let PathResolution::Def(ModuleDef::Function(func)) = resolved {
Expand Down

0 comments on commit 660a896

Please sign in to comment.