mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +00:00
Fix macro expansion expression parenthesis wrapping
This commit is contained in:
parent
efa67294ed
commit
d2a31acda1
18 changed files with 218 additions and 64 deletions
|
@ -792,9 +792,21 @@ fn match_meta_var<S: Span>(
|
|||
}
|
||||
_ => {}
|
||||
};
|
||||
return input
|
||||
.expect_fragment(parser::PrefixEntryPoint::Expr)
|
||||
.map(|tt| tt.map(tt::TokenTree::subtree_or_wrap).map(Fragment::Expr));
|
||||
return input.expect_fragment(parser::PrefixEntryPoint::Expr).map(|tt| {
|
||||
tt.map(|tt| match tt {
|
||||
tt::TokenTree::Leaf(leaf) => tt::Subtree {
|
||||
delimiter: tt::Delimiter::dummy_invisible(),
|
||||
token_trees: vec![leaf.into()],
|
||||
},
|
||||
tt::TokenTree::Subtree(mut s) => {
|
||||
if s.delimiter.kind == tt::DelimiterKind::Invisible {
|
||||
s.delimiter.kind = tt::DelimiterKind::Parenthesis;
|
||||
}
|
||||
s
|
||||
}
|
||||
})
|
||||
.map(Fragment::Expr)
|
||||
});
|
||||
}
|
||||
MetaVarKind::Ident | MetaVarKind::Tt | MetaVarKind::Lifetime | MetaVarKind::Literal => {
|
||||
let tt_result = match kind {
|
||||
|
|
|
@ -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),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue