]> git.lizzy.rs Git - rust.git/blob - tests/ui/redundant_pattern_matching_option.fixed
Merge remote-tracking branch 'upstream/master' into rustup
[rust.git] / tests / ui / redundant_pattern_matching_option.fixed
1 // run-rustfix
2
3 #![warn(clippy::all)]
4 #![warn(clippy::redundant_pattern_matching)]
5 #![allow(unused_must_use, clippy::needless_bool, clippy::match_like_matches_macro)]
6
7 fn main() {
8     if None::<()>.is_none() {}
9
10     if Some(42).is_some() {}
11
12     if Some(42).is_some() {
13         foo();
14     } else {
15         bar();
16     }
17
18     while Some(42).is_some() {}
19
20     while Some(42).is_none() {}
21
22     while None::<()>.is_none() {}
23
24     let mut v = vec![1, 2, 3];
25     while v.pop().is_some() {
26         foo();
27     }
28
29     if None::<i32>.is_none() {}
30
31     if Some(42).is_some() {}
32
33     Some(42).is_some();
34
35     None::<()>.is_none();
36
37     let _ = None::<()>.is_none();
38
39     let opt = Some(false);
40     let x = if opt.is_some() { true } else { false };
41     takes_bool(x);
42
43     issue6067();
44
45     let _ = if gen_opt().is_some() {
46         1
47     } else if gen_opt().is_none() {
48         2
49     } else {
50         3
51     };
52 }
53
54 fn gen_opt() -> Option<()> {
55     None
56 }
57
58 fn takes_bool(_: bool) {}
59
60 fn foo() {}
61
62 fn bar() {}
63
64 // Methods that are unstable const should not be suggested within a const context, see issue #5697.
65 // However, in Rust 1.48.0 the methods `is_some` and `is_none` of `Option` were stabilized as const,
66 // so the following should be linted.
67 const fn issue6067() {
68     if Some(42).is_some() {}
69
70     if None::<()>.is_none() {}
71
72     while Some(42).is_some() {}
73
74     while None::<()>.is_none() {}
75
76     Some(42).is_some();
77
78     None::<()>.is_none();
79 }