Skip to content

Commit 23e17cd

Browse files
committed
Improve insert whitespace in mbe
1 parent 5366009 commit 23e17cd

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

crates/hir-expand/src/builtin_fn_macro.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,13 @@ fn format_args_expand(
251251
}
252252
for arg in &mut args {
253253
// Remove `key =`.
254-
if matches!(arg.token_trees.get(1), Some(tt::TokenTree::Leaf(tt::Leaf::Punct(p))) if p.char == '=' && p.spacing != tt::Spacing::Joint)
254+
if matches!(arg.token_trees.get(1), Some(tt::TokenTree::Leaf(tt::Leaf::Punct(p))) if p.char == '=')
255255
{
256-
arg.token_trees.drain(..2);
256+
// but not with `==`
257+
if !matches!(arg.token_trees.get(2), Some(tt::TokenTree::Leaf(tt::Leaf::Punct(p))) if p.char == '=' )
258+
{
259+
arg.token_trees.drain(..2);
260+
}
257261
}
258262
}
259263
let _format_string = args.remove(0);

crates/mbe/src/syntax_bridge.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -228,16 +228,7 @@ fn convert_tokens<C: TokenConvertor>(conv: &mut C) -> tt::Subtree {
228228
}
229229

230230
let spacing = match conv.peek().map(|next| next.kind(conv)) {
231-
Some(kind)
232-
if !kind.is_trivia()
233-
&& kind.is_punct()
234-
&& kind != T!['[']
235-
&& kind != T!['{']
236-
&& kind != T!['(']
237-
&& kind != UNDERSCORE =>
238-
{
239-
tt::Spacing::Joint
240-
}
231+
Some(kind) if !kind.is_trivia() => tt::Spacing::Joint,
241232
_ => tt::Spacing::Alone,
242233
};
243234
let char = match token.to_char(conv) {

0 commit comments

Comments
 (0)