]> git.lizzy.rs Git - rust.git/blob - tests/target/chains.rs
Reformat tests
[rust.git] / tests / target / chains.rs
1 // rustfmt-normalize_comments: true
2 // rustfmt-single_line_if_else_max_width: 0
3 // rustfmt-chain_one_line_max: 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 || if true {
27         1
28     } else {
29         2
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| { *root.borrow_mut() = Some(&script_task); });
49     });
50
51     let suuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuum =
52         xxxxxxx.map(|x| x + 5).map(|x| x / 2).fold(0, |acc, x| acc + x);
53
54     aaaaaaaaaaaaaaaa
55         .map(|x| {
56             x += 1;
57             x
58         })
59         .filter(some_mod::some_filter)
60 }
61
62 fn floaters() {
63     let z = Foo {
64         field1: val1,
65         field2: val2,
66     };
67
68     let x = Foo {
69         field1: val1,
70         field2: val2,
71     }.method_call()
72         .method_call();
73
74     let y = if cond {
75         val1
76     } else {
77         val2
78     }.method_call();
79
80     {
81         match x {
82             PushParam => {
83                 // params are 1-indexed
84                 stack.push(
85                     mparams[match cur.to_digit(10) {
86                                 Some(d) => d as usize - 1,
87                                 None => return Err("bad param number".to_owned()),
88                             }].clone(),
89                 );
90             }
91         }
92     }
93
94     if cond {
95         some();
96     } else {
97         none();
98     }.bar()
99         .baz();
100
101     Foo { x: val }
102         .baz(|| {
103             force();
104             multiline();
105         })
106         .quux();
107
108     Foo {
109         y: i_am_multi_line,
110         z: ok,
111     }.baz(|| {
112         force();
113         multiline();
114     })
115         .quux();
116
117     a +
118         match x {
119             true => "yay!",
120             false => "boo!",
121         }.bar()
122 }
123
124 fn is_replaced_content() -> bool {
125     constellat.send(ConstellationMsg::ViewportConstrained(self.id, constraints)).unwrap();
126 }
127
128 fn issue587() {
129     a.b::<()>(c);
130
131     std::mem::transmute(dl.symbol::<()>("init").unwrap())
132 }
133
134 fn try_shorthand() {
135     let x = expr?;
136     let y = expr.kaas()?.test();
137     let loooooooooooooooooooooooooooooooooooooooooong =
138         does_this?.look?.good?.should_we_break?.after_the_first_question_mark?;
139     let yyyy = expr?.another?.another?.another?.another?.another?.another?.another?.another?.test();
140     let zzzz = expr?.another?.another?.another?.another?;
141     let aaa = x??????????????????????????????????????????????????????????????????????????;
142
143     let y = a.very
144         .loooooooooooooooooooooooooooooooooooooong()
145         .chain()
146         .inside()
147         .weeeeeeeeeeeeeee()?
148         .test()
149         .0
150         .x;
151
152     parameterized(f, substs, def_id, Ns::Value, &[], |tcx| {
153         tcx.lookup_item_type(def_id).generics
154     })?;
155     fooooooooooooooooooooooooooo()?
156         .bar()?
157         .baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz()?;
158 }
159
160 fn issue_1004() {
161     match *self {
162         ty::ImplOrTraitItem::MethodTraitItem(ref i) => write!(f, "{:?}", i),
163         ty::ImplOrTraitItem::ConstTraitItem(ref i) => write!(f, "{:?}", i),
164         ty::ImplOrTraitItem::TypeTraitItem(ref i) => write!(f, "{:?}", i),
165     }?;
166
167     ty::tls::with(|tcx| {
168         let tap = ty::Binder(TraitAndProjections(principal, projections));
169         in_binder(f, tcx, &ty::Binder(""), Some(tap))
170     })?;
171 }