fork/rust

git clone https://git.julia.blue/fork/rust

borsAuto merge of #103046 - JanBeh:PR_clarify_cmp_terminology, r=workingjubilee3bcad65fbf6

master
3.1 KiB156 linesraw
1#![warn(clippy::manual_map)]
2#![allow(
3    clippy::no_effect,
4    clippy::map_identity,
5    clippy::unit_arg,
6    clippy::match_ref_pats,
7    clippy::redundant_pattern_matching,
8    clippy::unnecessary_map_on_constructor,
9    for_loops_over_fallibles,
10    dead_code
11)]
12
13fn main() {
14    Some(0).map(|_| 2);
15
16    Some(0).map(|x| x + 1);
17
18    Some("").map(|x| x.is_empty());
19
20    Some(0).map(|x| !x);
21
22    #[rustfmt::skip]
23    Some(0).map(std::convert::identity);
24
25    Some(&String::new()).map(|x| str::len(x));
26
27    match Some(0) {
28        Some(x) if false => Some(x + 1),
29        _ => None,
30    };
31
32    Some([0, 1]).as_ref().map(|x| x[0]);
33
34    Some(0).map(|x| x * 2);
35
36    Some(String::new()).as_ref().map(|x| x.is_empty());
37
38    Some(String::new()).as_ref().map(|x| x.len());
39
40    Some(0).map(|x| x + x);
41
42    #[warn(clippy::option_map_unit_fn)]
43    match &mut Some(String::new()) {
44        Some(x) => Some(x.push_str("")),
45        None => None,
46    };
47
48    #[allow(clippy::option_map_unit_fn)]
49    {
50        Some(String::new()).as_mut().map(|x| x.push_str(""));
51    }
52
53    Some(String::new()).as_ref().map(|x| x.len());
54
55    Some(String::new()).as_ref().map(|x| x.is_empty());
56
57    Some((0, 1, 2)).map(|(x, y, z)| x + y + z);
58
59    Some([1, 2, 3]).map(|[first, ..]| first);
60
61    Some((String::new(), "test")).as_ref().map(|(x, y)| (y, x));
62
63    match Some((String::new(), 0)) {
64        Some((ref x, y)) => Some((y, x)),
65        None => None,
66    };
67
68    match Some(Some(0)) {
69        Some(Some(_)) | Some(None) => Some(0),
70        None => None,
71    };
72
73    match Some(Some((0, 1))) {
74        Some(Some((x, 1))) => Some(x),
75        _ => None,
76    };
77
78    // #6795
79    fn f1() -> Result<(), ()> {
80        let _ = match Some(Ok(())) {
81            Some(x) => Some(x?),
82            None => None,
83        };
84        Ok(())
85    }
86
87    for &x in Some(Some(true)).iter() {
88        let _ = match x {
89            Some(x) => Some(if x { continue } else { x }),
90            None => None,
91        };
92    }
93
94    // #6797
95    let x1 = (Some(String::new()), 0);
96    let x2 = x1.0;
97    match x2 {
98        Some(x) => Some((x, x1.1)),
99        None => None,
100    };
101
102    struct S1 {
103        x: Option<String>,
104        y: u32,
105    }
106    impl S1 {
107        fn f(self) -> Option<(String, u32)> {
108            match self.x {
109                Some(x) => Some((x, self.y)),
110                None => None,
111            }
112        }
113    }
114
115    // #6811
116    Some(0).map(|x| vec![x]);
117
118    option_env!("").map(String::from);
119
120    // #6819
121    async fn f2(x: u32) -> u32 {
122        x
123    }
124
125    async fn f3() {
126        match Some(0) {
127            Some(x) => Some(f2(x).await),
128            None => None,
129        };
130    }
131
132    // #6847
133    if let Some(_) = Some(0) {
134        Some(0)
135    } else { Some(0).map(|x| x + 1) };
136
137    if true {
138        Some(0)
139    } else { Some(0).map(|x| x + 1) };
140
141    // #6967
142    const fn f4() {
143        match Some(0) {
144            Some(x) => Some(x + 1),
145            None => None,
146        };
147    }
148
149    // #7077
150    let s = &String::new();
151    #[allow(clippy::needless_match)]
152    let _: Option<&str> = match Some(s) {
153        Some(s) => Some(s),
154        None => None,
155    };
156}