Skip to content

Commit 6d5fa21

Browse files
Alexander Gluskerrscprof
authored andcommitted
In macro definitions new name can start from $ without spaces before it.
1 parent d5f1200 commit 6d5fa21

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

src/macros.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,13 @@ fn replace_names(input: &str) -> Option<(String, HashMap<String, String>)> {
520520
if kind != FullCodeCharKind::Normal {
521521
result.push(c);
522522
} else if c == '$' {
523+
// the name can end by starting new name with $
524+
if !cur_name.is_empty() {
525+
dbg!(&cur_name);
526+
register_metavariable(&mut substs, &mut result, &cur_name, dollar_count);
527+
dollar_count = 0;
528+
cur_name.clear();
529+
}
523530
dollar_count += 1;
524531
} else if dollar_count == 0 {
525532
result.push(c);

tests/source/issue-5905/test.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
macro_rules! test_macro {
2+
($member:ident $($rest:tt)*) => {
3+
paste::paste! {fn test(&self) {
4+
(self.$member$($rest)* )
5+
}}
6+
};
7+
}
8+

tests/target/issue-5905/test.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
macro_rules! test_macro {
2+
($member:ident $($rest:tt)*) => {
3+
paste::paste! {fn test(&self) {
4+
(self.$member$($rest)* )
5+
}}
6+
};
7+
}

0 commit comments

Comments
 (0)