]> git.lizzy.rs Git - rust.git/blob - tests/target/chains.rs
Merge pull request #1017 from marcusklaas/tweak-if-else
[rust.git] / tests / target / chains.rs
1 // rustfmt-single_line_if_else_max_width: 0
2 // Test chain formatting.
3
4 fn main() {
5     // Don't put chains on a single line if it wasn't so in source.
6     let a = b.c
7         .d
8         .1
9         .foo(|x| x + 1);
10
11     bbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccc
12         .ddddddddddddddddddddddddddd();
13
14     bbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccc
15         .ddddddddddddddddddddddddddd
16         .eeeeeeee();
17
18     // Test case where first chain element isn't a path, but is shorter than
19     // the size of a tab.
20     x().y(|| match cond() {
21         true => (),
22         false => (),
23     });
24
25     loong_func().quux(move || if true {
26         1
27     } else {
28         2
29     });
30
31     some_fuuuuuuuuunction().method_call_a(aaaaa, bbbbb, |c| {
32         let x = c;
33         x
34     });
35
36     some_fuuuuuuuuunction()
37         .method_call_a(aaaaa, bbbbb, |c| {
38             let x = c;
39             x
40         })
41         .method_call_b(aaaaa, bbbbb, |c| {
42             let x = c;
43             x
44         });
45
46     fffffffffffffffffffffffffffffffffff(a, {
47         SCRIPT_TASK_ROOT.with(|root| {
48             *root.borrow_mut() = Some(&script_task);
49         });
50     });
51
52     let suuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuum = xxxxxxx.map(|x| x + 5)
53         .map(|x| x / 2)
54         .fold(0, |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 }
137
138 fn try_shorthand() {
139     let x = expr?;
140     let y = expr.kaas()?.test();
141     let loooooooooooooooooooooooooooooooooooooooooong =
142         does_this?.look?.good?.should_we_break?.after_the_first_question_mark?;
143     let yyyy = expr?.another?.another?.another?.another?.another?.another?.another?.another?.test();
144     let zzzz = expr?.another?.another?.another?.another?;
145     let aaa = x??????????????????????????????????????????????????????????????????????????;
146
147     let y = a.very
148         .loooooooooooooooooooooooooooooooooooooong()
149         .chain()
150         .inside()
151         .weeeeeeeeeeeeeee()?
152         .test()
153         .0
154         .x;
155
156     parameterized(f,
157                   substs,
158                   def_id,
159                   Ns::Value,
160                   &[],
161                   |tcx| tcx.lookup_item_type(def_id).generics)?;
162     fooooooooooooooooooooooooooo()?
163         .bar()?
164         .baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz()?;
165 }