Skip to content

Commit 112f7e9

Browse files
committed
Auto merge of #60248 - estebank:macro-comma, r=oli-obk
Add guard for missing comma in macro call suggestion Fix #60233. Follow up to #58796. r? @oli-obk
2 parents 3d720d7 + 0e505d4 commit 112f7e9

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

src/libsyntax/tokenstream.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,10 @@ impl TokenStream {
182182
(_, (TokenTree::Token(_, token::Token::Comma), _)) => continue,
183183
((TokenTree::Token(sp, token_left), NonJoint),
184184
(TokenTree::Token(_, token_right), _))
185-
if (token_left.is_ident() || token_left.is_lit()) &&
186-
(token_right.is_ident() || token_right.is_lit()) => *sp,
185+
if ((token_left.is_ident() && !token_left.is_reserved_ident())
186+
|| token_left.is_lit()) &&
187+
((token_right.is_ident() && !token_right.is_reserved_ident())
188+
|| token_right.is_lit()) => *sp,
187189
((TokenTree::Delimited(sp, ..), NonJoint), _) => sp.entire(),
188190
_ => continue,
189191
};

src/test/ui/macros/missing-comma.rs

+7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ macro_rules! bar {
1010
($lvl:expr, $($arg:tt)+) => {}
1111
}
1212

13+
macro_rules! check {
14+
($ty:ty, $expected:expr) => {};
15+
($ty_of:expr, $expected:expr) => {};
16+
}
1317

1418
fn main() {
1519
println!("{}" a);
@@ -24,4 +28,7 @@ fn main() {
2428
//~^ ERROR no rules expected the token `d`
2529
bar!(Level::Error, );
2630
//~^ ERROR unexpected end of macro invocation
31+
check!(<str as Debug>::fmt, "fmt");
32+
check!(<str as Debug>::fmt, "fmt",);
33+
//~^ ERROR no rules expected the token `,`
2734
}

src/test/ui/macros/missing-comma.stderr

+16-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error: expected token: `,`
2-
--> $DIR/missing-comma.rs:15:19
2+
--> $DIR/missing-comma.rs:19:19
33
|
44
LL | println!("{}" a);
55
| ^
66

77
error: no rules expected the token `b`
8-
--> $DIR/missing-comma.rs:17:12
8+
--> $DIR/missing-comma.rs:21:12
99
|
1010
LL | macro_rules! foo {
1111
| ---------------- when calling this macro
@@ -16,7 +16,7 @@ LL | foo!(a b);
1616
| help: missing comma here
1717

1818
error: no rules expected the token `e`
19-
--> $DIR/missing-comma.rs:19:21
19+
--> $DIR/missing-comma.rs:23:21
2020
|
2121
LL | macro_rules! foo {
2222
| ---------------- when calling this macro
@@ -27,7 +27,7 @@ LL | foo!(a, b, c, d e);
2727
| help: missing comma here
2828

2929
error: no rules expected the token `d`
30-
--> $DIR/missing-comma.rs:21:18
30+
--> $DIR/missing-comma.rs:25:18
3131
|
3232
LL | macro_rules! foo {
3333
| ---------------- when calling this macro
@@ -38,7 +38,7 @@ LL | foo!(a, b, c d, e);
3838
| help: missing comma here
3939

4040
error: no rules expected the token `d`
41-
--> $DIR/missing-comma.rs:23:18
41+
--> $DIR/missing-comma.rs:27:18
4242
|
4343
LL | macro_rules! foo {
4444
| ---------------- when calling this macro
@@ -47,13 +47,22 @@ LL | foo!(a, b, c d e);
4747
| ^ no rules expected this token in macro call
4848

4949
error: unexpected end of macro invocation
50-
--> $DIR/missing-comma.rs:25:23
50+
--> $DIR/missing-comma.rs:29:23
5151
|
5252
LL | macro_rules! bar {
5353
| ---------------- when calling this macro
5454
...
5555
LL | bar!(Level::Error, );
5656
| ^ missing tokens in macro arguments
5757

58-
error: aborting due to 6 previous errors
58+
error: no rules expected the token `,`
59+
--> $DIR/missing-comma.rs:32:38
60+
|
61+
LL | macro_rules! check {
62+
| ------------------ when calling this macro
63+
...
64+
LL | check!(<str as Debug>::fmt, "fmt",);
65+
| ^ no rules expected this token in macro call
66+
67+
error: aborting due to 7 previous errors
5968

0 commit comments

Comments
 (0)