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
This commit is contained in:
bors 2022-08-03 16:11:08 +00:00
commit 2bc9a2d9e0

View File

@ -621,7 +621,10 @@ fn expander_to_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 @@ fn expand(
}
}
/// 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 @@ fn expand(
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 {