2 #![warn(clippy::needless_match)]
3 #![allow(clippy::manual_map)]
16 let _: i32 = match i {
23 let _: &str = match s {
30 fn custom_type_match() {
32 let _: Simple = match se {
33 Simple::A => Simple::A,
34 Simple::B => Simple::B,
35 Simple::C => Simple::C,
36 Simple::D => Simple::D,
39 let _: Simple = match se {
40 Simple::A => Simple::A,
41 Simple::B => Simple::B,
44 // Mingled, don't trigger
45 let _: Simple = match se {
46 Simple::A => Simple::B,
47 Simple::B => Simple::C,
48 Simple::C => Simple::D,
49 Simple::D => Simple::A,
53 fn option_match(x: Option<i32>) {
54 let _: Option<i32> = match x {
58 // Don't trigger, this is the case for manual_map_option
59 let _: Option<i32> = match x {
65 fn func_ret_err<T>(err: T) -> Result<i32, T> {
70 let _: Result<i32, i32> = match Ok(1) {
74 let _: Result<i32, i32> = match func_ret_err(0_i32) {
78 // as ref, don't trigger
79 let res = &func_ret_err(0_i32);
80 let _: Result<&i32, &i32> = match *res {
87 let _ = if let Some(a) = Some(1) { Some(a) } else { None };
92 let _ = if let Some(a) = Some(1) {
100 let _ = if let Some(a) = Some(1) {
108 let _ = if let Some(a) = Some(1) { Some(a) } else { Some(2) };
111 fn if_let_option_result() -> Result<(), ()> {
112 fn f(x: i32) -> Result<Option<i32>, ()> {
116 let _ = if let Some(v) = f(1)? { Some(v) } else { f(2)? };
121 let x: Result<i32, i32> = Ok(1);
122 let _: Result<i32, i32> = if let Err(e) = x { Err(e) } else { x };
123 let _: Result<i32, i32> = if let Ok(val) = x { Ok(val) } else { x };
124 // Input type mismatch, don't trigger
125 #[allow(clippy::question_mark)]
126 let _: Result<i32, i32> = if let Err(e) = Ok(1) { Err(e) } else { x };
129 fn if_let_custom_enum(x: Simple) {
130 let _: Simple = if let Simple::A = x {
132 } else if let Simple::B = x {
134 } else if let Simple::C = x {
141 let _: Simple = if let Simple::A = x {
151 #[derive(Clone, Copy)]
165 let ce = Complex::B(8, false);
169 let _: Complex = match ce {
170 Complex::A(a) => Complex::A(a),
171 Complex::B(a, b) => Complex::B(a, b),
172 Complex::C(a, b, c) => Complex::C(a, b, c),
173 Complex::D(E::VariantA(ea, eb), b) => Complex::D(E::VariantA(ea, eb), b),
174 Complex::D(E::VariantB(ea, eb), b) => Complex::D(E::VariantB(ea, eb), b),
178 let _: Complex = match ce {
179 Complex::A(_) => Complex::A(aa),
180 Complex::B(_, b) => Complex::B(aa, b),
181 Complex::C(_, b, _) => Complex::C(aa, b, 64_f64),
182 Complex::D(e, b) => Complex::D(e, b),
186 let _: Complex = match ce {
187 Complex::A(a) => Complex::A(a),
188 Complex::B(a, _) => Complex::B(a, bb),
189 Complex::C(a, _, _) => Complex::C(a, 32_i32, 64_f64),
195 /// Lint triggered when type coercions happen.
196 /// Do NOT trigger on any of these.
200 impl Trait for Struct {}
202 fn optmap(s: Option<&Struct>) -> Option<&dyn Trait> {
210 let option: Option<&Struct> = None;
211 let _: Option<&dyn Trait> = match option {
216 let _: Option<&dyn Trait> = if true {
225 let result: Result<&Struct, i32> = Err(0);
226 let _: Result<&dyn Trait, i32> = match result {
231 let _: Option<&dyn Trait> = if let Some(s) = option { Some(s) } else { None };
236 fn as_mut(&mut self) -> Result<&mut i32, &mut i32>;
238 impl Tr for Result<i32, i32> {
239 fn as_mut(&mut self) -> Result<&mut i32, &mut i32> {
249 let mut some_bool = true;
273 Some(i) => Some(i + 1),
278 // should not lint (guard has side effects)