]> git.lizzy.rs Git - rust.git/blob - src/tools/rustfmt/tests/source/chains-visual.rs
Rollup merge of #107166 - petrochenkov:nooptable, r=oli-obk
[rust.git] / src / tools / rustfmt / tests / source / chains-visual.rs
1 // rustfmt-indent_style: Visual
2 // Test chain formatting.
3
4 fn main() {
5     // Don't put chains on a single line if it wasn't so in source.
6     let a = b .c
7     .d.1
8                 .foo(|x| x + 1);
9
10     bbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccc
11                        .ddddddddddddddddddddddddddd();
12
13     bbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccc.ddddddddddddddddddddddddddd.eeeeeeee();
14
15     // Test case where first chain element isn't a path, but is shorter than
16     // the size of a tab.
17     x()
18         .y(|| match cond() { true => (), false => () });
19
20     loong_func()
21         .quux(move || if true {
22             1
23         } else {
24             2
25         });
26
27     some_fuuuuuuuuunction()
28         .method_call_a(aaaaa, bbbbb, |c| {
29             let x = c;
30             x
31         });
32
33     some_fuuuuuuuuunction().method_call_a(aaaaa, bbbbb, |c| {
34         let x = c;
35         x
36     }).method_call_b(aaaaa, bbbbb, |c| {
37         let x = c;
38         x
39     });
40
41     fffffffffffffffffffffffffffffffffff(a,
42                                         {
43                                             SCRIPT_TASK_ROOT
44                                             .with(|root| {
45                                                 *root.borrow_mut()  =   Some(&script_task);
46                                             });
47                                         });                                        
48
49     let suuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuum = xxxxxxx
50         .map(|x| x + 5)
51         .map(|x| x / 2)
52         .fold(0, |acc, x| acc + x);
53
54     aaaaaaaaaaaaaaaa.map(|x| {
55                          x += 1;
56                          x
57                      }).filter(some_mod::some_filter)
58 }
59
60 fn floaters() {
61     let z = Foo {
62         field1: val1,
63         field2: val2,
64     };
65
66     let x = Foo {
67         field1: val1,
68         field2: val2,
69     }.method_call().method_call();
70
71     let y = if cond {
72                 val1
73             } else {
74                 val2
75             }
76                 .method_call();
77
78     {
79         match x {
80             PushParam => {
81                 // params are 1-indexed
82                 stack.push(mparams[match cur.to_digit(10) {
83                     Some(d) => d as usize - 1,
84                     None => return Err("bad param number".to_owned()),
85                 }]
86                                .clone());
87             }
88         }
89     }
90
91     if cond { some(); } else { none(); }
92         .bar()
93         .baz();
94
95     Foo { x: val } .baz(|| { force(); multiline();    }) .quux(); 
96
97     Foo { y: i_am_multi_line, z: ok }
98         .baz(|| {
99             force(); multiline();
100         })
101         .quux(); 
102
103     a + match x { true => "yay!", false => "boo!" }.bar()
104 }
105
106 fn is_replaced_content() -> bool {
107     constellat.send(ConstellationMsg::ViewportConstrained(
108             self.id, constraints)).unwrap();
109 }
110
111 fn issue587() {
112     a.b::<()>(c);
113
114     std::mem::transmute(dl.symbol::<()>("init").unwrap())
115 }
116
117 fn issue_1389() {
118     let names = String::from_utf8(names)?.split('|').map(str::to_owned).collect();
119 }
120
121 fn issue1217() -> Result<Mnemonic, Error> {
122 let random_chars: String = OsRng::new()?
123     .gen_ascii_chars()
124     .take(self.bit_length)
125     .collect();
126
127     Ok(Mnemonic::new(&random_chars))
128 }
129
130 fn issue1236(options: Vec<String>) -> Result<Option<String>> {
131 let process = Command::new("dmenu").stdin(Stdio::piped())
132     .stdout(Stdio::piped())
133     .spawn()
134     .chain_err(|| "failed to spawn dmenu")?;
135 }
136
137 fn issue1434() {
138     for _ in 0..100 {
139         let prototype_id = PrototypeIdData::from_reader::<_, B>(&mut self.file_cursor).chain_err(|| {
140             format!("could not read prototype ID at offset {:#010x}",
141                     current_offset)
142         })?;
143     }
144 }
145
146 fn issue2264() {
147     {
148         something.function()
149             .map(|| {
150                 if let a_very_very_very_very_very_very_very_very_long_variable =
151                     compute_this_variable()
152                 {
153                     println!("Hello");
154                 }
155             })
156             .collect();
157     }
158 }