]> git.lizzy.rs Git - rust.git/blob - src/tools/rustfmt/tests/target/chains-visual.rs
Rollup merge of #85326 - infinity0:fix-cross-compile-tools, r=Mark-Simulacrum
[rust.git] / src / tools / rustfmt / tests / target / 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.d.1.foo(|x| x + 1);
7
8     bbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccc
9                        .ddddddddddddddddddddddddddd();
10
11     bbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccc
12                        .ddddddddddddddddddddddddddd
13                        .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().y(|| match cond() {
18            true => (),
19            false => (),
20        });
21
22     loong_func().quux(move || if true { 1 } else { 2 });
23
24     some_fuuuuuuuuunction().method_call_a(aaaaa, bbbbb, |c| {
25                                let x = c;
26                                x
27                            });
28
29     some_fuuuuuuuuunction().method_call_a(aaaaa, bbbbb, |c| {
30                                let x = c;
31                                x
32                            })
33                            .method_call_b(aaaaa, bbbbb, |c| {
34                                let x = c;
35                                x
36                            });
37
38     fffffffffffffffffffffffffffffffffff(a, {
39         SCRIPT_TASK_ROOT.with(|root| {
40                             *root.borrow_mut() = Some(&script_task);
41                         });
42     });
43
44     let suuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuum =
45         xxxxxxx.map(|x| x + 5)
46                .map(|x| x / 2)
47                .fold(0, |acc, x| acc + x);
48
49     aaaaaaaaaaaaaaaa.map(|x| {
50                         x += 1;
51                         x
52                     })
53                     .filter(some_mod::some_filter)
54 }
55
56 fn floaters() {
57     let z = Foo { field1: val1,
58                   field2: val2 };
59
60     let x = Foo { field1: val1,
61                   field2: val2 }.method_call()
62                                 .method_call();
63
64     let y = if cond { val1 } else { val2 }.method_call();
65
66     {
67         match x {
68             PushParam => {
69                 // params are 1-indexed
70                 stack.push(mparams[match cur.to_digit(10) {
71                                        Some(d) => d as usize - 1,
72                                        None => return Err("bad param number".to_owned()),
73                                    }].clone());
74             }
75         }
76     }
77
78     if cond {
79         some();
80     } else {
81         none();
82     }.bar()
83      .baz();
84
85     Foo { x: val }.baz(|| {
86                       force();
87                       multiline();
88                   })
89                   .quux();
90
91     Foo { y: i_am_multi_line,
92           z: ok }.baz(|| {
93                      force();
94                      multiline();
95                  })
96                  .quux();
97
98     a + match x {
99             true => "yay!",
100             false => "boo!",
101         }.bar()
102 }
103
104 fn is_replaced_content() -> bool {
105     constellat.send(ConstellationMsg::ViewportConstrained(self.id, constraints))
106               .unwrap();
107 }
108
109 fn issue587() {
110     a.b::<()>(c);
111
112     std::mem::transmute(dl.symbol::<()>("init").unwrap())
113 }
114
115 fn issue_1389() {
116     let names = String::from_utf8(names)?.split('|')
117                                          .map(str::to_owned)
118                                          .collect();
119 }
120
121 fn issue1217() -> Result<Mnemonic, Error> {
122     let random_chars: String = OsRng::new()?.gen_ascii_chars()
123                                             .take(self.bit_length)
124                                             .collect();
125
126     Ok(Mnemonic::new(&random_chars))
127 }
128
129 fn issue1236(options: Vec<String>) -> Result<Option<String>> {
130     let process = Command::new("dmenu").stdin(Stdio::piped())
131                                        .stdout(Stdio::piped())
132                                        .spawn()
133                                        .chain_err(|| "failed to spawn dmenu")?;
134 }
135
136 fn issue1434() {
137     for _ in 0..100 {
138         let prototype_id =
139             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 }