]> git.lizzy.rs Git - rust.git/blob - tests/target/chains.rs
Merge pull request #1586 from topecongiro/minor
[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(mparams[match cur.to_digit(10) {
85                                        Some(d) => d as usize - 1,
86                                        None => return Err("bad param number".to_owned()),
87                                    }].clone());
88             }
89         }
90     }
91
92     if cond {
93         some();
94     } else {
95         none();
96     }.bar()
97         .baz();
98
99     Foo { x: val }
100         .baz(|| {
101                  force();
102                  multiline();
103              })
104         .quux();
105
106     Foo {
107         y: i_am_multi_line,
108         z: ok,
109     }.baz(|| {
110               force();
111               multiline();
112           })
113         .quux();
114
115     a +
116     match x {
117         true => "yay!",
118         false => "boo!",
119     }.bar()
120 }
121
122 fn is_replaced_content() -> bool {
123     constellat.send(ConstellationMsg::ViewportConstrained(self.id, constraints)).unwrap();
124 }
125
126 fn issue587() {
127     a.b::<()>(c);
128
129     std::mem::transmute(dl.symbol::<()>("init").unwrap())
130 }
131
132 fn try_shorthand() {
133     let x = expr?;
134     let y = expr.kaas()?.test();
135     let loooooooooooooooooooooooooooooooooooooooooong =
136         does_this?.look?.good?.should_we_break?.after_the_first_question_mark?;
137     let yyyy = expr?.another?.another?.another?.another?.another?.another?.another?.another?.test();
138     let zzzz = expr?.another?.another?.another?.another?;
139     let aaa = x??????????????????????????????????????????????????????????????????????????;
140
141     let y = a.very
142         .loooooooooooooooooooooooooooooooooooooong()
143         .chain()
144         .inside()
145         .weeeeeeeeeeeeeee()?
146         .test()
147         .0
148         .x;
149
150     parameterized(f,
151                   substs,
152                   def_id,
153                   Ns::Value,
154                   &[],
155                   |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 }