2 #![warn(clippy::needless_match)]
3 #![allow(clippy::manual_map)]
21 fn custom_type_match() {
25 let _: Simple = match se {
26 Simple::A => Simple::A,
27 Simple::B => Simple::B,
30 // Mingled, don't trigger
31 let _: Simple = match se {
32 Simple::A => Simple::B,
33 Simple::B => Simple::C,
34 Simple::C => Simple::D,
35 Simple::D => Simple::A,
39 fn option_match(x: Option<i32>) {
40 let _: Option<i32> = x;
41 // Don't trigger, this is the case for manual_map_option
42 let _: Option<i32> = match x {
48 fn func_ret_err<T>(err: T) -> Result<i32, T> {
53 let _: Result<i32, i32> = Ok(1);
54 let _: Result<i32, i32> = func_ret_err(0_i32);
55 // as ref, don't trigger
56 let res = &func_ret_err(0_i32);
57 let _: Result<&i32, &i32> = match *res {
69 let _ = if let Some(a) = Some(1) {
77 let _ = if let Some(a) = Some(1) {
85 let _ = if let Some(a) = Some(1) { Some(a) } else { Some(2) };
88 fn if_let_option_result() -> Result<(), ()> {
89 fn f(x: i32) -> Result<Option<i32>, ()> {
93 let _ = if let Some(v) = f(1)? { Some(v) } else { f(2)? };
98 let x: Result<i32, i32> = Ok(1);
99 let _: Result<i32, i32> = x;
100 let _: Result<i32, i32> = x;
101 // Input type mismatch, don't trigger
102 #[allow(clippy::question_mark)]
103 let _: Result<i32, i32> = if let Err(e) = Ok(1) { Err(e) } else { x };
106 fn if_let_custom_enum(x: Simple) {
110 let _: Simple = if let Simple::A = x {
120 #[derive(Clone, Copy)]
134 let ce = Complex::B(8, false);
141 let _: Complex = match ce {
142 Complex::A(_) => Complex::A(aa),
143 Complex::B(_, b) => Complex::B(aa, b),
144 Complex::C(_, b, _) => Complex::C(aa, b, 64_f64),
145 Complex::D(e, b) => Complex::D(e, b),
149 let _: Complex = match ce {
150 Complex::A(a) => Complex::A(a),
151 Complex::B(a, _) => Complex::B(a, bb),
152 Complex::C(a, _, _) => Complex::C(a, 32_i32, 64_f64),
158 /// Lint triggered when type coercions happen.
159 /// Do NOT trigger on any of these.
163 impl Trait for Struct {}
165 fn optmap(s: Option<&Struct>) -> Option<&dyn Trait> {
173 let option: Option<&Struct> = None;
174 let _: Option<&dyn Trait> = match option {
179 let _: Option<&dyn Trait> = if true {
188 let result: Result<&Struct, i32> = Err(0);
189 let _: Result<&dyn Trait, i32> = match result {
194 let _: Option<&dyn Trait> = if let Some(s) = option { Some(s) } else { None };
199 fn as_mut(&mut self) -> Result<&mut i32, &mut i32>;
201 impl Tr for Result<i32, i32> {
202 fn as_mut(&mut self) -> Result<&mut i32, &mut i32> {