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) {
109 let x: Result<i32, i32> = Ok(1);
110 let _: Result<i32, i32> = if let Err(e) = x { Err(e) } else { x };
111 let _: Result<i32, i32> = if let Ok(val) = x { Ok(val) } else { x };
112 // Input type mismatch, don't trigger
113 let _: Result<i32, i32> = if let Err(e) = Ok(1) { Err(e) } else { x };
116 fn if_let_custom_enum(x: Simple) {
117 let _: Simple = if let Simple::A = x {
119 } else if let Simple::B = x {
121 } else if let Simple::C = x {
128 let _: Simple = if let Simple::A = x {
138 #[derive(Clone, Copy)]
152 let ce = Complex::B(8, false);
156 let _: Complex = match ce {
157 Complex::A(a) => Complex::A(a),
158 Complex::B(a, b) => Complex::B(a, b),
159 Complex::C(a, b, c) => Complex::C(a, b, c),
160 Complex::D(E::VariantA(ea, eb), b) => Complex::D(E::VariantA(ea, eb), b),
161 Complex::D(E::VariantB(ea, eb), b) => Complex::D(E::VariantB(ea, eb), b),
165 let _: Complex = match ce {
166 Complex::A(_) => Complex::A(aa),
167 Complex::B(_, b) => Complex::B(aa, b),
168 Complex::C(_, b, _) => Complex::C(aa, b, 64_f64),
169 Complex::D(e, b) => Complex::D(e, b),
173 let _: Complex = match ce {
174 Complex::A(a) => Complex::A(a),
175 Complex::B(a, _) => Complex::B(a, bb),
176 Complex::C(a, _, _) => Complex::C(a, 32_i32, 64_f64),
182 /// Lint triggered when type coercions happen.
183 /// Do NOT trigger on any of these.
187 impl Trait for Struct {}
189 fn optmap(s: Option<&Struct>) -> Option<&dyn Trait> {
197 let option: Option<&Struct> = None;
198 let _: Option<&dyn Trait> = match option {
203 let _: Option<&dyn Trait> = if true {
212 let result: Result<&Struct, i32> = Err(0);
213 let _: Result<&dyn Trait, i32> = match result {
218 let _: Option<&dyn Trait> = if let Some(s) = option { Some(s) } else { None };
223 fn as_mut(&mut self) -> Result<&mut i32, &mut i32>;
225 impl Tr for Result<i32, i32> {
226 fn as_mut(&mut self) -> Result<&mut i32, &mut i32> {