Do not replace items annotated with builtin attrs with the attr input

This commit is contained in:
Lukas Wirth 2021-08-18 15:35:14 +02:00
parent 8dd3a71730
commit 351cec0cb4
4 changed files with 25 additions and 18 deletions

View file

@ -17,11 +17,12 @@ macro_rules! register_builtin {
db: &dyn AstDatabase,
id: MacroCallId,
tt: &tt::Subtree,
item: &tt::Subtree,
) -> Result<tt::Subtree, mbe::ExpandError> {
let expander = match *self {
$( BuiltinAttrExpander::$variant => $expand, )*
};
expander(db, id, tt)
expander(db, id, tt, item)
}
fn find_by_name(name: &name::Name) -> Option<Self> {
@ -61,7 +62,8 @@ pub fn find_builtin_attr(
fn dummy_attr_expand(
_db: &dyn AstDatabase,
_id: MacroCallId,
tt: &tt::Subtree,
_tt: &tt::Subtree,
item: &tt::Subtree,
) -> Result<tt::Subtree, mbe::ExpandError> {
Ok(tt.clone())
Ok(item.clone())
}

View file

@ -54,7 +54,18 @@ impl TokenExpander {
TokenExpander::MacroDef { mac, .. } => mac.expand(tt),
TokenExpander::Builtin(it) => it.expand(db, id, tt),
// FIXME switch these to ExpandResult as well
TokenExpander::BuiltinAttr(it) => it.expand(db, id, tt).into(),
TokenExpander::BuiltinAttr(it) => {
let macro_arg = match db.macro_arg(id) {
Some(it) => it,
None => {
return mbe::ExpandResult::only_err(
mbe::ExpandError::Other("No item argument for attribute".to_string())
.into(),
);
}
};
it.expand(db, id, tt, &macro_arg.0).into()
}
TokenExpander::BuiltinDerive(it) => it.expand(db, id, tt).into(),
TokenExpander::ProcMacro(_) => {
// We store the result in salsa db to prevent non-deterministic behavior in