Fix macro expansion expression parenthesis wrapping

This commit is contained in:
Lukas Wirth 2023-12-02 13:03:46 +01:00
parent efa67294ed
commit d2a31acda1
18 changed files with 218 additions and 64 deletions

View file

@ -444,15 +444,8 @@ fn expand_repeat<S: Span>(
fn push_fragment<S: Span>(buf: &mut Vec<tt::TokenTree<S>>, fragment: Fragment<S>) {
match fragment {
Fragment::Tokens(tt::TokenTree::Subtree(tt)) => push_subtree(buf, tt),
Fragment::Expr(mut tt) => {
if tt.delimiter.kind == tt::DelimiterKind::Invisible {
tt.delimiter = tt::Delimiter {
open: S::DUMMY,
close: S::DUMMY,
kind: tt::DelimiterKind::Parenthesis,
};
}
buf.push(tt.into())
Fragment::Expr(sub) => {
push_subtree(buf, sub);
}
Fragment::Path(tt) => fix_up_and_push_path_tt(buf, tt),
Fragment::Tokens(tt) => buf.push(tt),