]> git.lizzy.rs Git - rust.git/blob - tests/ui/redundant_pattern_matching_option.fixed
Ignore associated items in trait *implementations* when considering type complexity
[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(
6     unused_must_use,
7     clippy::needless_bool,
8     clippy::match_like_matches_macro,
9     clippy::equatable_if_let,
10     clippy::if_same_then_else
11 )]
12
13 fn main() {
14     if None::<()>.is_none() {}
15
16     if Some(42).is_some() {}
17
18     if Some(42).is_some() {
19         foo();
20     } else {
21         bar();
22     }
23
24     while Some(42).is_some() {}
25
26     while Some(42).is_none() {}
27
28     while None::<()>.is_none() {}
29
30     let mut v = vec![1, 2, 3];
31     while v.pop().is_some() {
32         foo();
33     }
34
35     if None::<i32>.is_none() {}
36
37     if Some(42).is_some() {}
38
39     Some(42).is_some();
40
41     None::<()>.is_none();
42
43     let _ = None::<()>.is_none();
44
45     let opt = Some(false);
46     let _ = if opt.is_some() { true } else { false };
47
48     issue6067();
49
50     let _ = if gen_opt().is_some() {
51         1
52     } else if gen_opt().is_none() {
53         2
54     } else {
55         3
56     };
57 }
58
59 fn gen_opt() -> Option<()> {
60     None
61 }
62
63 fn foo() {}
64
65 fn bar() {}
66
67 // Methods that are unstable const should not be suggested within a const context, see issue #5697.
68 // However, in Rust 1.48.0 the methods `is_some` and `is_none` of `Option` were stabilized as const,
69 // so the following should be linted.
70 const fn issue6067() {
71     if Some(42).is_some() {}
72
73     if None::<()>.is_none() {}
74
75     while Some(42).is_some() {}
76
77     while None::<()>.is_none() {}
78
79     Some(42).is_some();
80
81     None::<()>.is_none();
82 }
83
84 #[allow(clippy::deref_addrof, dead_code)]
85 fn issue7921() {
86     if (&None::<()>).is_none() {}
87     if (&None::<()>).is_none() {}
88 }