about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2022-02-21 17:56:11 +0100
committerLukas Wirth <lukastw97@gmail.com>2022-02-21 17:56:11 +0100
commit0d3cd90d0883625e894d7635858fb15c16d826d2 (patch)
tree5fb7f213833733f0fc3859f18e3be530ff49ba3f
parentcef8a17ea5ac8b6d5bc70f7d9d7a248f9c940772 (diff)
downloadrust-0d3cd90d0883625e894d7635858fb15c16d826d2.tar.gz
rust-0d3cd90d0883625e894d7635858fb15c16d826d2.zip
Move fn to proc-macro conversion to name classification
-rw-r--r--crates/ide/src/references.rs15
-rw-r--r--crates/ide_db/src/defs.rs7
-rw-r--r--crates/ide_db/src/search.rs15
3 files changed, 27 insertions, 10 deletions
diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs
index 4ef9e3d4592..91c311fe94e 100644
--- a/crates/ide/src/references.rs
+++ b/crates/ide/src/references.rs
@@ -1550,14 +1550,27 @@ fn func() {}
 
                 FileId(0) 16..24
             "#]],
-        )
+        );
+        check(
+            r#"
+#[proc_macro_attribute]
+fn func$0() {}
+"#,
+            expect![[r#"
+                func Attribute FileId(0) 0..36 27..31
+
+                (no references)
+            "#]],
+        );
     }
 
+    // FIXME
     #[test]
     fn derive() {
         check(
             r#"
 //- proc_macros: derive_identity
+//- minicore: derive
 
 #[derive(proc_macros::DeriveIdentity$0)]
 struct Foo;
diff --git a/crates/ide_db/src/defs.rs b/crates/ide_db/src/defs.rs
index 172acdbc3c4..5a4cfe6e941 100644
--- a/crates/ide_db/src/defs.rs
+++ b/crates/ide_db/src/defs.rs
@@ -225,7 +225,12 @@ impl NameClass {
                     Definition::Macro(sema.to_def(&ast::Macro::MacroDef(it))?)
                 }
                 ast::Item::Const(it) => Definition::Const(sema.to_def(&it)?),
-                ast::Item::Fn(it) => Definition::Function(sema.to_def(&it)?),
+                ast::Item::Fn(it) => {
+                    let def = sema.to_def(&it)?;
+                    def.as_proc_macro(sema.db)
+                        .map(Definition::Macro)
+                        .unwrap_or(Definition::Function(def))
+                }
                 ast::Item::Module(it) => Definition::Module(sema.to_def(&it)?),
                 ast::Item::Static(it) => Definition::Static(sema.to_def(&it)?),
                 ast::Item::Trait(it) => Definition::Trait(sema.to_def(&it)?),
diff --git a/crates/ide_db/src/search.rs b/crates/ide_db/src/search.rs
index b7db96e9341..7ea2bc63f25 100644
--- a/crates/ide_db/src/search.rs
+++ b/crates/ide_db/src/search.rs
@@ -309,14 +309,13 @@ impl Definition {
     }
 
     pub fn usages<'a>(self, sema: &'a Semantics<RootDatabase>) -> FindUsages<'a> {
-        let def = match self {
-            def @ Definition::Function(f) => {
-                // search for proc-macro usages if this function describes a proc macro
-                f.as_proc_macro(sema.db).map(Definition::Macro).unwrap_or(def)
-            }
-            def => def,
-        };
-        FindUsages { def, sema, scope: None, include_self_kw_refs: None, search_self_mod: false }
+        FindUsages {
+            def: self,
+            sema,
+            scope: None,
+            include_self_kw_refs: None,
+            search_self_mod: false,
+        }
     }
 }