summary refs log tree commit diff
path: root/src/test/compile-fail
diff options
context:
space:
mode:
authorKevin Atkinson <kevina@cs.utah.edu>2012-01-10 14:50:40 -0700
committerGraydon Hoare <graydon@mozilla.com>2012-01-10 15:59:57 -0800
commit08abf8d37fa549ebc67f80d80530f4aa43d716e4 (patch)
treef6c9bce62c494a37d989d07be4661f57c0c7eba3 /src/test/compile-fail
parentd0fe6723fc2f431205092bda9ec399d932081bd0 (diff)
downloadrust-08abf8d37fa549ebc67f80d80530f4aa43d716e4.tar.gz
rust-08abf8d37fa549ebc67f80d80530f4aa43d716e4.zip
Support explicit discriminant numbers on tag variants.
Addresses issue #1393.

For now disallow disr. values unless all variants use nullary
contractors (i.e. "enum-like").

Disr. values are now encoded in the crate metadata, but only when it
will differ from the inferred value based on the order.
Diffstat (limited to 'src/test/compile-fail')
-rw-r--r--src/test/compile-fail/tag-variant-disr-dup.rs11
-rw-r--r--src/test/compile-fail/tag-variant-disr-non-nullary.rs11
2 files changed, 22 insertions, 0 deletions
diff --git a/src/test/compile-fail/tag-variant-disr-dup.rs b/src/test/compile-fail/tag-variant-disr-dup.rs
new file mode 100644
index 00000000000..c3e671f1011
--- /dev/null
+++ b/src/test/compile-fail/tag-variant-disr-dup.rs
@@ -0,0 +1,11 @@
+//error-pattern:discriminator value already exists
+
+// black and white have the same discriminator value ...
+
+tag color {
+    red = 0xff0000;
+    green = 0x00ff00;
+    blue = 0x0000ff;
+    black = 0x000000;
+    white = 0x000000;
+}
diff --git a/src/test/compile-fail/tag-variant-disr-non-nullary.rs b/src/test/compile-fail/tag-variant-disr-non-nullary.rs
new file mode 100644
index 00000000000..1d3a59e172f
--- /dev/null
+++ b/src/test/compile-fail/tag-variant-disr-non-nullary.rs
@@ -0,0 +1,11 @@
+//error-pattern: discriminator values can only be used with enum-like tag
+// black and white have the same discriminator value ...
+
+tag color {
+    red = 0xff0000;
+    green = 0x00ff00;
+    blue = 0x0000ff;
+    black = 0x000000;
+    white = 0xffffff;
+    other (str);
+}