]> git.lizzy.rs Git - rust.git/blob - tests/target/match.rs
Merge pull request #358 from eefriedman/rewrite-return
[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     let whatever = match something {
45         /// DOC COMMENT!
46         Some(_) => 42,
47         // Comment on an attribute.
48         #[an_attribute]
49         // Comment after an attribute.
50         None => 0,
51         #[rustfmt_skip]
52         Blurb     =>     {                  }
53     };
54 }
55
56 // Test that a match on an overflow line is laid out properly.
57 fn main() {
58     let sub_span =
59         match xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx {
60             Some(sub_span) => Some(sub_span),
61             None => sub_span,
62         };
63 }
64
65 // Test that one-line bodies align.
66 fn main() {
67     match r {
68         Variableeeeeeeeeeeeeeeeee => ("variable",
69                                       vec!("id", "name", "qualname", "value", "type", "scopeid"),
70                                       true,
71                                       true),
72         Enummmmmmmmmmmmmmmmmmmmm => ("enum",
73                                      vec!("id", "qualname", "scopeid", "value"),
74                                      true,
75                                      true),
76         Variantttttttttttttttttttttttt => ("variant",
77                                            vec!("id",
78                                                 "name",
79                                                 "qualname",
80                                                 "type",
81                                                 "value",
82                                                 "scopeid"),
83                                            true,
84                                            true),
85     }
86 }