]> git.lizzy.rs Git - rust.git/blob - tests/source/chains.rs
Don't put a newline before `?` when it is the second sub-expression in a chain (...
[rust.git] / tests / source / chains.rs
1 // Test chain formatting.
2
3 fn main() {
4     // Don't put chains on a single line if it wasn't so in source.
5     let a = b .c
6     .d.1
7                 .foo(|x| x + 1);
8
9     bbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccc
10                        .ddddddddddddddddddddddddddd();
11
12     bbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccc.ddddddddddddddddddddddddddd.eeeeeeee();
13
14     // Test case where first chain element isn't a path, but is shorter than
15     // the size of a tab.
16     x()
17         .y(|| match cond() { true => (), false => () });
18
19     loong_func()
20         .quux(move || if true {
21             1
22         } else {
23             2
24         });
25
26     some_fuuuuuuuuunction()
27         .method_call_a(aaaaa, bbbbb, |c| {
28             let x = c;
29             x
30         });
31
32     some_fuuuuuuuuunction().method_call_a(aaaaa, bbbbb, |c| {
33         let x = c;
34         x
35     }).method_call_b(aaaaa, bbbbb, |c| {
36         let x = c;
37         x
38     });
39
40     fffffffffffffffffffffffffffffffffff(a,
41                                         {
42                                             SCRIPT_TASK_ROOT
43                                             .with(|root| {
44                                                 *root.borrow_mut()  =   Some(&script_task);
45                                             });
46                                         });                                        
47
48     let suuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuum = xxxxxxx
49         .map(|x| x + 5)
50         .map(|x| x / 2)
51         .fold(0, |acc, x| acc + x);
52
53     aaaaaaaaaaaaaaaa.map(|x| {
54                          x += 1;
55                          x
56                      }).filter(some_mod::some_filter)
57 }
58
59 fn floaters() {
60     let z = Foo {
61         field1: val1,
62         field2: val2,
63     };
64
65     let x = Foo {
66         field1: val1,
67         field2: val2,
68     }.method_call().method_call();
69
70     let y = if cond {
71                 val1
72             } else {
73                 val2
74             }
75                 .method_call();
76
77     {
78         match x {
79             PushParam => {
80                 // params are 1-indexed
81                 stack.push(mparams[match cur.to_digit(10) {
82                     Some(d) => d as usize - 1,
83                     None => return Err("bad param number".to_owned()),
84                 }]
85                                .clone());
86             }
87         }
88     }
89
90     if cond { some(); } else { none(); }
91         .bar()
92         .baz();
93
94     Foo { x: val } .baz(|| { /*force multiline    */    }) .quux(); 
95
96     Foo { y: i_am_multi_line, z: ok }
97         .baz(|| {
98             // force multiline
99         })
100         .quux(); 
101
102     a + match x { true => "yay!", false => "boo!" }.bar()
103 }
104
105 fn is_replaced_content() -> bool {
106     constellat.send(ConstellationMsg::ViewportConstrained(
107             self.id, constraints)).unwrap();
108 }
109
110 fn issue587() {
111     a.b::<()>(c);
112
113     std::mem::transmute(dl.symbol::<()>("init").unwrap())
114 }
115
116 fn try_shorthand() {
117     let x = expr?;
118     let y = expr.kaas()?.test();
119     let loooooooooooooooooooooooooooooooooooooooooong = does_this?.look?.good?.should_we_break?.after_the_first_question_mark?;
120     let yyyy = expr?.another?.another?.another?.another?.another?.another?.another?.another?.test();
121     let zzzz = expr?.another?.another?.another?.another?;
122     let aaa =  x ????????????  ?????????????? ???? ?????  ?????????????? ?????????  ?????????????? ??;
123
124     let y = a.very .loooooooooooooooooooooooooooooooooooooong()  .chain()
125              .inside()          .weeeeeeeeeeeeeee()? .test()  .0
126         .x;
127
128                 parameterized(f,
129                               substs,
130                               def_id,
131                               Ns::Value,
132                               &[],
133                               |tcx| tcx.lookup_item_type(def_id).generics)?;
134     fooooooooooooooooooooooooooo()?.bar()?.baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz()?;
135 }