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