about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOli Scherer <github333195615777966@oli-obk.de>2025-01-30 09:15:33 +0000
committerOli Scherer <github333195615777966@oli-obk.de>2025-02-05 09:43:09 +0000
commit24d94b2db9c18a30e8564ac8144a30b52dd31577 (patch)
tree62ad77da05740842fc094f39ac70e4dc3a960488
parent8df89d1cb077cd76013d3f9f5a4e92c5b5a9280c (diff)
downloadrust-24d94b2db9c18a30e8564ac8144a30b52dd31577.tar.gz
rust-24d94b2db9c18a30e8564ac8144a30b52dd31577.zip
Add regression test for negative unsigned literals in patterns
-rw-r--r--tests/ui/type/pattern_types/signed_ranges.rs22
-rw-r--r--tests/ui/type/pattern_types/signed_ranges.stderr17
2 files changed, 39 insertions, 0 deletions
diff --git a/tests/ui/type/pattern_types/signed_ranges.rs b/tests/ui/type/pattern_types/signed_ranges.rs
new file mode 100644
index 00000000000..73ae89ac813
--- /dev/null
+++ b/tests/ui/type/pattern_types/signed_ranges.rs
@@ -0,0 +1,22 @@
+#![feature(pattern_types)]
+#![feature(pattern_type_macro)]
+
+use std::pat::pattern_type;
+
+type Sign = pattern_type!(u32 is -10..);
+//~^ ERROR: cannot apply unary operator `-`
+
+type SignedChar = pattern_type!(char is -'A'..);
+//~^ ERROR: cannot apply unary operator `-`
+
+fn main() {
+    match 42_u8 {
+        -10..253 => {}
+        _ => {}
+    }
+
+    match 'A' {
+        -'\0'..'a' => {}
+        _ => {}
+    }
+}
diff --git a/tests/ui/type/pattern_types/signed_ranges.stderr b/tests/ui/type/pattern_types/signed_ranges.stderr
new file mode 100644
index 00000000000..63e346927f7
--- /dev/null
+++ b/tests/ui/type/pattern_types/signed_ranges.stderr
@@ -0,0 +1,17 @@
+error[E0600]: cannot apply unary operator `-` to type `u32`
+  --> $DIR/signed_ranges.rs:6:34
+   |
+LL | type Sign = pattern_type!(u32 is -10..);
+   |                                  ^^^ cannot apply unary operator `-`
+   |
+   = note: unsigned values cannot be negated
+
+error[E0600]: cannot apply unary operator `-` to type `char`
+  --> $DIR/signed_ranges.rs:9:41
+   |
+LL | type SignedChar = pattern_type!(char is -'A'..);
+   |                                         ^^^^ cannot apply unary operator `-`
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0600`.