]> git.lizzy.rs Git - rust.git/blob - tests/target/chains.rs
Merge pull request #1487 from topecongiro/issue1470
[rust.git] / tests / target / chains.rs
1 // rustfmt-normalize_comments: true
2 // rustfmt-single_line_if_else_max_width: 0
3 // rustfmt-chain_one_line_max: 100
4 // Test chain formatting.
5
6 fn main() {
7     let a = b.c.d.1.foo(|x| x + 1);
8
9     bbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccc.ddddddddddddddddddddddddddd();
10
11     bbbbbbbbbbbbbbbbbbb
12         .ccccccccccccccccccccccccccccccccccccc
13         .ddddddddddddddddddddddddddd
14         .eeeeeeee();
15
16     // Test case where first chain element isn't a path, but is shorter than
17     // the size of a tab.
18     x().y(|| match cond() {
19               true => (),
20               false => (),
21           });
22
23     loong_func().quux(move || if true {
24                           1
25                       } else {
26                           2
27                       });
28
29     some_fuuuuuuuuunction().method_call_a(aaaaa, bbbbb, |c| {
30         let x = c;
31         x
32     });
33
34     some_fuuuuuuuuunction()
35         .method_call_a(aaaaa, bbbbb, |c| {
36             let x = c;
37             x
38         })
39         .method_call_b(aaaaa, bbbbb, |c| {
40             let x = c;
41             x
42         });
43
44     fffffffffffffffffffffffffffffffffff(a, {
45         SCRIPT_TASK_ROOT.with(|root| { *root.borrow_mut() = Some(&script_task); });
46     });
47
48     let suuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuum =
49         xxxxxxx.map(|x| x + 5).map(|x| x / 2).fold(0, |acc, x| acc + x);
50
51     aaaaaaaaaaaaaaaa
52         .map(|x| {
53                  x += 1;
54                  x
55              })
56         .filter(some_mod::some_filter)
57 }
58
59 fn floaters() {
60     let z = Foo {
61         field1: val1,
62         field2: val2,
63     };
64
65     let x = Foo {
66             field1: val1,
67             field2: val2,
68         }
69         .method_call()
70         .method_call();
71
72     let y = if cond {
73             val1
74         } else {
75             val2
76         }
77         .method_call();
78
79     {
80         match x {
81             PushParam => {
82                 // params are 1-indexed
83                 stack.push(mparams[match cur.to_digit(10) {
84                                    Some(d) => d as usize - 1,
85                                    None => return Err("bad param number".to_owned()),
86                                }]
87                                .clone());
88             }
89         }
90     }
91
92     if cond {
93             some();
94         } else {
95             none();
96         }
97         .bar()
98         .baz();
99
100     Foo { x: val }
101         .baz(|| {
102                  force();
103                  multiline();
104              })
105         .quux();
106
107     Foo {
108             y: i_am_multi_line,
109             z: ok,
110         }
111         .baz(|| {
112                  force();
113                  multiline();
114              })
115         .quux();
116
117     a +
118     match x {
119             true => "yay!",
120             false => "boo!",
121         }
122         .bar()
123 }
124
125 fn is_replaced_content() -> bool {
126     constellat.send(ConstellationMsg::ViewportConstrained(self.id, constraints)).unwrap();
127 }
128
129 fn issue587() {
130     a.b::<()>(c);
131
132     std::mem::transmute(dl.symbol::<()>("init").unwrap())
133 }
134
135 fn try_shorthand() {
136     let x = expr?;
137     let y = expr.kaas()?.test();
138     let loooooooooooooooooooooooooooooooooooooooooong =
139         does_this?.look?.good?.should_we_break?.after_the_first_question_mark?;
140     let yyyy = expr?.another?.another?.another?.another?.another?.another?.another?.another?.test();
141     let zzzz = expr?.another?.another?.another?.another?;
142     let aaa = x??????????????????????????????????????????????????????????????????????????;
143
144     let y = a.very
145         .loooooooooooooooooooooooooooooooooooooong()
146         .chain()
147         .inside()
148         .weeeeeeeeeeeeeee()?
149         .test()
150         .0
151         .x;
152
153     parameterized(f,
154                   substs,
155                   def_id,
156                   Ns::Value,
157                   &[],
158                   |tcx| tcx.lookup_item_type(def_id).generics)?;
159     fooooooooooooooooooooooooooo()?
160         .bar()?
161         .baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz()?;
162 }
163
164 fn issue_1004() {
165     match *self {
166         ty::ImplOrTraitItem::MethodTraitItem(ref i) => write!(f, "{:?}", i),
167         ty::ImplOrTraitItem::ConstTraitItem(ref i) => write!(f, "{:?}", i),
168         ty::ImplOrTraitItem::TypeTraitItem(ref i) => write!(f, "{:?}", i),
169     }?;
170
171     ty::tls::with(|tcx| {
172                       let tap = ty::Binder(TraitAndProjections(principal, projections));
173                       in_binder(f, tcx, &ty::Binder(""), Some(tap))
174                   })?;
175 }