]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Add regression tests for exclusive range pattern
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Tue, 21 May 2024 16:29:08 +0000 (18:29 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Mon, 17 Mar 2025 15:35:35 +0000 (16:35 +0100)
Add a few test to check the exclusive range pattern feature. This feature
is experimental and shall not be enabled in stable rust.

gcc/testsuite/ChangeLog:

* rust/compile/exclusive_range_pattern.rs: New test.
* rust/compile/exclusive_range_pattern_feature_gate.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
gcc/testsuite/rust/compile/exclusive_range_pattern.rs [new file with mode: 0644]
gcc/testsuite/rust/compile/exclusive_range_pattern_feature_gate.rs [new file with mode: 0644]

diff --git a/gcc/testsuite/rust/compile/exclusive_range_pattern.rs b/gcc/testsuite/rust/compile/exclusive_range_pattern.rs
new file mode 100644 (file)
index 0000000..4840abe
--- /dev/null
@@ -0,0 +1,17 @@
+// { dg-options "-fsyntax-only" }
+#![feature(exclusive_range_pattern)]
+
+const TEN: usize = 10;
+
+fn test(n: usize) {
+    match n {
+        0..TEN => (),
+        TEN..20 => (),
+        20..30 => (),
+        _ => (),
+    }
+}
+
+fn test2(t: usize) {
+    if let 0..10 = t {}
+}
diff --git a/gcc/testsuite/rust/compile/exclusive_range_pattern_feature_gate.rs b/gcc/testsuite/rust/compile/exclusive_range_pattern_feature_gate.rs
new file mode 100644 (file)
index 0000000..4530214
--- /dev/null
@@ -0,0 +1,8 @@
+// { dg-options "-frust-compile-until=lowering" }
+
+fn test(n: usize) {
+    match n {
+        0..10 => (), //{ dg-error "exclusive range pattern syntax is experimental." "" { target *-*-* }  }
+        _ => (),
+    }
+}