]> git.lizzy.rs Git - rust.git/blob - tests/target/chains.rs
Merge pull request #2129 from topecongiro/changelog
[rust.git] / tests / target / chains.rs
1 // rustfmt-normalize_comments: true
2 // rustfmt-single_line_if_else_max_width: 0
3 // rustfmt-chain_width: 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     let f = fooooooooooooooooooooooooooooooooooooooooooooooooooo
17         .baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar;
18
19     // Test case where first chain element isn't a path, but is shorter than
20     // the size of a tab.
21     x().y(|| match cond() {
22         true => (),
23         false => (),
24     });
25
26     loong_func().quux(move || {
27         if true {
28             1
29         } else {
30             2
31         }
32     });
33
34     some_fuuuuuuuuunction().method_call_a(aaaaa, bbbbb, |c| {
35         let x = c;
36         x
37     });
38
39     some_fuuuuuuuuunction()
40         .method_call_a(aaaaa, bbbbb, |c| {
41             let x = c;
42             x
43         })
44         .method_call_b(aaaaa, bbbbb, |c| {
45             let x = c;
46             x
47         });
48
49     fffffffffffffffffffffffffffffffffff(a, {
50         SCRIPT_TASK_ROOT.with(|root| {
51             *root.borrow_mut() = Some(&script_task);
52         });
53     });
54
55     let suuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuum =
56         xxxxxxx.map(|x| x + 5).map(|x| x / 2).fold(0, |acc, x| acc + x);
57
58     aaaaaaaaaaaaaaaa
59         .map(|x| {
60             x += 1;
61             x
62         })
63         .filter(some_mod::some_filter)
64 }
65
66 fn floaters() {
67     let z = Foo {
68         field1: val1,
69         field2: val2,
70     };
71
72     let x = Foo {
73         field1: val1,
74         field2: val2,
75     }.method_call()
76         .method_call();
77
78     let y = if cond {
79         val1
80     } else {
81         val2
82     }.method_call();
83
84     {
85         match x {
86             PushParam => {
87                 // params are 1-indexed
88                 stack.push(
89                     mparams[match cur.to_digit(10) {
90                                 Some(d) => d as usize - 1,
91                                 None => return Err("bad param number".to_owned()),
92                             }].clone(),
93                 );
94             }
95         }
96     }
97
98     if cond {
99         some();
100     } else {
101         none();
102     }.bar()
103         .baz();
104
105     Foo { 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| {
156         tcx.lookup_item_type(def_id).generics
157     })?;
158     fooooooooooooooooooooooooooo()?
159         .bar()?
160         .baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz()?;
161 }
162
163 fn issue_1004() {
164     match *self {
165         ty::ImplOrTraitItem::MethodTraitItem(ref i) => write!(f, "{:?}", i),
166         ty::ImplOrTraitItem::ConstTraitItem(ref i) => write!(f, "{:?}", i),
167         ty::ImplOrTraitItem::TypeTraitItem(ref i) => write!(f, "{:?}", i),
168     }?;
169
170     ty::tls::with(|tcx| {
171         let tap = ty::Binder(TraitAndProjections(principal, projections));
172         in_binder(f, tcx, &ty::Binder(""), Some(tap))
173     })?;
174 }
175
176 fn issue1392() {
177     test_method(
178         r#"
179         if foo {
180             a();
181         }
182         else {
183             b();
184         }
185         "#.trim(),
186     );
187 }
188
189 // #2067
190 impl Settings {
191     fn save(&self) -> Result<()> {
192         let mut file = File::create(&settings_path)
193             .chain_err(|| ErrorKind::WriteError(settings_path.clone()))?;
194     }
195 }
196
197 fn issue2126() {
198     {
199         {
200             {
201                 {
202                     {
203                         let x = self.span_from(
204                             sub_span.expect("No span found for struct arant variant"),
205                         );
206                         self.sspanpan_from_span(
207                             sub_span.expect("No span found for struct variant"),
208                         );
209                         let x = self.spanpan_from_span(
210                             sub_span.expect("No span found for struct variant"),
211                         )?;
212                     }
213                 }
214             }
215         }
216     }
217 }