]> git.lizzy.rs Git - rust.git/blob - tests/target/chains.rs
Merge pull request #1326 from durka/assoc-type-density
[rust.git] / tests / target / chains.rs
1 // rustfmt-normalize_comments: true
2 // rustfmt-single_line_if_else_max_width: 0
3 // Test chain formatting.
4
5 fn main() {
6     // Don't put chains on a single line if it wasn't so in source.
7     let a = b.c
8         .d
9         .1
10         .foo(|x| x + 1);
11
12     bbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccc
13         .ddddddddddddddddddddddddddd();
14
15     bbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccc
16         .ddddddddddddddddddddddddddd
17         .eeeeeeee();
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 = xxxxxxx.map(|x| x + 5)
52         .map(|x| x / 2)
53         .fold(0, |acc, x| acc + x);
54
55     aaaaaaaaaaaaaaaa.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))
130         .unwrap();
131 }
132
133 fn issue587() {
134     a.b::<()>(c);
135
136     std::mem::transmute(dl.symbol::<()>("init").unwrap())
137 }
138
139 fn try_shorthand() {
140     let x = expr?;
141     let y = expr.kaas()?.test();
142     let loooooooooooooooooooooooooooooooooooooooooong =
143         does_this?.look?.good?.should_we_break?.after_the_first_question_mark?;
144     let yyyy = expr?.another?.another?.another?.another?.another?.another?.another?.another?.test();
145     let zzzz = expr?.another?.another?.another?.another?;
146     let aaa = x??????????????????????????????????????????????????????????????????????????;
147
148     let y = a.very
149         .loooooooooooooooooooooooooooooooooooooong()
150         .chain()
151         .inside()
152         .weeeeeeeeeeeeeee()?
153         .test()
154         .0
155         .x;
156
157     parameterized(f,
158                   substs,
159                   def_id,
160                   Ns::Value,
161                   &[],
162                   |tcx| tcx.lookup_item_type(def_id).generics)?;
163     fooooooooooooooooooooooooooo()?
164         .bar()?
165         .baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz()?;
166 }
167
168 fn issue_1004() {
169     match *self {
170         ty::ImplOrTraitItem::MethodTraitItem(ref i) => write!(f, "{:?}", i),
171         ty::ImplOrTraitItem::ConstTraitItem(ref i) => write!(f, "{:?}", i),
172         ty::ImplOrTraitItem::TypeTraitItem(ref i) => write!(f, "{:?}", i),
173     }?;
174
175     ty::tls::with(|tcx| {
176                       let tap = ty::Binder(TraitAndProjections(principal, projections));
177                       in_binder(f, tcx, &ty::Binder(""), Some(tap))
178                   })?;
179 }