2023-04-20 09:37:15 -05:00
|
|
|
//@run-rustfix
|
2020-09-21 08:32:26 -05:00
|
|
|
|
|
|
|
#![warn(clippy::all)]
|
|
|
|
#![warn(clippy::redundant_pattern_matching)]
|
2021-01-03 13:01:01 -06:00
|
|
|
#![allow(
|
|
|
|
unused_must_use,
|
|
|
|
clippy::needless_bool,
|
2023-06-10 06:43:30 -05:00
|
|
|
clippy::needless_if,
|
2021-01-03 13:01:01 -06:00
|
|
|
clippy::match_like_matches_macro,
|
2021-10-04 01:33:40 -05:00
|
|
|
clippy::equatable_if_let,
|
2021-01-03 13:01:01 -06:00
|
|
|
clippy::if_same_then_else
|
|
|
|
)]
|
2023-07-17 14:18:11 -05:00
|
|
|
#![feature(let_chains, if_let_guard)]
|
2020-09-21 08:32:26 -05:00
|
|
|
|
2023-07-17 12:25:28 -05:00
|
|
|
fn issue_11174<T>(boolean: bool, maybe_some: Option<T>) -> bool {
|
2023-07-17 14:18:11 -05:00
|
|
|
maybe_some.is_none() && (!boolean)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn issue_11174_edge_cases<T>(boolean: bool, boolean2: bool, maybe_some: Option<T>) {
|
|
|
|
let _ = maybe_some.is_none() && (boolean || boolean2); // guard needs parentheses
|
|
|
|
let _ = match maybe_some { // can't use `matches!` here
|
|
|
|
// because `expr` metavars in macros don't allow let exprs
|
|
|
|
None if let Some(x) = Some(0) && x > 5 => true,
|
|
|
|
_ => false
|
|
|
|
};
|
2023-07-17 12:25:28 -05:00
|
|
|
}
|
|
|
|
|
2020-09-21 08:32:26 -05:00
|
|
|
fn main() {
|
|
|
|
if None::<()>.is_none() {}
|
|
|
|
|
|
|
|
if Some(42).is_some() {}
|
|
|
|
|
|
|
|
if Some(42).is_some() {
|
|
|
|
foo();
|
|
|
|
} else {
|
|
|
|
bar();
|
|
|
|
}
|
|
|
|
|
|
|
|
while Some(42).is_some() {}
|
|
|
|
|
|
|
|
while Some(42).is_none() {}
|
|
|
|
|
|
|
|
while None::<()>.is_none() {}
|
|
|
|
|
|
|
|
let mut v = vec![1, 2, 3];
|
|
|
|
while v.pop().is_some() {
|
|
|
|
foo();
|
|
|
|
}
|
|
|
|
|
|
|
|
if None::<i32>.is_none() {}
|
|
|
|
|
|
|
|
if Some(42).is_some() {}
|
|
|
|
|
|
|
|
Some(42).is_some();
|
|
|
|
|
|
|
|
None::<()>.is_none();
|
|
|
|
|
|
|
|
let _ = None::<()>.is_none();
|
|
|
|
|
|
|
|
let opt = Some(false);
|
2020-11-24 19:01:05 -06:00
|
|
|
let _ = if opt.is_some() { true } else { false };
|
2020-09-21 08:32:26 -05:00
|
|
|
|
|
|
|
issue6067();
|
2023-05-05 14:33:16 -05:00
|
|
|
issue10726();
|
2023-05-25 23:16:39 -05:00
|
|
|
issue10803();
|
2020-09-21 08:32:26 -05:00
|
|
|
|
|
|
|
let _ = if gen_opt().is_some() {
|
|
|
|
1
|
|
|
|
} else if gen_opt().is_none() {
|
|
|
|
2
|
|
|
|
} else {
|
|
|
|
3
|
|
|
|
};
|
2023-04-23 14:34:42 -05:00
|
|
|
|
|
|
|
if gen_opt().is_some() {}
|
2020-09-21 08:32:26 -05: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 Some(42).is_some() {}
|
|
|
|
|
|
|
|
if None::<()>.is_none() {}
|
|
|
|
|
|
|
|
while Some(42).is_some() {}
|
|
|
|
|
|
|
|
while None::<()>.is_none() {}
|
|
|
|
|
|
|
|
Some(42).is_some();
|
|
|
|
|
|
|
|
None::<()>.is_none();
|
|
|
|
}
|
2021-11-08 17:31:18 -06:00
|
|
|
|
2022-01-11 18:44:33 -06:00
|
|
|
#[allow(clippy::deref_addrof, dead_code, clippy::needless_borrow)]
|
2021-11-08 17:31:18 -06:00
|
|
|
fn issue7921() {
|
|
|
|
if (&None::<()>).is_none() {}
|
|
|
|
if (&None::<()>).is_none() {}
|
|
|
|
}
|
2023-05-05 14:33:16 -05:00
|
|
|
|
|
|
|
fn issue10726() {
|
2023-05-11 00:20:02 -05:00
|
|
|
let x = Some(42);
|
2023-05-05 14:33:16 -05:00
|
|
|
|
2023-05-11 00:20:02 -05:00
|
|
|
x.is_some();
|
2023-05-05 14:33:16 -05:00
|
|
|
|
2023-05-11 00:20:02 -05:00
|
|
|
x.is_none();
|
2023-05-05 14:33:16 -05:00
|
|
|
|
2023-05-15 12:43:22 -05:00
|
|
|
x.is_none();
|
2023-05-11 00:20:02 -05:00
|
|
|
|
2023-05-15 12:43:22 -05:00
|
|
|
x.is_some();
|
2023-05-05 14:33:16 -05:00
|
|
|
|
2023-05-11 00:20:02 -05:00
|
|
|
// Don't lint
|
|
|
|
match x {
|
2023-05-09 13:50:47 -05:00
|
|
|
Some(21) => true,
|
|
|
|
_ => false,
|
|
|
|
};
|
2023-05-05 14:33:16 -05:00
|
|
|
}
|
2023-05-25 23:16:39 -05:00
|
|
|
|
|
|
|
fn issue10803() {
|
|
|
|
let x = Some(42);
|
|
|
|
|
|
|
|
let _ = x.is_some();
|
|
|
|
|
|
|
|
let _ = x.is_none();
|
|
|
|
|
|
|
|
// Don't lint
|
|
|
|
let _ = matches!(x, Some(16));
|
|
|
|
}
|