Skip to content

Commit

Permalink
chore(macros): fix expansion spans
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Dec 20, 2024
1 parent 13d4e71 commit d6a5aec
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
12 changes: 4 additions & 8 deletions crates/ast/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,8 @@ declare_visitors! {
self.visit_variable_definition #_mut(var)?;
}
StmtKind::DeclMulti(vars, expr) => {
for var in vars.iter #_mut() {
if let Some(var) = var {
self.visit_variable_definition #_mut(var)?;
}
for var in vars.iter #_mut().flatten() {
self.visit_variable_definition #_mut(var)?;
}
self.visit_expr #_mut(expr)?;
}
Expand Down Expand Up @@ -441,10 +439,8 @@ declare_visitors! {
self.visit_expr #_mut(false_)?;
}
ExprKind::Tuple(exprs) => {
for expr in exprs.iter #_mut() {
if let Some(expr) = expr {
self.visit_expr #_mut(expr)?;
}
for expr in exprs.iter #_mut().flatten() {
self.visit_expr #_mut(expr)?;
}
}
ExprKind::TypeCall(ty) => {
Expand Down
9 changes: 7 additions & 2 deletions crates/macros/src/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,13 @@ fn expand_streams(tts: &TokenStream) -> (TokenStream, TokenStream) {
match tt {
TokenTree::Group(group) => {
let (nm, m) = expand_streams(&group.stream());
nonmut_tts.append(Group::new(group.delimiter(), nm));
mut_tts.append(Group::new(group.delimiter(), m));
let group = |stream| {
let mut g = Group::new(group.delimiter(), stream);
g.set_span(group.span());
g
};
nonmut_tts.append(group(nm));
mut_tts.append(group(m));
}
TokenTree::Punct(punct)
if punct.as_char() == '#' && tt_iter.clone().next().is_some_and(is_token_mut) =>
Expand Down

0 comments on commit d6a5aec

Please sign in to comment.