]> git.lizzy.rs Git - rust.git/blob - tests/target/match.rs
Merge pull request #216 from marcusklaas/format-fields
[rust.git] / tests / target / match.rs
1 // Match expressions.
2
3 fn foo() {
4     // A match expression.
5     match x {
6         // Some comment.
7         a => foo(),
8         b if 0 < 42 => foo(),
9         c => { // Another comment.
10             // Comment.
11             an_expression;
12             foo()
13         }
14         // Perhaps this should introduce braces?
15         Foo(ref bar) =>
16             aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
17         Pattern1 | Pattern2 | Pattern3 => false,
18         Paternnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn |
19         Paternnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn => {
20             blah
21         }
22         Patternnnnnnnnnnnnnnnnnnn |
23         Patternnnnnnnnnnnnnnnnnnn |
24         Patternnnnnnnnnnnnnnnnnnn |
25         Patternnnnnnnnnnnnnnnnnnn => meh,
26
27         Patternnnnnnnnnnnnnnnnnnn |
28         Patternnnnnnnnnnnnnnnnnnn if looooooooooooooooooong_guard => meh,
29
30         Patternnnnnnnnnnnnnnnnnnnnnnnnn |
31         Patternnnnnnnnnnnnnnnnnnnnnnnnn if looooooooooooooooooooooooooooooooooooooooong_guard =>
32             meh,
33
34         // Test that earlier patterns can take the guard space
35         (aaaa, bbbbb, ccccccc, aaaaa, bbbbbbbb, cccccc, aaaa, bbbbbbbb, cccccc, dddddd) |
36         Patternnnnnnnnnnnnnnnnnnnnnnnnn if loooooooooooooooooooooooooooooooooooooooooong_guard => {}
37
38         _ => {}
39         ast::PathParameters::AngleBracketedParameters(ref data) if data.lifetimes.len() > 0 ||
40                                                                    data.types.len() > 0 ||
41                                                                    data.bindings.len() > 0 => {
42         }
43     }
44
45     let whatever = match something {
46         /// DOC COMMENT!
47         Some(_) => 42,
48         // Comment on an attribute.
49         #[an_attribute]
50         // Comment after an attribute.
51         None => 0,
52         #[rustfmt_skip]
53         Blurb     =>     {                  }
54     };
55 }
56
57 // Test that a match on an overflow line is laid out properly.
58 fn main() {
59     let sub_span =
60         match xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx {
61             Some(sub_span) => Some(sub_span),
62             None => sub_span,
63         };
64 }
65
66 // Test that one-line bodies align.
67 fn main() {
68     match r {
69         Variableeeeeeeeeeeeeeeeee => ("variable",
70                                       vec!("id","name","qualname","value","type","scopeid"),
71                                       true,
72                                       true),
73         Enummmmmmmmmmmmmmmmmmmmm => ("enum", vec!("id","qualname","scopeid","value"), true, true),
74         Variantttttttttttttttttttttttt => ("variant",
75                                            vec!("id","name","qualname","type","value","scopeid"),
76                                            true,
77                                            true),
78     }
79 }