]> git.lizzy.rs Git - rust.git/blob - tests/target/chains.rs
Merge pull request #2229 from CAD97/patch-2
[rust.git] / tests / target / chains.rs
1 // rustfmt-normalize_comments: true
2 // rustfmt-use_small_heuristics: false
3 // Test chain formatting.
4
5 fn main() {
6     let a = b.c.d.1.foo(|x| x + 1);
7
8     bbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccc.ddddddddddddddddddddddddddd();
9
10     bbbbbbbbbbbbbbbbbbb
11         .ccccccccccccccccccccccccccccccccccccc
12         .ddddddddddddddddddddddddddd
13         .eeeeeeee();
14
15     let f = fooooooooooooooooooooooooooooooooooooooooooooooooooo
16         .baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar;
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 || {
26         if true {
27             1
28         } else {
29             2
30         }
31     });
32
33     some_fuuuuuuuuunction().method_call_a(aaaaa, bbbbb, |c| {
34         let x = c;
35         x
36     });
37
38     some_fuuuuuuuuunction()
39         .method_call_a(aaaaa, bbbbb, |c| {
40             let x = c;
41             x
42         })
43         .method_call_b(aaaaa, bbbbb, |c| {
44             let x = c;
45             x
46         });
47
48     fffffffffffffffffffffffffffffffffff(a, {
49         SCRIPT_TASK_ROOT.with(|root| {
50             *root.borrow_mut() = Some(&script_task);
51         });
52     });
53
54     let suuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuum =
55         xxxxxxx.map(|x| x + 5).map(|x| x / 2).fold(0, |acc, x| acc + x);
56
57     body.fold(Body::new(), |mut body, chunk| {
58         body.extend(chunk);
59         Ok(body)
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
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     }.method_call()
83         .method_call();
84
85     let y = if cond {
86         val1
87     } else {
88         val2
89     }.method_call();
90
91     {
92         match x {
93             PushParam => {
94                 // params are 1-indexed
95                 stack.push(
96                     mparams[match cur.to_digit(10) {
97                                 Some(d) => d as usize - 1,
98                                 None => return Err("bad param number".to_owned()),
99                             }].clone(),
100                 );
101             }
102         }
103     }
104
105     if cond {
106         some();
107     } else {
108         none();
109     }.bar()
110         .baz();
111
112     Foo {
113         x: val,
114     }.baz(|| {
115         force();
116         multiline();
117     })
118         .quux();
119
120     Foo {
121         y: i_am_multi_line,
122         z: ok,
123     }.baz(|| {
124         force();
125         multiline();
126     })
127         .quux();
128
129     a + match x {
130         true => "yay!",
131         false => "boo!",
132     }.bar()
133 }
134
135 fn is_replaced_content() -> bool {
136     constellat.send(ConstellationMsg::ViewportConstrained(self.id, constraints)).unwrap();
137 }
138
139 fn issue587() {
140     a.b::<()>(c);
141
142     std::mem::transmute(dl.symbol::<()>("init").unwrap())
143 }
144
145 fn try_shorthand() {
146     let x = expr?;
147     let y = expr.kaas()?.test();
148     let loooooooooooooooooooooooooooooooooooooooooong =
149         does_this?.look?.good?.should_we_break?.after_the_first_question_mark?;
150     let yyyy = expr?.another?.another?.another?.another?.another?.another?.another?.another?.test();
151     let zzzz = expr?.another?.another?.another?.another?;
152     let aaa = x??????????????????????????????????????????????????????????????????????????;
153
154     let y = a.very
155         .loooooooooooooooooooooooooooooooooooooong()
156         .chain()
157         .inside()
158         .weeeeeeeeeeeeeee()?
159         .test()
160         .0
161         .x;
162
163     parameterized(f, substs, def_id, Ns::Value, &[], |tcx| tcx.lookup_item_type(def_id).generics)?;
164     fooooooooooooooooooooooooooo()?
165         .bar()?
166         .baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz()?;
167 }
168
169 fn issue_1004() {
170     match *self {
171         ty::ImplOrTraitItem::MethodTraitItem(ref i) => write!(f, "{:?}", i),
172         ty::ImplOrTraitItem::ConstTraitItem(ref i) => write!(f, "{:?}", i),
173         ty::ImplOrTraitItem::TypeTraitItem(ref i) => write!(f, "{:?}", i),
174     }?;
175
176     ty::tls::with(|tcx| {
177         let tap = ty::Binder(TraitAndProjections(principal, projections));
178         in_binder(f, tcx, &ty::Binder(""), Some(tap))
179     })?;
180 }
181
182 fn issue1392() {
183     test_method(
184         r#"
185         if foo {
186             a();
187         }
188         else {
189             b();
190         }
191         "#.trim(),
192     );
193 }
194
195 // #2067
196 impl Settings {
197     fn save(&self) -> Result<()> {
198         let mut file = File::create(&settings_path)
199             .chain_err(|| ErrorKind::WriteError(settings_path.clone()))?;
200     }
201 }
202
203 fn issue2126() {
204     {
205         {
206             {
207                 {
208                     {
209                         let x = self.span_from(
210                             sub_span.expect("No span found for struct arant variant"),
211                         );
212                         self.sspanpan_from_span(
213                             sub_span.expect("No span found for struct variant"),
214                         );
215                         let x = self.spanpan_from_span(
216                             sub_span.expect("No span found for struct variant"),
217                         )?;
218                     }
219                 }
220             }
221         }
222     }
223 }
224
225 // #2200
226 impl Foo {
227     pub fn from_ast(diagnostic: &::errors::Handler, attrs: &[ast::Attribute]) -> Attributes {
228         let other_attrs = attrs
229             .iter()
230             .filter_map(|attr| {
231                 attr.with_desugared_doc(|attr| {
232                     if attr.check_name("doc") {
233                         if let Some(mi) = attr.meta() {
234                             if let Some(value) = mi.value_str() {
235                                 doc_strings.push(DocFragment::Include(
236                                     line,
237                                     attr.span,
238                                     filename,
239                                     contents,
240                                 ));
241                             }
242                         }
243                     }
244                 })
245             })
246             .collect();
247     }
248 }