Rust: separate attribute macro and macro call expansions

This commit is contained in:
Paolo Tranquilli
2025-04-29 16:18:40 +02:00
parent 2d32c366d8
commit a7a887c828
90 changed files with 442 additions and 244 deletions

View File

@@ -1,2 +1,2 @@
mod.rs 4bcb9def847469aae9d8649461546b7c21ec97cf6e63d3cf394e339915ce65d7 4bcb9def847469aae9d8649461546b7c21ec97cf6e63d3cf394e339915ce65d7
top.rs af7f3cf5d0941e7dffd6fa4ce75ac432f433a5367a408fb944176dc1a932883b af7f3cf5d0941e7dffd6fa4ce75ac432f433a5367a408fb944176dc1a932883b
top.rs 7fa95af0d85ffc251cfcd543129baa8cb0dde9df310194f3aff1868dd66417f4 7fa95af0d85ffc251cfcd543129baa8cb0dde9df310194f3aff1868dd66417f4

View File

@@ -5819,8 +5819,8 @@ pub struct Item {
}
impl Item {
pub fn emit_expanded(id: trap::Label<Self>, value: trap::Label<AstNode>, out: &mut trap::Writer) {
out.add_tuple("item_expandeds", vec![id.into(), value.into()]);
pub fn emit_attribute_macro_expansion(id: trap::Label<Self>, value: trap::Label<MacroItems>, out: &mut trap::Writer) {
out.add_tuple("item_attribute_macro_expansions", vec![id.into(), value.into()]);
}
}
@@ -9771,6 +9771,12 @@ impl trap::TrapEntry for MacroCall {
}
}
impl MacroCall {
pub fn emit_macro_call_expansion(id: trap::Label<Self>, value: trap::Label<AstNode>, out: &mut trap::Writer) {
out.add_tuple("macro_call_macro_call_expansions", vec![id.into(), value.into()]);
}
}
impl trap::TrapClass for MacroCall {
fn class_name() -> &'static str { "MacroCall" }
}

View File

@@ -328,7 +328,11 @@ impl<'a> Translator<'a> {
let expand_to = ra_ap_hir_expand::ExpandTo::from_call_site(mcall);
let kind = expanded.kind();
if let Some(value) = self.emit_expanded_as(expand_to, expanded) {
generated::Item::emit_expanded(label.into(), value, &mut self.trap.writer);
generated::MacroCall::emit_macro_call_expansion(
label,
value,
&mut self.trap.writer,
);
} else {
let range = self.text_range_for_node(mcall);
self.emit_parse_error(mcall, &SyntaxError::new(
@@ -655,8 +659,9 @@ impl<'a> Translator<'a> {
} = semantics.expand_attr_macro(node)?;
// TODO emit err?
self.emit_macro_expansion_parse_errors(node, &expanded);
let expanded = self.emit_expanded_as(ExpandTo::Items, expanded)?;
generated::Item::emit_expanded(label, expanded, &mut self.trap.writer);
let macro_items = ast::MacroItems::cast(expanded)?;
let expanded = self.emit_macro_items(&macro_items)?;
generated::Item::emit_attribute_macro_expansion(label, expanded, &mut self.trap.writer);
Some(())
})();
}