2023-04-23 11:03:09 +00:00
|
|
|
//@run-rustfix
|
2020-09-24 12:49:22 +00:00
|
|
|
|
|
|
|
#![warn(clippy::all)]
|
|
|
|
#![warn(clippy::redundant_pattern_matching)]
|
2021-04-22 09:31:13 +00:00
|
|
|
#![allow(
|
|
|
|
unused_must_use,
|
|
|
|
clippy::needless_bool,
|
2023-07-02 12:35:19 +00:00
|
|
|
clippy::needless_if,
|
2021-04-22 09:31:13 +00:00
|
|
|
clippy::match_like_matches_macro,
|
2021-10-07 09:21:30 +00:00
|
|
|
clippy::equatable_if_let,
|
2021-04-22 09:31:13 +00:00
|
|
|
clippy::if_same_then_else
|
|
|
|
)]
|
2020-09-24 12:49:22 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
if let None = None::<()> {}
|
|
|
|
|
|
|
|
if let Some(_) = Some(42) {}
|
|
|
|
|
|
|
|
if let Some(_) = Some(42) {
|
|
|
|
foo();
|
|
|
|
} else {
|
|
|
|
bar();
|
|
|
|
}
|
|
|
|
|
|
|
|
while let Some(_) = Some(42) {}
|
|
|
|
|
|
|
|
while let None = Some(42) {}
|
|
|
|
|
|
|
|
while let None = None::<()> {}
|
|
|
|
|
|
|
|
let mut v = vec![1, 2, 3];
|
|
|
|
while let Some(_) = v.pop() {
|
|
|
|
foo();
|
|
|
|
}
|
|
|
|
|
|
|
|
if None::<i32>.is_none() {}
|
|
|
|
|
|
|
|
if Some(42).is_some() {}
|
|
|
|
|
|
|
|
match Some(42) {
|
|
|
|
Some(_) => true,
|
|
|
|
None => false,
|
|
|
|
};
|
|
|
|
|
|
|
|
match None::<()> {
|
|
|
|
Some(_) => false,
|
|
|
|
None => true,
|
|
|
|
};
|
|
|
|
|
|
|
|
let _ = match None::<()> {
|
|
|
|
Some(_) => false,
|
|
|
|
None => true,
|
|
|
|
};
|
|
|
|
|
|
|
|
let opt = Some(false);
|
2020-12-06 14:01:03 +00:00
|
|
|
let _ = if let Some(_) = opt { true } else { false };
|
2020-09-24 12:49:22 +00:00
|
|
|
|
|
|
|
issue6067();
|
2023-05-20 13:39:26 +00:00
|
|
|
issue10726();
|
2023-06-02 09:41:57 +00:00
|
|
|
issue10803();
|
2020-09-24 12:49:22 +00:00
|
|
|
|
|
|
|
let _ = if let Some(_) = gen_opt() {
|
|
|
|
1
|
|
|
|
} else if let None = gen_opt() {
|
|
|
|
2
|
|
|
|
} else {
|
|
|
|
3
|
|
|
|
};
|
2023-05-05 15:45:49 +00:00
|
|
|
|
|
|
|
if let Some(..) = gen_opt() {}
|
2020-09-24 12:49:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn gen_opt() -> Option<()> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
|
|
|
fn foo() {}
|
|
|
|
|
|
|
|
fn bar() {}
|
|
|
|
|
|
|
|
// Methods that are unstable const should not be suggested within a const context, see issue #5697.
|
|
|
|
// However, in Rust 1.48.0 the methods `is_some` and `is_none` of `Option` were stabilized as const,
|
|
|
|
// so the following should be linted.
|
|
|
|
const fn issue6067() {
|
|
|
|
if let Some(_) = Some(42) {}
|
|
|
|
|
|
|
|
if let None = None::<()> {}
|
|
|
|
|
|
|
|
while let Some(_) = Some(42) {}
|
|
|
|
|
|
|
|
while let None = None::<()> {}
|
|
|
|
|
|
|
|
match Some(42) {
|
|
|
|
Some(_) => true,
|
|
|
|
None => false,
|
|
|
|
};
|
|
|
|
|
|
|
|
match None::<()> {
|
|
|
|
Some(_) => false,
|
|
|
|
None => true,
|
|
|
|
};
|
|
|
|
}
|
2021-12-06 11:33:31 +00:00
|
|
|
|
2022-01-27 14:12:45 +00:00
|
|
|
#[allow(clippy::deref_addrof, dead_code, clippy::needless_borrow)]
|
2021-12-06 11:33:31 +00:00
|
|
|
fn issue7921() {
|
|
|
|
if let None = *(&None::<()>) {}
|
|
|
|
if let None = *&None::<()> {}
|
|
|
|
}
|
2023-05-20 13:39:26 +00:00
|
|
|
|
|
|
|
fn issue10726() {
|
|
|
|
let x = Some(42);
|
|
|
|
|
|
|
|
match x {
|
|
|
|
Some(_) => true,
|
|
|
|
_ => false,
|
|
|
|
};
|
|
|
|
|
|
|
|
match x {
|
|
|
|
None => true,
|
|
|
|
_ => false,
|
|
|
|
};
|
|
|
|
|
|
|
|
match x {
|
|
|
|
Some(_) => false,
|
|
|
|
_ => true,
|
|
|
|
};
|
|
|
|
|
|
|
|
match x {
|
|
|
|
None => false,
|
|
|
|
_ => true,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Don't lint
|
|
|
|
match x {
|
|
|
|
Some(21) => true,
|
|
|
|
_ => false,
|
|
|
|
};
|
|
|
|
}
|
2023-06-02 09:41:57 +00:00
|
|
|
|
|
|
|
fn issue10803() {
|
|
|
|
let x = Some(42);
|
|
|
|
|
|
|
|
let _ = matches!(x, Some(_));
|
|
|
|
|
|
|
|
let _ = matches!(x, None);
|
|
|
|
|
|
|
|
// Don't lint
|
|
|
|
let _ = matches!(x, Some(16));
|
|
|
|
}
|