]> git.lizzy.rs Git - rust.git/blob - tests/target/chains.rs
Fix a test target
[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     aaaaaaaaaaaaaaaa
58         .map(|x| {
59             x += 1;
60             x
61         })
62         .filter(some_mod::some_filter)
63 }
64
65 fn floaters() {
66     let z = Foo {
67         field1: val1,
68         field2: val2,
69     };
70
71     let x = Foo {
72         field1: val1,
73         field2: val2,
74     }.method_call()
75         .method_call();
76
77     let y = if cond {
78         val1
79     } else {
80         val2
81     }.method_call();
82
83     {
84         match x {
85             PushParam => {
86                 // params are 1-indexed
87                 stack.push(
88                     mparams[match cur.to_digit(10) {
89                                 Some(d) => d as usize - 1,
90                                 None => return Err("bad param number".to_owned()),
91                             }].clone(),
92                 );
93             }
94         }
95     }
96
97     if cond {
98         some();
99     } else {
100         none();
101     }.bar()
102         .baz();
103
104     Foo {
105         x: val,
106     }.baz(|| {
107         force();
108         multiline();
109     })
110         .quux();
111
112     Foo {
113         y: i_am_multi_line,
114         z: ok,
115     }.baz(|| {
116         force();
117         multiline();
118     })
119         .quux();
120
121     a + match x {
122         true => "yay!",
123         false => "boo!",
124     }.bar()
125 }
126
127 fn is_replaced_content() -> bool {
128     constellat.send(ConstellationMsg::ViewportConstrained(self.id, constraints)).unwrap();
129 }
130
131 fn issue587() {
132     a.b::<()>(c);
133
134     std::mem::transmute(dl.symbol::<()>("init").unwrap())
135 }
136
137 fn try_shorthand() {
138     let x = expr?;
139     let y = expr.kaas()?.test();
140     let loooooooooooooooooooooooooooooooooooooooooong =
141         does_this?.look?.good?.should_we_break?.after_the_first_question_mark?;
142     let yyyy = expr?.another?.another?.another?.another?.another?.another?.another?.another?.test();
143     let zzzz = expr?.another?.another?.another?.another?;
144     let aaa = x??????????????????????????????????????????????????????????????????????????;
145
146     let y = a.very
147         .loooooooooooooooooooooooooooooooooooooong()
148         .chain()
149         .inside()
150         .weeeeeeeeeeeeeee()?
151         .test()
152         .0
153         .x;
154
155     parameterized(f, substs, def_id, Ns::Value, &[], |tcx| tcx.lookup_item_type(def_id).generics)?;
156     fooooooooooooooooooooooooooo()?
157         .bar()?
158         .baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz()?;
159 }
160
161 fn issue_1004() {
162     match *self {
163         ty::ImplOrTraitItem::MethodTraitItem(ref i) => write!(f, "{:?}", i),
164         ty::ImplOrTraitItem::ConstTraitItem(ref i) => write!(f, "{:?}", i),
165         ty::ImplOrTraitItem::TypeTraitItem(ref i) => write!(f, "{:?}", i),
166     }?;
167
168     ty::tls::with(|tcx| {
169         let tap = ty::Binder(TraitAndProjections(principal, projections));
170         in_binder(f, tcx, &ty::Binder(""), Some(tap))
171     })?;
172 }
173
174 fn issue1392() {
175     test_method(
176         r#"
177         if foo {
178             a();
179         }
180         else {
181             b();
182         }
183         "#.trim(),
184     );
185 }
186
187 // #2067
188 impl Settings {
189     fn save(&self) -> Result<()> {
190         let mut file = File::create(&settings_path)
191             .chain_err(|| ErrorKind::WriteError(settings_path.clone()))?;
192     }
193 }
194
195 fn issue2126() {
196     {
197         {
198             {
199                 {
200                     {
201                         let x = self.span_from(
202                             sub_span.expect("No span found for struct arant variant"),
203                         );
204                         self.sspanpan_from_span(
205                             sub_span.expect("No span found for struct variant"),
206                         );
207                         let x = self.spanpan_from_span(
208                             sub_span.expect("No span found for struct variant"),
209                         )?;
210                     }
211                 }
212             }
213         }
214     }
215 }
216
217 // #2200
218 impl Foo {
219     pub fn from_ast(diagnostic: &::errors::Handler, attrs: &[ast::Attribute]) -> Attributes {
220         let other_attrs = attrs
221             .iter()
222             .filter_map(|attr| {
223                 attr.with_desugared_doc(|attr| {
224                     if attr.check_name("doc") {
225                         if let Some(mi) = attr.meta() {
226                             if let Some(value) = mi.value_str() {
227                                 doc_strings.push(DocFragment::Include(
228                                     line,
229                                     attr.span,
230                                     filename,
231                                     contents,
232                                 ));
233                             }
234                         }
235                     }
236                 })
237             })
238             .collect();
239     }
240 }