]> git.lizzy.rs Git - rust.git/blob - tests/target/chains.rs
b8e47607b8329f3a4e07a43ff3a2e8dddceceb1f
[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         }
72         .method_call()
73         .method_call();
74
75     let y = if cond {
76             val1
77         } else {
78             val2
79         }
80         .method_call();
81
82     {
83         match x {
84             PushParam => {
85                 // params are 1-indexed
86                 stack.push(mparams[match cur.to_digit(10) {
87                                    Some(d) => d as usize - 1,
88                                    None => return Err("bad param number".to_owned()),
89                                }]
90                                .clone());
91             }
92         }
93     }
94
95     if cond {
96             some();
97         } else {
98             none();
99         }
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         }
114         .baz(|| {
115                  force();
116                  multiline();
117              })
118         .quux();
119
120     a +
121     match x {
122             true => "yay!",
123             false => "boo!",
124         }
125         .bar()
126 }
127
128 fn is_replaced_content() -> bool {
129     constellat.send(ConstellationMsg::ViewportConstrained(self.id, constraints)).unwrap();
130 }
131
132 fn issue587() {
133     a.b::<()>(c);
134
135     std::mem::transmute(dl.symbol::<()>("init").unwrap())
136 }
137
138 fn try_shorthand() {
139     let x = expr?;
140     let y = expr.kaas()?.test();
141     let loooooooooooooooooooooooooooooooooooooooooong =
142         does_this?.look?.good?.should_we_break?.after_the_first_question_mark?;
143     let yyyy = expr?.another?.another?.another?.another?.another?.another?.another?.another?.test();
144     let zzzz = expr?.another?.another?.another?.another?;
145     let aaa = x??????????????????????????????????????????????????????????????????????????;
146
147     let y = a.very
148         .loooooooooooooooooooooooooooooooooooooong()
149         .chain()
150         .inside()
151         .weeeeeeeeeeeeeee()?
152         .test()
153         .0
154         .x;
155
156     parameterized(f,
157                   substs,
158                   def_id,
159                   Ns::Value,
160                   &[],
161                   |tcx| tcx.lookup_item_type(def_id).generics)?;
162     fooooooooooooooooooooooooooo()?
163         .bar()?
164         .baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz()?;
165 }
166
167 fn issue_1004() {
168     match *self {
169         ty::ImplOrTraitItem::MethodTraitItem(ref i) => write!(f, "{:?}", i),
170         ty::ImplOrTraitItem::ConstTraitItem(ref i) => write!(f, "{:?}", i),
171         ty::ImplOrTraitItem::TypeTraitItem(ref i) => write!(f, "{:?}", i),
172     }?;
173
174     ty::tls::with(|tcx| {
175                       let tap = ty::Binder(TraitAndProjections(principal, projections));
176                       in_binder(f, tcx, &ty::Binder(""), Some(tap))
177                   })?;
178 }