Skip to content

Commit 319b6df

Browse files
committed
Put a space before colon that appears after a meta variable
Closes #2534.
1 parent 78706d5 commit 319b6df

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

src/macros.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ impl MacroArgKind {
523523
_ => false,
524524
}
525525
}
526+
526527
fn starts_with_dollar(&self) -> bool {
527528
match *self {
528529
MacroArgKind::Repeat(..) | MacroArgKind::MetaVariable(..) => true,
@@ -778,6 +779,9 @@ impl MacroArgParser {
778779
if ident_like(&self.start_tok) {
779780
return true;
780781
}
782+
if self.start_tok == Token::Colon {
783+
return true;
784+
}
781785
}
782786

783787
if force_space_before(&self.start_tok) {

tests/source/macro_rules.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,9 @@ macro foo($type_name: ident, $docs: expr) {
146146
#[derive(Debug, Clone, Copy)]
147147
pub struct $type_name;
148148
}
149+
150+
// #2534
151+
macro_rules! foo {
152+
($a:ident : $b:ty) => {};
153+
($a:ident $b:ident $c:ident) => {};
154+
}

tests/target/macro_rules.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ macro_rules! m {
1515
) => {};
1616
($name: ident($($dol: tt $var: ident)*) $($body: tt)*) => {};
1717
(
18-
$($i: ident: $ty: ty, $def: expr, $stb: expr, $($dstring: tt),+);+ $(;)*
19-
$($i: ident: $ty: ty, $def: expr, $stb: expr, $($dstring: tt),+);+ $(;)*
18+
$($i: ident : $ty: ty, $def: expr, $stb: expr, $($dstring: tt),+);+ $(;)*
19+
$($i: ident : $ty: ty, $def: expr, $stb: expr, $($dstring: tt),+);+ $(;)*
2020
) => {};
2121
($foo: tt foo[$attr: meta] $name: ident) => {};
2222
($foo: tt[$attr: meta] $name: ident) => {};
@@ -28,7 +28,7 @@ macro_rules! m {
2828
}
2929

3030
macro_rules! impl_a_method {
31-
($n: ident($a: ident: $ta: ty) -> $ret: ty { $body: expr }) => {
31+
($n: ident($a: ident : $ta: ty) -> $ret: ty { $body: expr }) => {
3232
fn $n($a: $ta) -> $ret {
3333
$body
3434
}
@@ -38,7 +38,7 @@ macro_rules! impl_a_method {
3838
};
3939
}
4040
};
41-
($n: ident($a: ident: $ta: ty, $b: ident: $tb: ty) -> $ret: ty { $body: expr }) => {
41+
($n: ident($a: ident : $ta: ty, $b: ident : $tb: ty) -> $ret: ty { $body: expr }) => {
4242
fn $n($a: $ta, $b: $tb) -> $ret {
4343
$body
4444
}
@@ -49,7 +49,7 @@ macro_rules! impl_a_method {
4949
}
5050
};
5151
(
52-
$n: ident($a: ident: $ta: ty, $b: ident: $tb: ty, $c: ident: $tc: ty) ->
52+
$n: ident($a: ident : $ta: ty, $b: ident : $tb: ty, $c: ident : $tc: ty) ->
5353
$ret: ty { $body: expr }
5454
) => {
5555
fn $n($a: $ta, $b: $tb, $c: $tc) -> $ret {
@@ -62,7 +62,7 @@ macro_rules! impl_a_method {
6262
}
6363
};
6464
(
65-
$n: ident($a: ident: $ta: ty, $b: ident: $tb: ty, $c: ident: $tc: ty, $d: ident: $td: ty) ->
65+
$n: ident($a: ident : $ta: ty, $b: ident : $tb: ty, $c: ident : $tc: ty, $d: ident : $td: ty) ->
6666
$ret: ty { $body: expr }
6767
) => {
6868
fn $n($a: $ta, $b: $tb, $c: $tc, $d: $td) -> $ret {
@@ -179,3 +179,9 @@ macro foo($type_name: ident, $docs: expr) {
179179
#[derive(Debug, Clone, Copy)]
180180
pub struct $type_name;
181181
}
182+
183+
// #2534
184+
macro_rules! foo {
185+
($a: ident : $b: ty) => {};
186+
($a: ident $b: ident $c: ident) => {};
187+
}

0 commit comments

Comments
 (0)