Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/mbe/src/expander/transcriber.rs')
-rw-r--r--crates/mbe/src/expander/transcriber.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/crates/mbe/src/expander/transcriber.rs b/crates/mbe/src/expander/transcriber.rs
index 2c046df10f..3e4ab8bdc1 100644
--- a/crates/mbe/src/expander/transcriber.rs
+++ b/crates/mbe/src/expander/transcriber.rs
@@ -401,7 +401,19 @@ fn expand_var(
let sub = sub.strip_invisible();
let mut span = id;
marker(&mut span);
- let wrap_in_parens = !matches!(sub.flat_tokens(), [tt::TokenTree::Leaf(_)])
+
+ // Check if this is a simple negative literal (MINUS + LITERAL)
+ // that should not be wrapped in parentheses
+ let is_negative_literal = matches!(
+ sub.flat_tokens(),
+ [
+ tt::TokenTree::Leaf(tt::Leaf::Punct(tt::Punct { char: '-', .. })),
+ tt::TokenTree::Leaf(tt::Leaf::Literal(_))
+ ]
+ );
+
+ let wrap_in_parens = !is_negative_literal
+ && !matches!(sub.flat_tokens(), [tt::TokenTree::Leaf(_)])
&& sub.try_into_subtree().is_none_or(|it| {
it.top_subtree().delimiter.kind == tt::DelimiterKind::Invisible
});