1// Check that we are flagged for ignoring `must_use` parallel adaptors.
2// (unfortunately there's no error code for `unused_must_use`)
3
4macro_rules! must_use {
5 ($( $name:ident #[$expr:meta] )*) => {$(
6 /// First sanity check that the expression is OK.
7 ///
8 /// ```
9 /// #![deny(unused_must_use)]
10 ///
11 /// use rayon::prelude::*;
12 ///
13 /// let v: Vec<_> = (0..100).map(Some).collect();
14 /// let _ =
15 #[$expr]
16 /// ```
17 ///
18 /// Now trigger the `must_use`.
19 ///
20 /// ```compile_fail
21 /// #![deny(unused_must_use)]
22 ///
23 /// use rayon::prelude::*;
24 ///
25 /// let v: Vec<_> = (0..100).map(Some).collect();
26 #[$expr]
27 /// ```
28 mod $name {}
29 )*}
30}
31
32must_use! {
33 step_by /** v.par_iter().step_by(2); */
34 chain /** v.par_iter().chain(&v); */
35 chunks /** v.par_iter().chunks(2); */
36 fold_chunks /** v.par_iter().fold_chunks(2, || 0, |x, _| x); */
37 fold_chunks_with /** v.par_iter().fold_chunks_with(2, 0, |x, _| x); */
38 cloned /** v.par_iter().cloned(); */
39 copied /** v.par_iter().copied(); */
40 enumerate /** v.par_iter().enumerate(); */
41 filter /** v.par_iter().filter(|_| true); */
42 filter_map /** v.par_iter().filter_map(|x| *x); */
43 flat_map /** v.par_iter().flat_map(|x| *x); */
44 flat_map_iter /** v.par_iter().flat_map_iter(|x| *x); */
45 flatten /** v.par_iter().flatten(); */
46 flatten_iter /** v.par_iter().flatten_iter(); */
47 fold /** v.par_iter().fold(|| 0, |x, _| x); */
48 fold_with /** v.par_iter().fold_with(0, |x, _| x); */
49 try_fold /** v.par_iter().try_fold(|| 0, |x, _| Some(x)); */
50 try_fold_with /** v.par_iter().try_fold_with(0, |x, _| Some(x)); */
51 inspect /** v.par_iter().inspect(|_| {}); */
52 interleave /** v.par_iter().interleave(&v); */
53 interleave_shortest /** v.par_iter().interleave_shortest(&v); */
54 intersperse /** v.par_iter().intersperse(&None); */
55 map /** v.par_iter().map(|x| x); */
56 map_with /** v.par_iter().map_with(0, |_, x| x); */
57 map_init /** v.par_iter().map_init(|| 0, |_, x| x); */
58 panic_fuse /** v.par_iter().panic_fuse(); */
59 positions /** v.par_iter().positions(|_| true); */
60 rev /** v.par_iter().rev(); */
61 skip /** v.par_iter().skip(1); */
62 take /** v.par_iter().take(1); */
63 update /** v.par_iter().update(|_| {}); */
64 while_some /** v.par_iter().cloned().while_some(); */
65 with_max_len /** v.par_iter().with_max_len(1); */
66 with_min_len /** v.par_iter().with_min_len(1); */
67 zip /** v.par_iter().zip(&v); */
68 zip_eq /** v.par_iter().zip_eq(&v); */
69}
70