mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-31 23:38:45 +00:00
Improve insert whitespace in mbe
This commit is contained in:
parent
5366009fe4
commit
23e17cd581
2 changed files with 7 additions and 12 deletions
|
@ -251,9 +251,13 @@ fn format_args_expand(
|
||||||
}
|
}
|
||||||
for arg in &mut args {
|
for arg in &mut args {
|
||||||
// Remove `key =`.
|
// Remove `key =`.
|
||||||
if matches!(arg.token_trees.get(1), Some(tt::TokenTree::Leaf(tt::Leaf::Punct(p))) if p.char == '=' && p.spacing != tt::Spacing::Joint)
|
if matches!(arg.token_trees.get(1), Some(tt::TokenTree::Leaf(tt::Leaf::Punct(p))) if p.char == '=')
|
||||||
{
|
{
|
||||||
arg.token_trees.drain(..2);
|
// but not with `==`
|
||||||
|
if !matches!(arg.token_trees.get(2), Some(tt::TokenTree::Leaf(tt::Leaf::Punct(p))) if p.char == '=' )
|
||||||
|
{
|
||||||
|
arg.token_trees.drain(..2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let _format_string = args.remove(0);
|
let _format_string = args.remove(0);
|
||||||
|
|
|
@ -228,16 +228,7 @@ fn convert_tokens<C: TokenConvertor>(conv: &mut C) -> tt::Subtree {
|
||||||
}
|
}
|
||||||
|
|
||||||
let spacing = match conv.peek().map(|next| next.kind(conv)) {
|
let spacing = match conv.peek().map(|next| next.kind(conv)) {
|
||||||
Some(kind)
|
Some(kind) if !kind.is_trivia() => tt::Spacing::Joint,
|
||||||
if !kind.is_trivia()
|
|
||||||
&& kind.is_punct()
|
|
||||||
&& kind != T!['[']
|
|
||||||
&& kind != T!['{']
|
|
||||||
&& kind != T!['(']
|
|
||||||
&& kind != UNDERSCORE =>
|
|
||||||
{
|
|
||||||
tt::Spacing::Joint
|
|
||||||
}
|
|
||||||
_ => tt::Spacing::Alone,
|
_ => tt::Spacing::Alone,
|
||||||
};
|
};
|
||||||
let char = match token.to_char(conv) {
|
let char = match token.to_char(conv) {
|
||||||
|
|
Loading…
Reference in a new issue