2022-02-25 04:08:52 -06:00
|
|
|
// run-rustfix
|
2022-03-09 19:44:25 -06:00
|
|
|
#![warn(clippy::needless_match)]
|
2022-02-25 04:08:52 -06:00
|
|
|
#![allow(clippy::manual_map)]
|
|
|
|
#![allow(dead_code)]
|
|
|
|
|
2022-03-08 04:15:11 -06:00
|
|
|
#[derive(Clone, Copy)]
|
2022-03-08 03:37:53 -06:00
|
|
|
enum Choice {
|
2022-03-07 04:12:35 -06:00
|
|
|
A,
|
|
|
|
B,
|
|
|
|
C,
|
2022-03-08 03:37:53 -06:00
|
|
|
D,
|
2022-03-07 04:12:35 -06:00
|
|
|
}
|
|
|
|
|
2022-03-08 03:37:53 -06:00
|
|
|
fn useless_match(x: i32) {
|
|
|
|
let _: i32 = x;
|
2022-03-07 04:12:35 -06:00
|
|
|
}
|
|
|
|
|
2022-03-08 03:37:53 -06:00
|
|
|
fn custom_type_match(se: Choice) {
|
|
|
|
let _: Choice = se;
|
|
|
|
// Don't trigger
|
|
|
|
let _: Choice = match se {
|
|
|
|
Choice::A => Choice::A,
|
|
|
|
Choice::B => Choice::B,
|
|
|
|
_ => Choice::C,
|
|
|
|
};
|
|
|
|
// Mingled, don't trigger
|
|
|
|
let _: Choice = match se {
|
|
|
|
Choice::A => Choice::B,
|
|
|
|
Choice::B => Choice::C,
|
|
|
|
Choice::C => Choice::D,
|
|
|
|
Choice::D => Choice::A,
|
|
|
|
};
|
2022-03-07 04:12:35 -06:00
|
|
|
}
|
|
|
|
|
2022-03-08 03:37:53 -06:00
|
|
|
fn option_match(x: Option<i32>) {
|
|
|
|
let _: Option<i32> = x;
|
|
|
|
// Don't trigger, this is the case for manual_map_option
|
|
|
|
let _: Option<i32> = match x {
|
|
|
|
Some(a) => Some(-a),
|
|
|
|
None => None,
|
|
|
|
};
|
2022-02-25 04:08:52 -06:00
|
|
|
}
|
|
|
|
|
2022-03-08 03:37:53 -06:00
|
|
|
fn func_ret_err<T>(err: T) -> Result<i32, T> {
|
|
|
|
Err(err)
|
2022-02-25 04:08:52 -06:00
|
|
|
}
|
|
|
|
|
2022-03-08 03:37:53 -06:00
|
|
|
fn result_match() {
|
|
|
|
let _: Result<i32, i32> = Ok(1);
|
|
|
|
let _: Result<i32, i32> = func_ret_err(0_i32);
|
2022-02-25 04:08:52 -06:00
|
|
|
}
|
|
|
|
|
2022-03-08 03:37:53 -06:00
|
|
|
fn if_let_option() -> Option<i32> {
|
|
|
|
Some(1)
|
2022-02-25 04:08:52 -06:00
|
|
|
}
|
|
|
|
|
2022-03-08 03:37:53 -06:00
|
|
|
fn if_let_result(x: Result<(), i32>) {
|
|
|
|
let _: Result<(), i32> = x;
|
|
|
|
let _: Result<(), i32> = x;
|
|
|
|
// Input type mismatch, don't trigger
|
|
|
|
let _: Result<(), i32> = if let Err(e) = Ok(1) { Err(e) } else { x };
|
2022-02-25 04:08:52 -06:00
|
|
|
}
|
|
|
|
|
2022-03-08 04:15:11 -06:00
|
|
|
fn if_let_custom_enum(x: Choice) {
|
|
|
|
let _: Choice = x;
|
|
|
|
// Don't trigger
|
|
|
|
let _: Choice = if let Choice::A = x {
|
|
|
|
Choice::A
|
|
|
|
} else if true {
|
|
|
|
Choice::B
|
|
|
|
} else {
|
|
|
|
x
|
|
|
|
};
|
2022-02-25 04:08:52 -06:00
|
|
|
}
|
|
|
|
|
2022-03-07 04:12:35 -06:00
|
|
|
fn main() {}
|