Improve insert whitespace in mbe

This commit is contained in:
Edwin Cheng 2022-08-10 16:28:56 +08:00
parent 5366009fe4
commit 23e17cd581
2 changed files with 7 additions and 12 deletions

View file

@ -251,9 +251,13 @@ fn format_args_expand(
}
for arg in &mut args {
// 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);

View file

@ -228,16 +228,7 @@ fn convert_tokens<C: TokenConvertor>(conv: &mut C) -> tt::Subtree {
}
let spacing = match conv.peek().map(|next| next.kind(conv)) {
Some(kind)
if !kind.is_trivia()
&& kind.is_punct()
&& kind != T!['[']
&& kind != T!['{']
&& kind != T!['(']
&& kind != UNDERSCORE =>
{
tt::Spacing::Joint
}
Some(kind) if !kind.is_trivia() => tt::Spacing::Joint,
_ => tt::Spacing::Alone,
};
let char = match token.to_char(conv) {