Skip to content

Commit 6f150e2

Browse files
committed
rust: macros: get paste! { [A $pos] } to work for integers
Signed-off-by: Fabien Parent <[email protected]>
1 parent 7b4547c commit 6f150e2

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

rust/macros/paste.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ fn concat(tokens: &[TokenTree], group_span: Span) -> TokenTree {
77
let mut segments = Vec::new();
88
let mut span = None;
99
loop {
10-
match tokens.next() {
10+
let t = tokens.next();
11+
match t {
1112
None => break,
1213
Some(TokenTree::Literal(lit)) => {
1314
// Allow us to concat string literals by stripping quotes
@@ -46,6 +47,19 @@ fn concat(tokens: &[TokenTree], group_span: Span) -> TokenTree {
4647
};
4748
segments.push((value, sp));
4849
}
50+
Some(TokenTree::Group(group)) => {
51+
let stream: Vec<_> = group.stream().into_iter().collect();
52+
if let TokenTree::Literal(lit) = &stream[0] {
53+
let mut value = lit.to_string();
54+
if value.starts_with('"') && value.ends_with('"') {
55+
value.remove(0);
56+
value.pop();
57+
}
58+
segments.push((value, lit.span()));
59+
} else {
60+
panic!("unexpected token in paste segments");
61+
}
62+
}
4963
_ => panic!("unexpected token in paste segments"),
5064
};
5165
}

0 commit comments

Comments
 (0)