1 // rustfmt-use_small_heuristics: Off
2 // Test chain formatting.
3
main()4 fn main() {
5 let a = b.c.d.1.foo(|x| x + 1);
6
7 bbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccc.ddddddddddddddddddddddddddd();
8
9 bbbbbbbbbbbbbbbbbbb
10 .ccccccccccccccccccccccccccccccccccccc
11 .ddddddddddddddddddddddddddd
12 .eeeeeeee();
13
14 let f = fooooooooooooooooooooooooooooooooooooooooooooooooooo
15 .baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar;
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 || {
25 if true {
26 1
27 } else {
28 2
29 }
30 });
31
32 some_fuuuuuuuuunction().method_call_a(aaaaa, bbbbb, |c| {
33 let x = c;
34 x
35 });
36
37 some_fuuuuuuuuunction()
38 .method_call_a(aaaaa, bbbbb, |c| {
39 let x = c;
40 x
41 })
42 .method_call_b(aaaaa, bbbbb, |c| {
43 let x = c;
44 x
45 });
46
47 fffffffffffffffffffffffffffffffffff(a, {
48 SCRIPT_TASK_ROOT.with(|root| {
49 *root.borrow_mut() = Some(&script_task);
50 });
51 });
52
53 let suuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuum =
54 xxxxxxx.map(|x| x + 5).map(|x| x / 2).fold(0, |acc, x| acc + x);
55
56 body.fold(Body::new(), |mut body, chunk| {
57 body.extend(chunk);
58 Ok(body)
59 })
60 .and_then(move |body| {
61 let req = Request::from_parts(parts, body);
62 f(req).map_err(|_| io::Error::new(io::ErrorKind::Other, ""))
63 });
64
65 aaaaaaaaaaaaaaaa
66 .map(|x| {
67 x += 1;
68 x
69 })
70 .filter(some_mod::some_filter)
71 }
72
floaters()73 fn floaters() {
74 let z = Foo {
75 field1: val1,
76 field2: val2,
77 };
78
79 let x = Foo {
80 field1: val1,
81 field2: val2,
82 }
83 .method_call()
84 .method_call();
85
86 let y = if cond {
87 val1
88 } else {
89 val2
90 }
91 .method_call();
92
93 {
94 match x {
95 PushParam => {
96 // params are 1-indexed
97 stack.push(
98 mparams[match cur.to_digit(10) {
99 Some(d) => d as usize - 1,
100 None => return Err("bad param number".to_owned()),
101 }]
102 .clone(),
103 );
104 }
105 }
106 }
107
108 if cond {
109 some();
110 } else {
111 none();
112 }
113 .bar()
114 .baz();
115
116 Foo {
117 x: val,
118 }
119 .baz(|| {
120 force();
121 multiline();
122 })
123 .quux();
124
125 Foo {
126 y: i_am_multi_line,
127 z: ok,
128 }
129 .baz(|| {
130 force();
131 multiline();
132 })
133 .quux();
134
135 a + match x {
136 true => "yay!",
137 false => "boo!",
138 }
139 .bar()
140 }
141
is_replaced_content() -> bool142 fn is_replaced_content() -> bool {
143 constellat.send(ConstellationMsg::ViewportConstrained(self.id, constraints)).unwrap();
144 }
145
issue587()146 fn issue587() {
147 a.b::<()>(c);
148
149 std::mem::transmute(dl.symbol::<()>("init").unwrap())
150 }
151
try_shorthand()152 fn try_shorthand() {
153 let x = expr?;
154 let y = expr.kaas()?.test();
155 let loooooooooooooooooooooooooooooooooooooooooong =
156 does_this?.look?.good?.should_we_break?.after_the_first_question_mark?;
157 let yyyy = expr?.another?.another?.another?.another?.another?.another?.another?.another?.test();
158 let zzzz = expr?.another?.another?.another?.another?;
159 let aaa = x??????????????????????????????????????????????????????????????????????????;
160
161 let y = a
162 .very
163 .loooooooooooooooooooooooooooooooooooooong()
164 .chain()
165 .inside()
166 .weeeeeeeeeeeeeee()?
167 .test()
168 .0
169 .x;
170
171 parameterized(f, substs, def_id, Ns::Value, &[], |tcx| tcx.lookup_item_type(def_id).generics)?;
172 fooooooooooooooooooooooooooo()?
173 .bar()?
174 .baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz()?;
175 }
176
issue_1004()177 fn issue_1004() {
178 match *self {
179 ty::ImplOrTraitItem::MethodTraitItem(ref i) => write!(f, "{:?}", i),
180 ty::ImplOrTraitItem::ConstTraitItem(ref i) => write!(f, "{:?}", i),
181 ty::ImplOrTraitItem::TypeTraitItem(ref i) => write!(f, "{:?}", i),
182 }?;
183
184 ty::tls::with(|tcx| {
185 let tap = ty::Binder(TraitAndProjections(principal, projections));
186 in_binder(f, tcx, &ty::Binder(""), Some(tap))
187 })?;
188 }
189
issue1392()190 fn issue1392() {
191 test_method(
192 r#"
193 if foo {
194 a();
195 }
196 else {
197 b();
198 }
199 "#
200 .trim(),
201 );
202 }
203
204 // #2067
205 impl Settings {
save(&self) -> Result<()>206 fn save(&self) -> Result<()> {
207 let mut file = File::create(&settings_path)
208 .chain_err(|| ErrorKind::WriteError(settings_path.clone()))?;
209 }
210 }
211
issue2126()212 fn issue2126() {
213 {
214 {
215 {
216 {
217 {
218 let x = self
219 .span_from(sub_span.expect("No span found for struct arant variant"));
220 self.sspanpan_from_span(
221 sub_span.expect("No span found for struct variant"),
222 );
223 let x = self.spanpan_from_span(
224 sub_span.expect("No span found for struct variant"),
225 )?;
226 }
227 }
228 }
229 }
230 }
231 }
232
233 // #2200
234 impl Foo {
from_ast(diagnostic: &::errors::Handler, attrs: &[ast::Attribute]) -> Attributes235 pub fn from_ast(diagnostic: &::errors::Handler, attrs: &[ast::Attribute]) -> Attributes {
236 let other_attrs = attrs
237 .iter()
238 .filter_map(|attr| {
239 attr.with_desugared_doc(|attr| {
240 if attr.check_name("doc") {
241 if let Some(mi) = attr.meta() {
242 if let Some(value) = mi.value_str() {
243 doc_strings.push(DocFragment::Include(
244 line, attr.span, filename, contents,
245 ));
246 }
247 }
248 }
249 })
250 })
251 .collect();
252 }
253 }
254
255 // #2415
256 // Avoid orphan in chain
issue2415()257 fn issue2415() {
258 let base_url = (|| {
259 // stuff
260
261 Ok((|| {
262 // stuff
263 Some(value.to_string())
264 })()
265 .ok_or("")?)
266 })()
267 .unwrap_or_else(|_: Box<::std::error::Error>| String::from(""));
268 }
269
270 impl issue_2786 {
thing(&self)271 fn thing(&self) {
272 foo(|a| {
273 println!("a");
274 println!("b");
275 })
276 .bar(|c| {
277 println!("a");
278 println!("b");
279 })
280 .baz(|c| {
281 println!("a");
282 println!("b");
283 })
284 }
285 }
286
issue_2773()287 fn issue_2773() {
288 let bar = Some(0);
289 bar.or_else(|| {
290 // do stuff
291 None
292 })
293 .or_else(|| {
294 // do other stuff
295 None
296 })
297 .and_then(|val| {
298 // do this stuff
299 None
300 });
301 }
302
issue_3034()303 fn issue_3034() {
304 disallowed_headers.iter().any(|header| *header == name)
305 || disallowed_header_prefixes.iter().any(|prefix| name.starts_with(prefix))
306 }
307