]> git.lizzy.rs Git - rust.git/commitdiff
Don't classify attributes on macro-calls are the macro itself
authorLukas Wirth <lukastw97@gmail.com>
Wed, 9 Jun 2021 22:25:36 +0000 (00:25 +0200)
committerLukas Wirth <lukastw97@gmail.com>
Wed, 9 Jun 2021 22:26:15 +0000 (00:26 +0200)
crates/ide/src/references.rs
crates/ide_db/src/defs.rs

index ae492a264f7aa6898c7f98e503c467a7ed5c1f79..f8b64a669048b984cd95f218d34fbff1964854c3 100644 (file)
@@ -1380,4 +1380,24 @@ macro_rules! foo$0 {
             "#]],
         );
     }
+
+    #[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
+            "#]],
+        );
+    }
 }
index 1dcccbb8be7cb436e06fe5e6fa2fb3c79159ec30..1b69d72f91909d714fe7bc5d3e291615e95ef243 100644 (file)
@@ -357,9 +357,9 @@ pub fn classify(
             }
         }
 
-        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) {
@@ -367,9 +367,7 @@ pub fn classify(
                     }
                 }
             }
-        }
 
-        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 {