about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/libsyntax/config.rs1
-rw-r--r--src/test/ui/cfg-attr-trailing-comma.rs13
-rw-r--r--src/test/ui/cfg-attr-trailing-comma.stderr14
3 files changed, 28 insertions, 0 deletions
diff --git a/src/libsyntax/config.rs b/src/libsyntax/config.rs
index 5d978b6b9e6..ea0d1efe7e2 100644
--- a/src/libsyntax/config.rs
+++ b/src/libsyntax/config.rs
@@ -90,6 +90,7 @@ impl<'a> StripUnconfigured<'a> {
             parser.expect(&token::Comma)?;
             let lo = parser.span.lo();
             let (path, tokens) = parser.parse_meta_item_unrestricted()?;
+            parser.eat(&token::Comma); // Optional trailing comma
             parser.expect(&token::CloseDelim(token::Paren))?;
             Ok((cfg, path, tokens, parser.prev_span.with_lo(lo)))
         }) {
diff --git a/src/test/ui/cfg-attr-trailing-comma.rs b/src/test/ui/cfg-attr-trailing-comma.rs
new file mode 100644
index 00000000000..21e00544ca0
--- /dev/null
+++ b/src/test/ui/cfg-attr-trailing-comma.rs
@@ -0,0 +1,13 @@
+// compile-flags: --cfg TRUE
+
+#[cfg_attr(TRUE, inline,)] // OK
+fn f() {}
+
+#[cfg_attr(FALSE, inline,)] // OK
+fn g() {}
+
+#[cfg_attr(TRUE, inline,,)] //~ ERROR expected `)`, found `,`
+fn h() {}
+
+#[cfg_attr(FALSE, inline,,)] //~ ERROR expected `)`, found `,`
+fn i() {}
diff --git a/src/test/ui/cfg-attr-trailing-comma.stderr b/src/test/ui/cfg-attr-trailing-comma.stderr
new file mode 100644
index 00000000000..76a470417e9
--- /dev/null
+++ b/src/test/ui/cfg-attr-trailing-comma.stderr
@@ -0,0 +1,14 @@
+error: expected `)`, found `,`
+  --> $DIR/cfg-attr-trailing-comma.rs:9:25
+   |
+LL | #[cfg_attr(TRUE, inline,,)] //~ ERROR expected `)`, found `,`
+   |                         ^ expected `)`
+
+error: expected `)`, found `,`
+  --> $DIR/cfg-attr-trailing-comma.rs:12:26
+   |
+LL | #[cfg_attr(FALSE, inline,,)] //~ ERROR expected `)`, found `,`
+   |                          ^ expected `)`
+
+error: aborting due to 2 previous errors
+