Skip to content

Commit 2b3e16b

Browse files
committed
Accept trailing comma in cfg_attr
1 parent 4141a40 commit 2b3e16b

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

Diff for: src/libsyntax/config.rs

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ impl<'a> StripUnconfigured<'a> {
9090
parser.expect(&token::Comma)?;
9191
let lo = parser.span.lo();
9292
let (path, tokens) = parser.parse_meta_item_unrestricted()?;
93+
parser.eat(&token::Comma); // Optional trailing comma
9394
parser.expect(&token::CloseDelim(token::Paren))?;
9495
Ok((cfg, path, tokens, parser.prev_span.with_lo(lo)))
9596
}) {

Diff for: src/test/ui/cfg-attr-trailing-comma.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// compile-flags: --cfg TRUE
2+
3+
#[cfg_attr(TRUE, inline,)] // OK
4+
fn f() {}
5+
6+
#[cfg_attr(FALSE, inline,)] // OK
7+
fn g() {}
8+
9+
#[cfg_attr(TRUE, inline,,)] //~ ERROR expected `)`, found `,`
10+
fn h() {}
11+
12+
#[cfg_attr(FALSE, inline,,)] //~ ERROR expected `)`, found `,`
13+
fn i() {}

Diff for: src/test/ui/cfg-attr-trailing-comma.stderr

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: expected `)`, found `,`
2+
--> $DIR/cfg-attr-trailing-comma.rs:9:25
3+
|
4+
LL | #[cfg_attr(TRUE, inline,,)] //~ ERROR expected `)`, found `,`
5+
| ^ expected `)`
6+
7+
error: expected `)`, found `,`
8+
--> $DIR/cfg-attr-trailing-comma.rs:12:26
9+
|
10+
LL | #[cfg_attr(FALSE, inline,,)] //~ ERROR expected `)`, found `,`
11+
| ^ expected `)`
12+
13+
error: aborting due to 2 previous errors
14+

0 commit comments

Comments
 (0)