mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 07:04:49 +00:00
Use an empty expander for ignored non-attribute proc-macros
This commit is contained in:
parent
ec3586eab9
commit
a8a6c160be
1 changed files with 22 additions and 4 deletions
|
@ -621,7 +621,10 @@ pub(crate) fn load_proc_macro(
|
||||||
};
|
};
|
||||||
let expander: Arc<dyn ProcMacroExpander> =
|
let expander: Arc<dyn ProcMacroExpander> =
|
||||||
if dummy_replace.iter().any(|replace| &**replace == name) {
|
if dummy_replace.iter().any(|replace| &**replace == name) {
|
||||||
Arc::new(DummyExpander)
|
match kind {
|
||||||
|
ProcMacroKind::Attr => Arc::new(IdentityExpander),
|
||||||
|
_ => Arc::new(EmptyExpander),
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Arc::new(Expander(expander))
|
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)]
|
#[derive(Debug)]
|
||||||
struct DummyExpander;
|
struct IdentityExpander;
|
||||||
|
|
||||||
impl ProcMacroExpander for DummyExpander {
|
impl ProcMacroExpander for IdentityExpander {
|
||||||
fn expand(
|
fn expand(
|
||||||
&self,
|
&self,
|
||||||
subtree: &tt::Subtree,
|
subtree: &tt::Subtree,
|
||||||
|
@ -661,6 +664,21 @@ pub(crate) fn load_proc_macro(
|
||||||
Ok(subtree.clone())
|
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 {
|
pub(crate) fn should_refresh_for_change(path: &AbsPath, change_kind: ChangeKind) -> bool {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue