]> git.lizzy.rs Git - rust.git/blob - tests/target/chains.rs
Merge pull request #926 from rust-lang-nursery/closures
[rust.git] / tests / target / chains.rs
1 // Test chain formatting.
2
3 fn main() {
4     // Don't put chains on a single line if it wasn't so in source.
5     let a = b.c
6              .d
7              .1
8              .foo(|x| x + 1);
9
10     bbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccc
11                        .ddddddddddddddddddddddddddd();
12
13     bbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccc
14                        .ddddddddddddddddddddddddddd
15                        .eeeeeeee();
16
17     // Test case where first chain element isn't a path, but is shorter than
18     // the size of a tab.
19     x().y(|| match cond() {
20         true => (),
21         false => (),
22     });
23
24     loong_func().quux(move || if true {
25         1
26     } else {
27         2
28     });
29
30     some_fuuuuuuuuunction().method_call_a(aaaaa, bbbbb, |c| {
31         let x = c;
32         x
33     });
34
35     some_fuuuuuuuuunction()
36         .method_call_a(aaaaa, bbbbb, |c| {
37             let x = c;
38             x
39         })
40         .method_call_b(aaaaa, bbbbb, |c| {
41             let x = c;
42             x
43         });
44
45     fffffffffffffffffffffffffffffffffff(a, {
46         SCRIPT_TASK_ROOT.with(|root| {
47             *root.borrow_mut() = Some(&script_task);
48         });
49     });
50
51     let suuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuum = xxxxxxx.map(|x| x + 5)
52                                                                           .map(|x| x / 2)
53                                                                           .fold(0,
54                                                                                 |acc, x| acc + x);
55
56     aaaaaaaaaaaaaaaa.map(|x| {
57                         x += 1;
58                         x
59                     })
60                     .filter(some_mod::some_filter)
61 }
62
63 fn floaters() {
64     let z = Foo {
65         field1: val1,
66         field2: val2,
67     };
68
69     let x = Foo {
70                 field1: val1,
71                 field2: val2,
72             }
73             .method_call()
74             .method_call();
75
76     let y = if cond {
77                 val1
78             } else {
79                 val2
80             }
81             .method_call();
82
83     {
84         match x {
85             PushParam => {
86                 // params are 1-indexed
87                 stack.push(mparams[match cur.to_digit(10) {
88                                Some(d) => d as usize - 1,
89                                None => return Err("bad param number".to_owned()),
90                            }]
91                            .clone());
92             }
93         }
94     }
95
96     if cond {
97         some();
98     } else {
99         none();
100     }
101     .bar()
102     .baz();
103
104     Foo { x: val }
105         .baz(|| {
106             // force multiline
107         })
108         .quux();
109
110     Foo {
111         y: i_am_multi_line,
112         z: ok,
113     }
114     .baz(|| {
115         // force multiline
116     })
117     .quux();
118
119     a +
120     match x {
121         true => "yay!",
122         false => "boo!",
123     }
124     .bar()
125 }
126
127 fn is_replaced_content() -> bool {
128     constellat.send(ConstellationMsg::ViewportConstrained(self.id, constraints))
129               .unwrap();
130 }
131
132 fn issue587() {
133     a.b::<()>(c);
134
135     std::mem::transmute(dl.symbol::<()>("init").unwrap())
136 }