rayon/compile_fail/
must_use.rs

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    by_exponential_blocks  /** v.par_iter().by_exponential_blocks(); */
34    by_uniform_blocks   /** v.par_iter().by_uniform_blocks(2); */
35    step_by             /** v.par_iter().step_by(2); */
36    chain               /** v.par_iter().chain(&v); */
37    chunks              /** v.par_iter().chunks(2); */
38    fold_chunks         /** v.par_iter().fold_chunks(2, || 0, |x, _| x); */
39    fold_chunks_with    /** v.par_iter().fold_chunks_with(2, 0, |x, _| x); */
40    cloned              /** v.par_iter().cloned(); */
41    copied              /** v.par_iter().copied(); */
42    enumerate           /** v.par_iter().enumerate(); */
43    filter              /** v.par_iter().filter(|_| true); */
44    filter_map          /** v.par_iter().filter_map(|x| *x); */
45    flat_map            /** v.par_iter().flat_map(|x| *x); */
46    flat_map_iter       /** v.par_iter().flat_map_iter(|x| *x); */
47    flatten             /** v.par_iter().flatten(); */
48    flatten_iter        /** v.par_iter().flatten_iter(); */
49    fold                /** v.par_iter().fold(|| 0, |x, _| x); */
50    fold_with           /** v.par_iter().fold_with(0, |x, _| x); */
51    try_fold            /** v.par_iter().try_fold(|| 0, |x, _| Some(x)); */
52    try_fold_with       /** v.par_iter().try_fold_with(0, |x, _| Some(x)); */
53    inspect             /** v.par_iter().inspect(|_| {}); */
54    interleave          /** v.par_iter().interleave(&v); */
55    interleave_shortest /** v.par_iter().interleave_shortest(&v); */
56    intersperse         /** v.par_iter().intersperse(&None); */
57    map                 /** v.par_iter().map(|x| x); */
58    map_with            /** v.par_iter().map_with(0, |_, x| x); */
59    map_init            /** v.par_iter().map_init(|| 0, |_, x| x); */
60    panic_fuse          /** v.par_iter().panic_fuse(); */
61    positions           /** v.par_iter().positions(|_| true); */
62    rev                 /** v.par_iter().rev(); */
63    skip                /** v.par_iter().skip(1); */
64    take                /** v.par_iter().take(1); */
65    update              /** v.par_iter().update(|_| {}); */
66    while_some          /** v.par_iter().cloned().while_some(); */
67    with_max_len        /** v.par_iter().with_max_len(1); */
68    with_min_len        /** v.par_iter().with_min_len(1); */
69    zip                 /** v.par_iter().zip(&v); */
70    zip_eq              /** v.par_iter().zip_eq(&v); */
71}