about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-08-03 16:11:08 +0000
committerbors <bors@rust-lang.org>2022-08-03 16:11:08 +0000
commit2bc9a2d9e0f039a3464f67f941bde5cd9d192052 (patch)
tree2a6869a5227c26bbb09ebc75be8663a1e172419e
parenta02b042ae75c368e4eaceb899ac3f4bcc97191ca (diff)
parenta8a6c160be157ee7fe130d2c99521a2f76d3b4be (diff)
downloadrust-2bc9a2d9e0f039a3464f67f941bde5cd9d192052.tar.gz
rust-2bc9a2d9e0f039a3464f67f941bde5cd9d192052.zip
Auto merge of #12933 - Veykril:proc-ignored, r=Veykril
Use an empty expander for ignored non-attribute proc-macros

Identity is the wrong behaviour for anything that's not an attribute here
-rw-r--r--crates/rust-analyzer/src/reload.rs26
1 files changed, 22 insertions, 4 deletions
diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs
index eaab275bc68..9a9a9dd4d84 100644
--- a/crates/rust-analyzer/src/reload.rs
+++ b/crates/rust-analyzer/src/reload.rs
@@ -621,7 +621,10 @@ pub(crate) fn load_proc_macro(
         };
         let expander: Arc<dyn ProcMacroExpander> =
             if dummy_replace.iter().any(|replace| &**replace == name) {
-                Arc::new(DummyExpander)
+                match kind {
+                    ProcMacroKind::Attr => Arc::new(IdentityExpander),
+                    _ => Arc::new(EmptyExpander),
+                }
             } else {
                 Arc::new(Expander(expander))
             };
@@ -647,11 +650,11 @@ pub(crate) fn load_proc_macro(
         }
     }
 
-    /// Dummy identity expander, used for proc-macros that are deliberately ignored by the user.
+    /// Dummy identity expander, used for attribute proc-macros that are deliberately ignored by the user.
     #[derive(Debug)]
-    struct DummyExpander;
+    struct IdentityExpander;
 
-    impl ProcMacroExpander for DummyExpander {
+    impl ProcMacroExpander for IdentityExpander {
         fn expand(
             &self,
             subtree: &tt::Subtree,
@@ -661,6 +664,21 @@ pub(crate) fn load_proc_macro(
             Ok(subtree.clone())
         }
     }
+
+    /// Empty expander, used for proc-macros that are deliberately ignored by the user.
+    #[derive(Debug)]
+    struct EmptyExpander;
+
+    impl ProcMacroExpander for EmptyExpander {
+        fn expand(
+            &self,
+            _: &tt::Subtree,
+            _: Option<&tt::Subtree>,
+            _: &Env,
+        ) -> Result<tt::Subtree, ProcMacroExpansionError> {
+            Ok(tt::Subtree::default())
+        }
+    }
 }
 
 pub(crate) fn should_refresh_for_change(path: &AbsPath, change_kind: ChangeKind) -> bool {