]> git.lizzy.rs Git - rust.git/blob - tests/run-make-fulldeps/emit/test-26235.rs
Rollup merge of #106726 - cmorin6:fix-comment-typos, r=Nilstrieb
[rust.git] / tests / run-make-fulldeps / emit / test-26235.rs
1 // Checks for issue #26235
2
3 fn main() {
4     use std::thread;
5
6     type Key = u32;
7     const NUM_THREADS: usize = 2;
8
9     #[derive(Clone,Copy)]
10     struct Stats<S> {
11         upsert: S,
12         delete: S,
13         insert: S,
14         update: S
15     };
16
17     impl<S> Stats<S> where S: Copy {
18         fn dot<B, F, T>(self, s: Stats<T>, f: F) -> Stats<B> where F: Fn(S, T) -> B {
19             let Stats { upsert: u1, delete: d1, insert: i1, update: p1 } = self;
20             let Stats { upsert: u2, delete: d2, insert: i2, update: p2 } = s;
21             Stats { upsert: f(u1, u2), delete: f(d1, d2), insert: f(i1, i2), update: f(p1, p2) }
22         }
23
24         fn new(init: S) -> Self {
25             Stats { upsert: init, delete: init, insert: init, update: init }
26         }
27     }
28
29     fn make_threads() -> Vec<thread::JoinHandle<()>> {
30         let mut t = Vec::with_capacity(NUM_THREADS);
31         for _ in 0..NUM_THREADS {
32             t.push(thread::spawn(move || {}));
33         }
34         t
35     }
36
37     let stats = [Stats::new(0); NUM_THREADS];
38     make_threads();
39
40     {
41         let Stats { ref upsert, ref delete, ref insert, ref update } = stats.iter().fold(
42             Stats::new(0), |res, &s| res.dot(s, |x: Key, y: Key| x.wrapping_add(y)));
43         println!("upserts: {}, deletes: {}, inserts: {}, updates: {}",
44                  upsert, delete, insert, update);
45     }
46 }