]> git.lizzy.rs Git - rust.git/blobdiff - tests/source/pattern.rs
Prevent duplicate comma when formatting struct pattern with ".."
[rust.git] / tests / source / pattern.rs
index b8781bd1d2e1ea390534b46e17c7bbf8ed57c4e7..f06d03cadf2f79556e5ae76b151605128087790d 100644 (file)
@@ -1,4 +1,7 @@
 // rustfmt-normalize_comments: true
+#![feature(exclusive_range_pattern)]
+use core::u8::MAX;
+
 fn main() {
     let z = match x {
         "pat1" => 1,
@@ -16,9 +19,9 @@ fn main() {
     let foo@bar (f) = 42;
     let a::foo ( ..) = 42;
     let [ ] = 42;
-    let [a..,     b,c ] = 42;
-    let [ a,b,c.. ] = 42;
-    let [a,    b, c, d..,e,f,     g] = 42;
+    let [a,     b,c ] = 42;
+    let [ a,b,c ] = 42;
+    let [a,    b, c, d,e,f,     g] = 42;
     let foo {   } = 42;
     let foo {..} = 42;
     let foo { x, y: ref foo,     .. } = 42;
@@ -26,6 +29,13 @@ fn main() {
     let foo { x,       yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy: ref foo,      } = 42;
     let foo { x, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy: ref foo,     .. };
     let foo { x,       yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy: ref foo,      };
+
+    match b"12" {
+        [0,
+        1..MAX
+        ] => {}
+        _ => {}
+    }
 }
 
 impl<'a,'b> ResolveGeneratedContentFragmentMutator<'a,'b> {
@@ -48,3 +58,33 @@ fn issue_1874() {
 y
     }
 }
+
+fn combine_patterns() {
+    let x = match y {
+        Some(
+            Some(
+                Foo {
+                    z: Bar(..),
+                    a: Bar(..),
+                    b: Bar(..),
+                },
+            ),
+        ) => z,
+        _ => return,
+    };
+}
+
+fn slice_patterns() {
+    match b"123" {
+        [0, ..] => {}
+        [0, foo] => {}
+        _ => {}
+    }
+}
+
+fn issue3728() {
+    let foo = |
+    (c,)
+        | c;
+    foo((1,));
+}