]>
Commit | Line | Data |
---|---|---|
f20569fa XL |
1 | #![allow(clippy::all)] |
2 | #![warn(clippy::pattern_type_mismatch)] | |
3 | ||
4 | fn main() {} | |
5 | ||
6 | fn syntax_match() { | |
7 | let ref_value = &Some(&Some(42)); | |
8 | ||
9 | // not ok | |
10 | match ref_value { | |
11 | Some(_) => (), | |
12 | None => (), | |
13 | } | |
14 | ||
15 | // ok | |
16 | match ref_value { | |
17 | &Some(_) => (), | |
18 | &None => (), | |
19 | } | |
20 | match *ref_value { | |
21 | Some(_) => (), | |
22 | None => (), | |
23 | } | |
24 | } | |
25 | ||
26 | fn syntax_if_let() { | |
27 | let ref_value = &Some(42); | |
28 | ||
29 | // not ok | |
30 | if let Some(_) = ref_value {} | |
31 | ||
32 | // ok | |
33 | if let &Some(_) = ref_value {} | |
34 | if let Some(_) = *ref_value {} | |
35 | } | |
36 | ||
37 | fn syntax_while_let() { | |
38 | let ref_value = &Some(42); | |
39 | ||
40 | // not ok | |
41 | while let Some(_) = ref_value { | |
42 | break; | |
43 | } | |
44 | ||
45 | // ok | |
46 | while let &Some(_) = ref_value { | |
47 | break; | |
48 | } | |
49 | while let Some(_) = *ref_value { | |
50 | break; | |
51 | } | |
52 | } | |
53 | ||
54 | fn syntax_for() { | |
55 | let ref_value = &Some(23); | |
56 | let slice = &[(2, 3), (4, 2)]; | |
57 | ||
58 | // not ok | |
59 | for (_a, _b) in slice.iter() {} | |
60 | ||
61 | // ok | |
62 | for &(_a, _b) in slice.iter() {} | |
63 | } | |
64 | ||
65 | fn syntax_let() { | |
66 | let ref_value = &(2, 3); | |
67 | ||
68 | // not ok | |
69 | let (_n, _m) = ref_value; | |
70 | ||
71 | // ok | |
72 | let &(_n, _m) = ref_value; | |
73 | let (_n, _m) = *ref_value; | |
74 | } | |
75 | ||
76 | fn syntax_fn() { | |
77 | // not ok | |
78 | fn foo((_a, _b): &(i32, i32)) {} | |
79 | ||
80 | // ok | |
81 | fn foo_ok_1(&(_a, _b): &(i32, i32)) {} | |
82 | } | |
83 | ||
84 | fn syntax_closure() { | |
85 | fn foo<F>(f: F) | |
86 | where | |
87 | F: FnOnce(&(i32, i32)), | |
88 | { | |
89 | } | |
90 | ||
91 | // not ok | |
92 | foo(|(_a, _b)| ()); | |
93 | ||
94 | // ok | |
95 | foo(|&(_a, _b)| ()); | |
96 | } | |
97 | ||
98 | fn macro_with_expression() { | |
99 | macro_rules! matching_macro { | |
100 | ($e:expr) => { | |
101 | $e | |
102 | }; | |
103 | } | |
104 | let value = &Some(23); | |
105 | ||
106 | // not ok | |
107 | matching_macro!(match value { | |
108 | Some(_) => (), | |
109 | _ => (), | |
110 | }); | |
111 | ||
112 | // ok | |
113 | matching_macro!(match value { | |
114 | &Some(_) => (), | |
115 | _ => (), | |
116 | }); | |
117 | matching_macro!(match *value { | |
118 | Some(_) => (), | |
119 | _ => (), | |
120 | }); | |
121 | } | |
122 | ||
123 | fn macro_expansion() { | |
124 | macro_rules! matching_macro { | |
125 | ($e:expr) => { | |
126 | // not ok | |
127 | match $e { | |
128 | Some(_) => (), | |
129 | _ => (), | |
130 | } | |
131 | ||
132 | // ok | |
133 | match $e { | |
134 | &Some(_) => (), | |
135 | _ => (), | |
136 | } | |
137 | match *$e { | |
138 | Some(_) => (), | |
139 | _ => (), | |
140 | } | |
141 | }; | |
142 | } | |
143 | ||
144 | let value = &Some(23); | |
145 | matching_macro!(value); | |
146 | } |