Skip to content

Commit adc257f

Browse files
committed
Put a space before colon that appears after a meta variable
Closes #2534.
1 parent f8109f8 commit adc257f

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
@@ -522,6 +522,7 @@ impl MacroArgKind {
522522
_ => false,
523523
}
524524
}
525+
525526
fn starts_with_dollar(&self) -> bool {
526527
match *self {
527528
MacroArgKind::Repeat(..) | MacroArgKind::MetaVariable(..) => true,
@@ -777,6 +778,9 @@ impl MacroArgParser {
777778
if ident_like(&self.start_tok) {
778779
return true;
779780
}
781+
if self.start_tok == Token::Colon {
782+
return true;
783+
}
780784
}
781785

782786
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
@@ -147,6 +147,12 @@ macro foo($type_name: ident, $docs: expr) {
147147
pub struct $type_name;
148148
}
149149

150+
// #2534
151+
macro_rules! foo {
152+
($a:ident : $b:ty) => {};
153+
($a:ident $b:ident $c:ident) => {};
154+
}
155+
150156
// #2538
151157
macro_rules! add_message_to_notes {
152158
($msg:expr) => {{

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 {
@@ -180,6 +180,12 @@ macro foo($type_name: ident, $docs: expr) {
180180
pub struct $type_name;
181181
}
182182

183+
// #2534
184+
macro_rules! foo {
185+
($a: ident : $b: ty) => {};
186+
($a: ident $b: ident $c: ident) => {};
187+
}
188+
183189
// #2538
184190
macro_rules! add_message_to_notes {
185191
($msg: expr) => {{

0 commit comments

Comments
 (0)