about summary refs log tree commit diff
diff options
context:
space:
mode:
authormark <markm@cs.wisc.edu>2019-01-15 16:55:23 -0600
committerMark Mansi <markm@cs.wisc.edu>2019-02-07 12:15:32 -0600
commit3e790a7c304b3bcb182c4fcb745ea288d3dc56f2 (patch)
tree8761f2c91c4f2ec9c3da3ba8c31ef4bc4d0fa53e
parent1d94cc2a2249b65f62e78e4998761193c3bfed23 (diff)
downloadrust-3e790a7c304b3bcb182c4fcb745ea288d3dc56f2.tar.gz
rust-3e790a7c304b3bcb182c4fcb745ea288d3dc56f2.zip
add a test
-rw-r--r--src/test/ui/macros/macro-multiple-matcher-bindings.rs19
-rw-r--r--src/test/ui/macros/macro-multiple-matcher-bindings.stderr50
2 files changed, 69 insertions, 0 deletions
diff --git a/src/test/ui/macros/macro-multiple-matcher-bindings.rs b/src/test/ui/macros/macro-multiple-matcher-bindings.rs
new file mode 100644
index 00000000000..ea57d66b565
--- /dev/null
+++ b/src/test/ui/macros/macro-multiple-matcher-bindings.rs
@@ -0,0 +1,19 @@
+// Test that duplicate matcher binding names are caught at declaration time, rather than at macro
+// invocation time.
+
+macro_rules! foo1 {
+    ($a:ident, $a:ident) => {}; //~ERROR duplicate matcher binding
+    ($a:ident, $a:path) => {};  //~ERROR duplicate matcher binding
+}
+
+macro_rules! foo2 {
+    ($a:ident) => {}; // OK
+    ($a:path) => {};  // OK
+}
+
+macro_rules! foo3 {
+    ($a:ident, $($a:ident),*) => {}; //~ERROR duplicate matcher binding
+    ($($a:ident)+ # $($($a:path),+);*) => {}; //~ERROR duplicate matcher binding
+}
+
+fn main() {}
diff --git a/src/test/ui/macros/macro-multiple-matcher-bindings.stderr b/src/test/ui/macros/macro-multiple-matcher-bindings.stderr
new file mode 100644
index 00000000000..3e3e1024587
--- /dev/null
+++ b/src/test/ui/macros/macro-multiple-matcher-bindings.stderr
@@ -0,0 +1,50 @@
+error: duplicate matcher binding
+  --> $DIR/macro-multiple-matcher-bindings.rs:5:16
+   |
+LL |     ($a:ident, $a:ident) => {}; //~ERROR duplicate matcher binding
+   |                ^^^^^^^^
+   |
+note: previous declaration was here
+  --> $DIR/macro-multiple-matcher-bindings.rs:5:6
+   |
+LL |     ($a:ident, $a:ident) => {}; //~ERROR duplicate matcher binding
+   |      ^^^^^^^^
+
+error: duplicate matcher binding
+  --> $DIR/macro-multiple-matcher-bindings.rs:6:16
+   |
+LL |     ($a:ident, $a:path) => {};  //~ERROR duplicate matcher binding
+   |                ^^^^^^^
+   |
+note: previous declaration was here
+  --> $DIR/macro-multiple-matcher-bindings.rs:6:6
+   |
+LL |     ($a:ident, $a:path) => {};  //~ERROR duplicate matcher binding
+   |      ^^^^^^^^
+
+error: duplicate matcher binding
+  --> $DIR/macro-multiple-matcher-bindings.rs:15:18
+   |
+LL |     ($a:ident, $($a:ident),*) => {}; //~ERROR duplicate matcher binding
+   |                  ^^^^^^^^
+   |
+note: previous declaration was here
+  --> $DIR/macro-multiple-matcher-bindings.rs:15:6
+   |
+LL |     ($a:ident, $($a:ident),*) => {}; //~ERROR duplicate matcher binding
+   |      ^^^^^^^^
+
+error: duplicate matcher binding
+  --> $DIR/macro-multiple-matcher-bindings.rs:16:25
+   |
+LL |     ($($a:ident)+ # $($($a:path),+);*) => {}; //~ERROR duplicate matcher binding
+   |                         ^^^^^^^
+   |
+note: previous declaration was here
+  --> $DIR/macro-multiple-matcher-bindings.rs:16:8
+   |
+LL |     ($($a:ident)+ # $($($a:path),+);*) => {}; //~ERROR duplicate matcher binding
+   |        ^^^^^^^^
+
+error: aborting due to 4 previous errors
+