Skip to content

Commit 2bc9a2d

Browse files
committed
Auto merge of rust-lang#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
2 parents a02b042 + a8a6c16 commit 2bc9a2d

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

crates/rust-analyzer/src/reload.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,10 @@ pub(crate) fn load_proc_macro(
621621
};
622622
let expander: Arc<dyn ProcMacroExpander> =
623623
if dummy_replace.iter().any(|replace| &**replace == name) {
624-
Arc::new(DummyExpander)
624+
match kind {
625+
ProcMacroKind::Attr => Arc::new(IdentityExpander),
626+
_ => Arc::new(EmptyExpander),
627+
}
625628
} else {
626629
Arc::new(Expander(expander))
627630
};
@@ -647,11 +650,11 @@ pub(crate) fn load_proc_macro(
647650
}
648651
}
649652

650-
/// Dummy identity expander, used for proc-macros that are deliberately ignored by the user.
653+
/// Dummy identity expander, used for attribute proc-macros that are deliberately ignored by the user.
651654
#[derive(Debug)]
652-
struct DummyExpander;
655+
struct IdentityExpander;
653656

654-
impl ProcMacroExpander for DummyExpander {
657+
impl ProcMacroExpander for IdentityExpander {
655658
fn expand(
656659
&self,
657660
subtree: &tt::Subtree,
@@ -661,6 +664,21 @@ pub(crate) fn load_proc_macro(
661664
Ok(subtree.clone())
662665
}
663666
}
667+
668+
/// Empty expander, used for proc-macros that are deliberately ignored by the user.
669+
#[derive(Debug)]
670+
struct EmptyExpander;
671+
672+
impl ProcMacroExpander for EmptyExpander {
673+
fn expand(
674+
&self,
675+
_: &tt::Subtree,
676+
_: Option<&tt::Subtree>,
677+
_: &Env,
678+
) -> Result<tt::Subtree, ProcMacroExpansionError> {
679+
Ok(tt::Subtree::default())
680+
}
681+
}
664682
}
665683

666684
pub(crate) fn should_refresh_for_change(path: &AbsPath, change_kind: ChangeKind) -> bool {

0 commit comments

Comments
 (0)