]> git.lizzy.rs Git - rust.git/blobdiff - tests/target/match.rs
Implement 'vec![expr; expr]'
[rust.git] / tests / target / match.rs
index 2c238ea8a685ff4214732d0471698017cf7662c5..09df7ebd55fdf7e997e5008bca1cc464ed4db5b5 100644 (file)
@@ -1,3 +1,4 @@
+// rustfmt-normalize_comments: true
 // Match expressions.
 
 fn foo() {
@@ -32,16 +33,7 @@ fn foo() {
         }
 
         // Test that earlier patterns can take the guard space
-        (aaaa,
-         bbbbb,
-         ccccccc,
-         aaaaa,
-         bbbbbbbb,
-         cccccc,
-         aaaa,
-         bbbbbbbb,
-         cccccc,
-         dddddd) |
+        (aaaa, bbbbb, ccccccc, aaaaa, bbbbbbbb, cccccc, aaaa, bbbbbbbb, cccccc, dddddd) |
         Patternnnnnnnnnnnnnnnnnnnnnnnnn if loooooooooooooooooooooooooooooooooooooooooong_guard => {}
 
         _ => {}
@@ -75,29 +67,18 @@ fn main() {
 fn main() {
     match r {
         Variableeeeeeeeeeeeeeeeee => {
-            ("variable",
-             vec!["id", "name", "qualname", "value", "type", "scopeid"],
-             true,
-             true)
+            ("variable", vec!["id", "name", "qualname", "value", "type", "scopeid"], true, true)
         }
         Enummmmmmmmmmmmmmmmmmmmm => {
-            ("enum",
-             vec!["id", "qualname", "scopeid", "value"],
-             true,
-             true)
+            ("enum", vec!["id", "qualname", "scopeid", "value"], true, true)
         }
         Variantttttttttttttttttttttttt => {
-            ("variant",
-             vec!["id", "name", "qualname", "type", "value", "scopeid"],
-             true,
-             true)
+            ("variant", vec!["id", "name", "qualname", "type", "value", "scopeid"], true, true)
         }
     };
 
     match x {
-        y => {
-            // Block with comment. Preserve me.
-        }
+        y => { /*Block with comment. Preserve me.*/ }
         z => {
             stmt();
         }
@@ -115,6 +96,14 @@ fn matches() {
     }
 }
 
+fn match_skip() {
+    let _ = match Some(1) {
+        #[rustfmt_skip]
+        Some( n ) => n,
+        None => 1,
+    };
+}
+
 fn issue339() {
     match a {
         b => {}
@@ -169,19 +158,19 @@ fn issue355() {
     match mac {
         a => println!("a", b),
         b => vec![1, 2],
-        c => vec!(3; 4),
+        c => vec![3; 4],
         d => println!("a", b),
         e => vec![1, 2],
-        f => vec!(3; 4),
+        f => vec![3; 4],
         h => println!("a", b), // h comment
         i => vec![1, 2], // i comment
-        j => vec!(3; 4), // j comment
+        j => vec![3; 4], // j comment
         // k comment
         k => println!("a", b),
         // l comment
         l => vec![1, 2],
         // m comment
-        m => vec!(3; 4),
+        m => vec![3; 4],
         // Rewrite splits macro
         nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn => {
             println!("a", b)
@@ -193,7 +182,7 @@ fn issue355() {
         // Macro support fails to recognise this macro as splitable
         // We push the whole expr to a new line, TODO split this macro as well
         pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp => {
-            vec!(3; 4)
+            vec![3; 4]
         }
         // q, r and s: Rewrite splits match arm
         qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq => {
@@ -203,19 +192,19 @@ fn issue355() {
             vec![1, 2]
         }
         ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss => {
-            vec!(3; 4)
+            vec![3; 4]
         }
         // Funky bracketing styles
         t => println!{"a", b},
         u => vec![1, 2],
-        v => vec!{3; 4},
+        v => vec![3; 4],
         w => println!["a", b],
         x => vec![1, 2],
         y => vec![3; 4],
         // Brackets with comments
         tc => println!{"a", b}, // comment
         uc => vec![1, 2], // comment
-        vc => vec!{3; 4}, // comment
+        vc => vec![3; 4], // comment
         wc => println!["a", b], // comment
         xc => vec![1, 2], // comment
         yc => vec![3; 4], // comment
@@ -231,9 +220,8 @@ fn issue355() {
 fn issue280() {
     {
         match x {
-            CompressionMode::DiscardNewline | CompressionMode::CompressWhitespaceNewline => {
-                ch == '\n'
-            }
+            CompressionMode::DiscardNewline |
+            CompressionMode::CompressWhitespaceNewline => ch == '\n',
             ast::ItemConst(ref typ, ref expr) => {
                 self.process_static_or_const_item(item, &typ, &expr)
             }
@@ -243,7 +231,7 @@ fn issue280() {
 
 fn issue383() {
     match resolution.last_private {
-        LastImport{..} => false,
+        LastImport { .. } => false,
         _ => true,
     };
 }
@@ -270,7 +258,8 @@ fn issue496() {
         {
             {
                 match def {
-                    def::DefConst(def_id) | def::DefAssociatedConst(def_id) => {
+                    def::DefConst(def_id) |
+                    def::DefAssociatedConst(def_id) => {
                         match const_eval::lookup_const_by_id(cx.tcx, def_id, Some(self.pat.id)) {
                             Some(const_expr) => x,
                         }
@@ -284,15 +273,136 @@ fn issue496() {
 fn issue494() {
     {
         match stmt.node {
-            hir::StmtExpr(ref expr, id) | hir::StmtSemi(ref expr, id) => {
+            hir::StmtExpr(ref expr, id) |
+            hir::StmtSemi(ref expr, id) => {
                 result.push(StmtRef::Mirror(Box::new(Stmt {
-                    span: stmt.span,
-                    kind: StmtKind::Expr {
-                        scope: cx.tcx.region_maps.node_extent(id),
-                        expr: expr.to_ref(),
-                    },
-                })))
+                                                         span: stmt.span,
+                                                         kind: StmtKind::Expr {
+                                                             scope: cx.tcx
+                                                                 .region_maps
+                                                                 .node_extent(id),
+                                                             expr: expr.to_ref(),
+                                                         },
+                                                     })))
             }
         }
     }
 }
+
+fn issue386() {
+    match foo {
+        BiEq | BiLt | BiLe | BiNe | BiGt | BiGe => true,
+        BiAnd | BiOr | BiAdd | BiSub | BiMul | BiDiv | BiRem | BiBitXor | BiBitAnd | BiBitOr |
+        BiShl | BiShr => false,
+    }
+}
+
+fn guards() {
+    match foo {
+        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa if foooooooooooooo &&
+                                                                      barrrrrrrrrrrr => {}
+        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
+        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa if foooooooooooooo &&
+                                                                      barrrrrrrrrrrr => {}
+        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+            if fooooooooooooooooooooo &&
+               (bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb ||
+                cccccccccccccccccccccccccccccccccccccccc) => {}
+    }
+}
+
+fn issue1371() {
+    Some(match type_ {
+             sfEvtClosed => Closed,
+             sfEvtResized => {
+                 let e = unsafe { *event.size.as_ref() };
+
+                 Resized {
+                     width: e.width,
+                     height: e.height,
+                 }
+             }
+             sfEvtLostFocus => LostFocus,
+             sfEvtGainedFocus => GainedFocus,
+             sfEvtTextEntered => {
+                 TextEntered {
+                     unicode:
+                         unsafe {
+                             ::std::char::from_u32((*event.text.as_ref()).unicode)
+                                 .expect("Invalid unicode encountered on TextEntered event")
+                         },
+                 }
+             }
+             sfEvtKeyPressed => {
+                 let e = unsafe { event.key.as_ref() };
+
+                 KeyPressed {
+                     code: unsafe { ::std::mem::transmute(e.code) },
+                     alt: e.alt.to_bool(),
+                     ctrl: e.control.to_bool(),
+                     shift: e.shift.to_bool(),
+                     system: e.system.to_bool(),
+                 }
+             }
+             sfEvtKeyReleased => {
+                 let e = unsafe { event.key.as_ref() };
+
+                 KeyReleased {
+                     code: unsafe { ::std::mem::transmute(e.code) },
+                     alt: e.alt.to_bool(),
+                     ctrl: e.control.to_bool(),
+                     shift: e.shift.to_bool(),
+                     system: e.system.to_bool(),
+                 }
+             }
+         })
+}
+
+fn issue1395() {
+    let bar = Some(true);
+    let foo = Some(true);
+    let mut x = false;
+    bar.and_then(|_| match foo {
+                     None => None,
+                     Some(b) => {
+                         x = true;
+                         Some(b)
+                     }
+                 });
+}
+
+fn issue1456() {
+    Ok(Recording {
+           artists: match reader
+                     .evaluate(".//mb:recording/mb:artist-credit/mb:name-credit")? {
+               Nodeset(nodeset) => {
+                   let res: Result<Vec<ArtistRef>, ReadError> = nodeset
+                       .iter()
+                       .map(|node| {
+                                XPathNodeReader::new(node, &context)
+                                    .and_then(|r| ArtistRef::from_xml(&r))
+                            })
+                       .collect();
+                   res?
+               }
+               _ => Vec::new(),
+           },
+       })
+}
+
+fn issue1460() {
+    let _ = match foo {
+        REORDER_BUFFER_CHANGE_INTERNAL_SPEC_INSERT => {
+            "internal_spec_insert_internal_spec_insert_internal_spec_insert"
+        }
+        _ => "reorder_something",
+    };
+}
+
+fn issue525() {
+    foobar(f, "{}", match *self {
+        TaskState::Started => "started",
+        TaskState::Success => "success",
+        TaskState::Failed => "failed",
+    });
+}