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