From a9ab7347b7a100553dc6b7b2ca3f2d93190bb265 Mon Sep 17 00:00:00 2001 From: Robin <1187338299@qq.com> Date: Wed, 30 Sep 2026 19:49:41 +0800 Subject: [PATCH 1/5] feat: add unnecessary literal option lint --- CHANGELOG.md | 1 + clippy_lints/src/declared_lints.rs | 1 + clippy_lints/src/methods/mod.rs | 41 +++++++- .../src/methods/unnecessary_literal_option.rs | 97 +++++++++++++++++++ tests/ui/unnecessary_literal_option.fixed | 24 +++++ tests/ui/unnecessary_literal_option.rs | 23 +++++ tests/ui/unnecessary_literal_option.stderr | 76 +++++++++++++++ 7 files changed, 261 insertions(+), 2 deletions(-) create mode 100644 clippy_lints/src/methods/unnecessary_literal_option.rs create mode 100644 tests/ui/unnecessary_literal_option.fixed create mode 100644 tests/ui/unnecessary_literal_option.rs create mode 100644 tests/ui/unnecessary_literal_option.stderr diff --git a/CHANGELOG.md b/CHANGELOG.md index f6814f0a9c7e..453dfd4d987e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7683,6 +7683,7 @@ Released 2018-09-13 [`unnecessary_join`]: https://rust-lang.github.io/rust-clippy/main/index.html#unnecessary_join [`unnecessary_lazy_evaluations`]: https://rust-lang.github.io/rust-clippy/main/index.html#unnecessary_lazy_evaluations [`unnecessary_literal_bound`]: https://rust-lang.github.io/rust-clippy/main/index.html#unnecessary_literal_bound +[`unnecessary_literal_option`]: https://rust-lang.github.io/rust-clippy/main/index.html#unnecessary_literal_option [`unnecessary_literal_unwrap`]: https://rust-lang.github.io/rust-clippy/main/index.html#unnecessary_literal_unwrap [`unnecessary_map_on_constructor`]: https://rust-lang.github.io/rust-clippy/main/index.html#unnecessary_map_on_constructor [`unnecessary_map_or`]: https://rust-lang.github.io/rust-clippy/main/index.html#unnecessary_map_or diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index 1729f9a3702f..e760533c08ac 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -511,6 +511,7 @@ pub static LINTS: &[&::declare_clippy_lint::LintInfo] = &[ crate::methods::UNNECESSARY_GET_THEN_CHECK_INFO, crate::methods::UNNECESSARY_JOIN_INFO, crate::methods::UNNECESSARY_LAZY_EVALUATIONS_INFO, + crate::methods::UNNECESSARY_LITERAL_OPTION_INFO, crate::methods::UNNECESSARY_LITERAL_UNWRAP_INFO, crate::methods::UNNECESSARY_MAP_OR_INFO, crate::methods::UNNECESSARY_MIN_OR_MAX_INFO, diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 8fd91f470c18..ca911c61d3f9 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -142,6 +142,7 @@ mod unnecessary_get_then_check; mod unnecessary_iter_cloned; mod unnecessary_join; mod unnecessary_lazy_eval; +mod unnecessary_literal_option; mod unnecessary_literal_unwrap; mod unnecessary_map_or; mod unnecessary_map_or_else; @@ -4527,6 +4528,31 @@ declare_clippy_lint! { "using unnecessary lazy evaluation, which can be replaced with simpler eager evaluation" } +declare_clippy_lint! { + /// ### What it does + /// Checks for `is_some`, `is_none`, `or`, and `or_else` calls on a literal `Some` or `None` + /// where the result is already known. + /// + /// ### Why is this bad? + /// The call does not change the result. It is either a mistake or leftover code. + /// + /// ### Example + /// ```no_run + /// let _ = Some(1).is_some(); + /// let _ = Some(1).or(None); + /// ``` + /// + /// Use instead: + /// ```no_run + /// let _ = true; + /// let _ = Some(1); + /// ``` + #[clippy::version = "1.99.0"] + pub UNNECESSARY_LITERAL_OPTION, + complexity, + "using `is_some`, `is_none`, `or`, or `or_else` on a literal `Some` or `None`" +} + declare_clippy_lint! { /// ### What it does /// Checks for `.unwrap()` related calls on `Result`s and `Option`s that are constructed. @@ -5197,6 +5223,7 @@ impl_lint_pass!(Methods => [ UNNECESSARY_GET_THEN_CHECK, UNNECESSARY_JOIN, UNNECESSARY_LAZY_EVALUATIONS, + UNNECESSARY_LITERAL_OPTION, UNNECESSARY_LITERAL_UNWRAP, UNNECESSARY_MAP_OR, UNNECESSARY_MIN_OR_MAX, @@ -5699,8 +5726,14 @@ impl Methods { }, (sym::is_file, []) => filetype_is_file::check(cx, expr, recv), (sym::is_digit, [radix]) => is_digit_ascii_radix::check(cx, expr, recv, radix, self.msrv), - (sym::is_none, []) => check_is_some_is_none(cx, expr, recv, call_span, false, self.msrv), - (sym::is_some, []) => check_is_some_is_none(cx, expr, recv, call_span, true, self.msrv), + (sym::is_none, []) => { + check_is_some_is_none(cx, expr, recv, call_span, false, self.msrv); + unnecessary_literal_option::check(cx, expr, recv, name, args); + }, + (sym::is_some, []) => { + check_is_some_is_none(cx, expr, recv, call_span, true, self.msrv); + unnecessary_literal_option::check(cx, expr, recv, name, args); + }, (sym::is_some_and, [arg]) => manual_is_variant_and::check_ok_is_some_and(cx, expr, recv, arg), (sym::iter | sym::iter_mut | sym::into_iter, []) => { iter_on_single_or_empty_collections::check(cx, expr, name, recv); @@ -5841,10 +5874,14 @@ impl Methods { (sym::open, [_]) => { open_options::check(cx, expr, recv); }, + (sym::or, [_arg]) => { + unnecessary_literal_option::check(cx, expr, recv, name, args); + }, (sym::or_else, [arg]) => { if !bind_instead_of_map::check_or_else_err(cx, expr, recv, arg) { unnecessary_lazy_eval::check(cx, expr, recv, arg, "or", false); } + unnecessary_literal_option::check(cx, expr, recv, name, args); }, (sym::peek, []) => { by_ref_peekable_peek::check(cx, expr, recv); diff --git a/clippy_lints/src/methods/unnecessary_literal_option.rs b/clippy_lints/src/methods/unnecessary_literal_option.rs new file mode 100644 index 000000000000..3da74f30c25b --- /dev/null +++ b/clippy_lints/src/methods/unnecessary_literal_option.rs @@ -0,0 +1,97 @@ +use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::res::{MaybeDef as _, MaybeQPath as _}; +use clippy_utils::{is_none_expr, last_path_segment, sym}; +use rustc_errors::Applicability; +use rustc_hir::{self as hir, AmbigArg}; +use rustc_lint::LateContext; +use rustc_span::Symbol; + +use super::UNNECESSARY_LITERAL_OPTION; + +fn get_ty_from_args<'a>(args: Option<&'a [hir::GenericArg<'a>]>, index: usize) -> Option<&'a hir::Ty<'a, AmbigArg>> { + let args = args?; + + if args.len() <= index { + return None; + } + + match args[index] { + hir::GenericArg::Type(ty) => Some(ty), + _ => None, + } +} + +pub(super) fn check( + cx: &LateContext<'_>, + expr: &hir::Expr<'_>, + recv: &hir::Expr<'_>, + method: Symbol, + _args: &[hir::Expr<'_>], +) { + let init = clippy_utils::expr_or_init(cx, recv); + if init.span.from_expansion() { + // don't lint if the receiver or binding initializer comes from a macro + // (e.g. `let x = option_env!(..); x.unwrap()`) + return; + } + + let (constructor, _call_args, ty) = if let hir::ExprKind::Call(call, call_args) = init.kind { + if let Some((qpath, hir_id)) = call.opt_qpath() + && let args = last_path_segment(qpath).args.map(|args| args.args) + && let Some(did) = cx.qpath_res(qpath, hir_id).ctor_parent(cx).opt_def_id() + { + let lang_items = cx.tcx.lang_items(); + if Some(did) == lang_items.option_some_variant() { + (sym::Some, call_args, get_ty_from_args(args, 0)) + } else if Some(did) == lang_items.result_ok_variant() { + (sym::Ok, call_args, get_ty_from_args(args, 0)) + } else if Some(did) == lang_items.result_err_variant() { + (sym::Err, call_args, get_ty_from_args(args, 1)) + } else { + return; + } + } else { + return; + } + } else if is_none_expr(cx, init) { + let call_args: &[hir::Expr<'_>] = &[]; + (sym::None, call_args, None) + } else { + return; + }; + + let help_message = format!("used `{method}()` on `{constructor}` value"); + let (suggestion_message, suggestions) = match (constructor, method, ty) { + (sym::Some, sym::is_some, _) => ( + "replace this with `true`".to_string(), + Some(vec![(expr.span, "true".to_string())]), + ), + (sym::Some, sym::is_none, _) => ( + "replace this with `false`".to_string(), + Some(vec![(expr.span, "false".to_string())]), + ), + (sym::None, sym::is_some, _) => ( + "replace this with `false`".to_string(), + Some(vec![(expr.span, "false".to_string())]), + ), + (sym::None, sym::is_none, _) => ( + "replace this with `true`".to_string(), + Some(vec![(expr.span, "true".to_string())]), + ), + (sym::Some, sym::or | sym::or_else, _) => ( + format!("remove this `.{method}()` call"), + Some(vec![(expr.span.with_lo(recv.span.hi()), String::new())]), + ), + _ => return, + }; + span_lint_and_then(cx, UNNECESSARY_LITERAL_OPTION, expr.span, help_message, |diag| { + match (init.span == recv.span, suggestions) { + (true, Some(suggestions)) => { + diag.multipart_suggestion(suggestion_message, suggestions, Applicability::MachineApplicable); + }, + _ => { + diag.span_help(init.span, suggestion_message); + }, + } + }); +} diff --git a/tests/ui/unnecessary_literal_option.fixed b/tests/ui/unnecessary_literal_option.fixed new file mode 100644 index 000000000000..c94e3c607fee --- /dev/null +++ b/tests/ui/unnecessary_literal_option.fixed @@ -0,0 +1,24 @@ +#![allow(clippy::unnecessary_lazy_evaluations)] +#![warn(clippy::unnecessary_literal_option)] +fn main() { + let _ = true; + //~^ unnecessary_literal_option + + let _ = false; + //~^ unnecessary_literal_option + + let _ = false; + //~^ unnecessary_literal_option + + let _ = true; + //~^ unnecessary_literal_option + + let _ = Some(1); + //~^ unnecessary_literal_option + + let _ = Some(1); + //~^ unnecessary_literal_option + + let _ = None.or(Some(1)); + +} \ No newline at end of file diff --git a/tests/ui/unnecessary_literal_option.rs b/tests/ui/unnecessary_literal_option.rs new file mode 100644 index 000000000000..841ca2646710 --- /dev/null +++ b/tests/ui/unnecessary_literal_option.rs @@ -0,0 +1,23 @@ +#![allow(clippy::unnecessary_lazy_evaluations)] +#![warn(clippy::unnecessary_literal_option)] +fn main() { + let _ = Some(1).is_some(); + //~^ unnecessary_literal_option + + let _ = Some(1).is_none(); + //~^ unnecessary_literal_option + + let _ = None::.is_some(); + //~^ unnecessary_literal_option + + let _ = None::.is_none(); + //~^ unnecessary_literal_option + + let _ = Some(1).or(None); + //~^ unnecessary_literal_option + + let _ = Some(1).or_else(|| None); + //~^ unnecessary_literal_option + + let _ = None.or(Some(1)); +} diff --git a/tests/ui/unnecessary_literal_option.stderr b/tests/ui/unnecessary_literal_option.stderr new file mode 100644 index 000000000000..42dd2bd3f3fe --- /dev/null +++ b/tests/ui/unnecessary_literal_option.stderr @@ -0,0 +1,76 @@ +error: used `is_some()` on `Some` value + --> tests/ui/unnecessary_literal_option.rs:4:13 + | +LL | let _ = Some(1).is_some(); + | ^^^^^^^^^^^^^^^^^ + | + = note: `-D clippy::unnecessary-literal-option` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_literal_option)]` +help: replace this with `true` + | +LL - let _ = Some(1).is_some(); +LL + let _ = true; + | + +error: used `is_none()` on `Some` value + --> tests/ui/unnecessary_literal_option.rs:7:13 + | +LL | let _ = Some(1).is_none(); + | ^^^^^^^^^^^^^^^^^ + | +help: replace this with `false` + | +LL - let _ = Some(1).is_none(); +LL + let _ = false; + | + +error: used `is_some()` on `None` value + --> tests/ui/unnecessary_literal_option.rs:10:13 + | +LL | let _ = None::.is_some(); + | ^^^^^^^^^^^^^^^^^^^^^ + | +help: replace this with `false` + | +LL - let _ = None::.is_some(); +LL + let _ = false; + | + +error: used `is_none()` on `None` value + --> tests/ui/unnecessary_literal_option.rs:13:13 + | +LL | let _ = None::.is_none(); + | ^^^^^^^^^^^^^^^^^^^^^ + | +help: replace this with `true` + | +LL - let _ = None::.is_none(); +LL + let _ = true; + | + +error: used `or()` on `Some` value + --> tests/ui/unnecessary_literal_option.rs:16:13 + | +LL | let _ = Some(1).or(None); + | ^^^^^^^^^^^^^^^^ + | +help: remove this `.or()` call + | +LL - let _ = Some(1).or(None); +LL + let _ = Some(1); + | + +error: used `or_else()` on `Some` value + --> tests/ui/unnecessary_literal_option.rs:19:13 + | +LL | let _ = Some(1).or_else(|| None); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: remove this `.or_else()` call + | +LL - let _ = Some(1).or_else(|| None); +LL + let _ = Some(1); + | + +error: aborting due to 6 previous errors + From 51416b3b9bca1d1e1c70d10f6b1935bb814c531f Mon Sep 17 00:00:00 2001 From: Robin <1187338299@qq.com> Date: Thu, 1 Oct 2026 16:52:51 +0800 Subject: [PATCH 2/5] feat: fix CI issues --- .../complex_conditionals_nested.rs | 6 +- .../complex_conditionals_nested.stderr | 4 +- .../ui/checked_unwrap/simple_conditionals.rs | 3 +- .../checked_unwrap/simple_conditionals.stderr | 114 +++++++++--------- tests/ui/iter_filter_is_ok.fixed | 2 +- tests/ui/iter_filter_is_ok.rs | 2 +- tests/ui/iter_filter_is_some.fixed | 7 +- tests/ui/iter_filter_is_some.rs | 7 +- tests/ui/iter_filter_is_some.stderr | 20 +-- tests/ui/manual_assert.edition2018.fixed | 1 + tests/ui/manual_assert.edition2018.stderr | 22 ++-- tests/ui/manual_assert.edition2021.fixed | 1 + tests/ui/manual_assert.edition2021.stderr | 22 ++-- tests/ui/manual_assert.rs | 1 + tests/ui/manual_is_variant_and.fixed | 2 +- tests/ui/manual_is_variant_and.rs | 2 +- tests/ui/manual_let_else_match.fixed | 2 +- tests/ui/manual_let_else_match.rs | 2 +- tests/ui/match_like_matches_macro.fixed | 6 +- tests/ui/match_like_matches_macro.rs | 6 +- tests/ui/match_like_matches_macro.stderr | 34 +++--- tests/ui/match_ref_pats.fixed | 1 + tests/ui/match_ref_pats.rs | 1 + tests/ui/match_ref_pats.stderr | 10 +- tests/ui/nonminimal_bool_methods.fixed | 6 +- tests/ui/nonminimal_bool_methods.rs | 6 +- tests/ui/nonminimal_bool_methods.stderr | 84 ++++++------- tests/ui/or_fun_call.fixed | 3 +- tests/ui/or_fun_call.rs | 3 +- tests/ui/or_fun_call.stderr | 98 +++++++-------- tests/ui/partialeq_to_none.fixed | 1 + tests/ui/partialeq_to_none.rs | 1 + tests/ui/partialeq_to_none.stderr | 30 ++--- ...edundant_pattern_matching_drop_order.fixed | 2 +- .../redundant_pattern_matching_drop_order.rs | 2 +- .../redundant_pattern_matching_option.fixed | 6 +- tests/ui/redundant_pattern_matching_option.rs | 6 +- .../redundant_pattern_matching_option.stderr | 90 +++++++------- tests/ui/significant_drop_tightening.fixed | 2 +- tests/ui/significant_drop_tightening.rs | 2 +- tests/ui/unnecessary_literal_option.fixed | 3 +- 41 files changed, 335 insertions(+), 288 deletions(-) diff --git a/tests/ui/checked_unwrap/complex_conditionals_nested.rs b/tests/ui/checked_unwrap/complex_conditionals_nested.rs index 6789e7c262b3..0015bd0b8a6d 100644 --- a/tests/ui/checked_unwrap/complex_conditionals_nested.rs +++ b/tests/ui/checked_unwrap/complex_conditionals_nested.rs @@ -1,6 +1,10 @@ //@no-rustfix: has placeholders #![warn(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] -#![expect(clippy::branches_sharing_code, clippy::unnecessary_literal_unwrap)] +#![expect( + clippy::branches_sharing_code, + clippy::unnecessary_literal_unwrap, + clippy::unnecessary_literal_option +)] fn test_nested() { fn nested() { diff --git a/tests/ui/checked_unwrap/complex_conditionals_nested.stderr b/tests/ui/checked_unwrap/complex_conditionals_nested.stderr index 7e4ef049f4a5..23cfdee4d28b 100644 --- a/tests/ui/checked_unwrap/complex_conditionals_nested.stderr +++ b/tests/ui/checked_unwrap/complex_conditionals_nested.stderr @@ -1,5 +1,5 @@ error: called `unwrap` on `x` after checking its variant with `is_some` - --> tests/ui/checked_unwrap/complex_conditionals_nested.rs:9:13 + --> tests/ui/checked_unwrap/complex_conditionals_nested.rs:13:13 | LL | if x.is_some() { | -------------- help: try: `if let Some() = x` @@ -10,7 +10,7 @@ LL | x.unwrap(); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_unwrap)]` error: this call to `unwrap()` will always panic - --> tests/ui/checked_unwrap/complex_conditionals_nested.rs:12:13 + --> tests/ui/checked_unwrap/complex_conditionals_nested.rs:16:13 | LL | if x.is_some() { | ----------- because of this check diff --git a/tests/ui/checked_unwrap/simple_conditionals.rs b/tests/ui/checked_unwrap/simple_conditionals.rs index 331fd8f05499..17b242fa6b5d 100644 --- a/tests/ui/checked_unwrap/simple_conditionals.rs +++ b/tests/ui/checked_unwrap/simple_conditionals.rs @@ -4,7 +4,8 @@ clippy::branches_sharing_code, clippy::if_same_then_else, clippy::self_assignment, - clippy::unnecessary_literal_unwrap + clippy::unnecessary_literal_unwrap, + clippy::unnecessary_literal_option )] macro_rules! m { diff --git a/tests/ui/checked_unwrap/simple_conditionals.stderr b/tests/ui/checked_unwrap/simple_conditionals.stderr index be979baa9fe4..af85b69ac94d 100644 --- a/tests/ui/checked_unwrap/simple_conditionals.stderr +++ b/tests/ui/checked_unwrap/simple_conditionals.stderr @@ -1,5 +1,5 @@ error: called `unwrap` on `x` after checking its variant with `is_some` - --> tests/ui/checked_unwrap/simple_conditionals.rs:46:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:47:9 | LL | if x.is_some() { | -------------- help: try: `if let Some() = x` @@ -10,7 +10,7 @@ LL | x.unwrap(); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_unwrap)]` error: called `expect` on `x` after checking its variant with `is_some` - --> tests/ui/checked_unwrap/simple_conditionals.rs:49:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:50:9 | LL | if x.is_some() { | -------------- help: try: `if let Some() = x` @@ -19,7 +19,7 @@ LL | x.expect("an error message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:52:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:53:9 | LL | if x.is_some() { | ----------- because of this check @@ -31,7 +31,7 @@ LL | x.unwrap(); = help: to override `-D warnings` add `#[allow(clippy::panicking_unwrap)]` error: this call to `expect()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:55:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:56:9 | LL | if x.is_some() { | ----------- because of this check @@ -40,7 +40,7 @@ LL | x.expect("an error message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:59:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:60:9 | LL | if x.is_none() { | ----------- because of this check @@ -48,7 +48,7 @@ LL | x.unwrap(); | ^^^^^^^^^^ error: called `unwrap` on `x` after checking its variant with `is_none` - --> tests/ui/checked_unwrap/simple_conditionals.rs:62:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:63:9 | LL | if x.is_none() { | -------------- help: try: `if let Some() = x` @@ -57,7 +57,7 @@ LL | x.unwrap(); | ^^^^^^^^^^ error: called `unwrap` on `x` after checking its variant with `is_some` - --> tests/ui/checked_unwrap/simple_conditionals.rs:13:13 + --> tests/ui/checked_unwrap/simple_conditionals.rs:14:13 | LL | if $a.is_some() { | --------------- help: try: `if let Some() = x` @@ -70,7 +70,7 @@ LL | m!(x); = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) error: called `unwrap` on `x` after checking its variant with `is_ok` - --> tests/ui/checked_unwrap/simple_conditionals.rs:71:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:72:9 | LL | if x.is_ok() { | ------------ help: try: `if let Ok() = x` @@ -78,7 +78,7 @@ LL | x.unwrap(); | ^^^^^^^^^^ error: called `expect` on `x` after checking its variant with `is_ok` - --> tests/ui/checked_unwrap/simple_conditionals.rs:74:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:75:9 | LL | if x.is_ok() { | ------------ help: try: `if let Ok() = x` @@ -87,7 +87,7 @@ LL | x.expect("an error message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap_err()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:77:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:78:9 | LL | if x.is_ok() { | --------- because of this check @@ -96,7 +96,7 @@ LL | x.unwrap_err(); | ^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:80:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:81:9 | LL | if x.is_ok() { | --------- because of this check @@ -105,7 +105,7 @@ LL | x.unwrap(); | ^^^^^^^^^^ error: this call to `expect()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:83:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:84:9 | LL | if x.is_ok() { | --------- because of this check @@ -114,7 +114,7 @@ LL | x.expect("an error message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: called `unwrap_err` on `x` after checking its variant with `is_ok` - --> tests/ui/checked_unwrap/simple_conditionals.rs:86:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:87:9 | LL | if x.is_ok() { | ------------ help: try: `if let Err() = x` @@ -123,7 +123,7 @@ LL | x.unwrap_err(); | ^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:90:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:91:9 | LL | if x.is_err() { | ---------- because of this check @@ -131,7 +131,7 @@ LL | x.unwrap(); | ^^^^^^^^^^ error: called `unwrap_err` on `x` after checking its variant with `is_err` - --> tests/ui/checked_unwrap/simple_conditionals.rs:93:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:94:9 | LL | if x.is_err() { | ------------- help: try: `if let Err() = x` @@ -140,7 +140,7 @@ LL | x.unwrap_err(); | ^^^^^^^^^^^^^^ error: called `unwrap` on `x` after checking its variant with `is_err` - --> tests/ui/checked_unwrap/simple_conditionals.rs:96:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:97:9 | LL | if x.is_err() { | ------------- help: try: `if let Ok() = x` @@ -149,7 +149,7 @@ LL | x.unwrap(); | ^^^^^^^^^^ error: this call to `unwrap_err()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:99:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:100:9 | LL | if x.is_err() { | ---------- because of this check @@ -158,7 +158,7 @@ LL | x.unwrap_err(); | ^^^^^^^^^^^^^^ error: called `unwrap` on `option` after checking its variant with `is_some` - --> tests/ui/checked_unwrap/simple_conditionals.rs:124:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:125:9 | LL | if option.is_some() { | ------------------- help: try: `if let Some() = &option` @@ -166,7 +166,7 @@ LL | option.as_ref().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:127:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:128:9 | LL | if option.is_some() { | ---------------- because of this check @@ -175,7 +175,7 @@ LL | option.as_ref().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: called `unwrap` on `result` after checking its variant with `is_ok` - --> tests/ui/checked_unwrap/simple_conditionals.rs:134:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:135:9 | LL | if result.is_ok() { | ----------------- help: try: `if let Ok() = &result` @@ -183,7 +183,7 @@ LL | result.as_ref().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:137:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:138:9 | LL | if result.is_ok() { | -------------- because of this check @@ -192,7 +192,7 @@ LL | result.as_ref().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: called `unwrap` on `option` after checking its variant with `is_some` - --> tests/ui/checked_unwrap/simple_conditionals.rs:143:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:144:9 | LL | if option.is_some() { | ------------------- help: try: `if let Some() = &mut option` @@ -200,7 +200,7 @@ LL | option.as_mut().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:146:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:147:9 | LL | if option.is_some() { | ---------------- because of this check @@ -209,7 +209,7 @@ LL | option.as_mut().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: called `unwrap` on `result` after checking its variant with `is_ok` - --> tests/ui/checked_unwrap/simple_conditionals.rs:152:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:153:9 | LL | if result.is_ok() { | ----------------- help: try: `if let Ok() = &mut result` @@ -217,7 +217,7 @@ LL | result.as_mut().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:155:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:156:9 | LL | if result.is_ok() { | -------------- because of this check @@ -226,7 +226,7 @@ LL | result.as_mut().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: called `unwrap` on `option` after checking its variant with `is_some` - --> tests/ui/checked_unwrap/simple_conditionals.rs:184:17 + --> tests/ui/checked_unwrap/simple_conditionals.rs:185:17 | LL | if option.is_some() { | ------------------- help: try: `if let Some() = &option` @@ -234,7 +234,7 @@ LL | let _ = option.as_ref().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:187:17 + --> tests/ui/checked_unwrap/simple_conditionals.rs:188:17 | LL | if option.is_some() { | ---------------- because of this check @@ -243,7 +243,7 @@ LL | let _ = option.as_ref().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: called `unwrap` on `result` after checking its variant with `is_ok` - --> tests/ui/checked_unwrap/simple_conditionals.rs:195:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:196:9 | LL | if result.is_ok() { | ----------------- help: try: `if let Ok() = &result` @@ -252,7 +252,7 @@ LL | result.as_ref().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:199:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:200:9 | LL | if result.is_ok() { | -------------- because of this check @@ -261,7 +261,7 @@ LL | result.as_ref().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: called `unwrap` on `x` after checking its variant with `is_some` - --> tests/ui/checked_unwrap/simple_conditionals.rs:225:17 + --> tests/ui/checked_unwrap/simple_conditionals.rs:226:17 | LL | if x.is_some() { | -------------- help: try: `if let Some() = x` @@ -269,7 +269,7 @@ LL | _ = x.unwrap(); | ^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:228:17 + --> tests/ui/checked_unwrap/simple_conditionals.rs:229:17 | LL | if x.is_some() { | ----------- because of this check @@ -278,7 +278,7 @@ LL | _ = x.unwrap(); | ^^^^^^^^^^ error: called `unwrap` on `r` after checking its variant with `is_ok` - --> tests/ui/checked_unwrap/simple_conditionals.rs:234:17 + --> tests/ui/checked_unwrap/simple_conditionals.rs:235:17 | LL | if r.is_ok() { | ------------ help: try: `if let Ok() = &r` @@ -286,7 +286,7 @@ LL | _ = r.as_ref().unwrap(); | ^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:237:17 + --> tests/ui/checked_unwrap/simple_conditionals.rs:238:17 | LL | if r.is_ok() { | --------- because of this check @@ -295,7 +295,7 @@ LL | _ = r.as_ref().unwrap(); | ^^^^^^^^^^^^^^^^^^^ error: called `unwrap` on `x` after checking its variant with `is_some` - --> tests/ui/checked_unwrap/simple_conditionals.rs:246:17 + --> tests/ui/checked_unwrap/simple_conditionals.rs:247:17 | LL | if x.is_some() { | -------------- help: try: `if let Some() = x` @@ -303,7 +303,7 @@ LL | _ = x.unwrap(); | ^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:249:17 + --> tests/ui/checked_unwrap/simple_conditionals.rs:250:17 | LL | if x.is_some() { | ----------- because of this check @@ -312,7 +312,7 @@ LL | _ = x.unwrap(); | ^^^^^^^^^^ error: called `unwrap` on `option` after checking its variant with `is_some` - --> tests/ui/checked_unwrap/simple_conditionals.rs:259:26 + --> tests/ui/checked_unwrap/simple_conditionals.rs:260:26 | LL | if option.is_some() { | ------------------- help: try: `if let Some() = option` @@ -320,7 +320,7 @@ LL | println!("{:?}", option.unwrap()); | ^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:262:26 + --> tests/ui/checked_unwrap/simple_conditionals.rs:263:26 | LL | if option.is_some() { | ---------------- because of this check @@ -329,7 +329,7 @@ LL | println!("{:?}", option.unwrap()); | ^^^^^^^^^^^^^^^ error: called `unwrap` on `result` after checking its variant with `is_ok` - --> tests/ui/checked_unwrap/simple_conditionals.rs:269:26 + --> tests/ui/checked_unwrap/simple_conditionals.rs:270:26 | LL | if result.is_ok() { | ----------------- help: try: `if let Ok() = result` @@ -337,7 +337,7 @@ LL | println!("{:?}", result.unwrap()); | ^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:272:26 + --> tests/ui/checked_unwrap/simple_conditionals.rs:273:26 | LL | if result.is_ok() { | -------------- because of this check @@ -346,7 +346,7 @@ LL | println!("{:?}", result.unwrap()); | ^^^^^^^^^^^^^^^ error: called `unwrap` on `x` after checking its variant with `is_some` - --> tests/ui/checked_unwrap/simple_conditionals.rs:299:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:300:9 | LL | if x.is_some() { | -------------- help: try: `if let Some() = x` @@ -355,7 +355,7 @@ LL | x.unwrap(); | ^^^^^^^^^^ error: called `unwrap` on `x` after checking its variant with `is_some` - --> tests/ui/checked_unwrap/simple_conditionals.rs:305:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:306:9 | LL | if x.is_some() { | -------------- help: try: `if let Some() = &x` @@ -364,7 +364,7 @@ LL | x.as_ref().unwrap(); | ^^^^^^^^^^^^^^^^^^^ error: called `unwrap` on `sopt.option` after checking its variant with `is_some` - --> tests/ui/checked_unwrap/simple_conditionals.rs:321:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:322:9 | LL | let _res = if sopt.option.is_some() { | ------------------------ help: try: `if let Some() = sopt.option` @@ -372,7 +372,7 @@ LL | sopt.option.unwrap() | ^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:324:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:325:9 | LL | let _res = if sopt.option.is_some() { | --------------------- because of this check @@ -381,7 +381,7 @@ LL | sopt.option.unwrap() | ^^^^^^^^^^^^^^^^^^^^ error: called `unwrap` on `sopt.option` after checking its variant with `is_some` - --> tests/ui/checked_unwrap/simple_conditionals.rs:330:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:331:9 | LL | let _res = if sopt.option.is_some() { | ------------------------ help: try: `if let Some() = sopt.option` @@ -390,7 +390,7 @@ LL | sopt.option.unwrap() | ^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:334:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:335:9 | LL | let _res = if sopt.option.is_some() { | --------------------- because of this check @@ -399,7 +399,7 @@ LL | sopt.option.unwrap() | ^^^^^^^^^^^^^^^^^^^^ error: called `unwrap` on `topt.0` after checking its variant with `is_some` - --> tests/ui/checked_unwrap/simple_conditionals.rs:358:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:359:9 | LL | let _res = if topt.0.is_some() { | ------------------- help: try: `if let Some() = topt.0` @@ -407,7 +407,7 @@ LL | topt.0.unwrap() | ^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:361:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:362:9 | LL | let _res = if topt.0.is_some() { | ---------------- because of this check @@ -416,7 +416,7 @@ LL | topt.0.unwrap() | ^^^^^^^^^^^^^^^ error: called `unwrap` on `topt.0` after checking its variant with `is_some` - --> tests/ui/checked_unwrap/simple_conditionals.rs:367:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:368:9 | LL | let _res = if topt.0.is_some() { | ------------------- help: try: `if let Some() = topt.0` @@ -425,7 +425,7 @@ LL | topt.0.unwrap() | ^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:371:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:372:9 | LL | let _res = if topt.0.is_some() { | ---------------- because of this check @@ -434,7 +434,7 @@ LL | topt.0.unwrap() | ^^^^^^^^^^^^^^^ error: called `unwrap` on `sopt2.option.option` after checking its variant with `is_some` - --> tests/ui/checked_unwrap/simple_conditionals.rs:405:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:406:9 | LL | let _res = if sopt2.option.option.is_some() { | -------------------------------- help: try: `if let Some() = sopt2.option.option` @@ -442,7 +442,7 @@ LL | sopt2.option.option.unwrap() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:408:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:409:9 | LL | let _res = if sopt2.option.option.is_some() { | ----------------------------- because of this check @@ -451,7 +451,7 @@ LL | sopt2.option.option.unwrap() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: called `unwrap` on `sopt2.option.option` after checking its variant with `is_some` - --> tests/ui/checked_unwrap/simple_conditionals.rs:415:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:416:9 | LL | let _res = if sopt2.option.option.is_some() { | -------------------------------- help: try: `if let Some() = sopt2.option.option` @@ -460,7 +460,7 @@ LL | sopt2.option.option.unwrap() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:419:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:420:9 | LL | let _res = if sopt2.option.option.is_some() { | ----------------------------- because of this check @@ -469,7 +469,7 @@ LL | sopt2.option.option.unwrap() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: called `unwrap` on `sopt2.option.option` after checking its variant with `is_some` - --> tests/ui/checked_unwrap/simple_conditionals.rs:425:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:426:9 | LL | let _res = if sopt2.option.option.is_some() { | -------------------------------- help: try: `if let Some() = sopt2.option.option` @@ -478,7 +478,7 @@ LL | sopt2.option.option.unwrap() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:429:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:430:9 | LL | let _res = if sopt2.option.option.is_some() { | ----------------------------- because of this check @@ -487,7 +487,7 @@ LL | sopt2.option.option.unwrap() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: called `unwrap` on `topt.0` after checking its variant with `is_some` - --> tests/ui/checked_unwrap/simple_conditionals.rs:465:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:466:9 | LL | if topt.0.is_some() { | ------------------- help: try: `if let Some() = topt.0` @@ -496,7 +496,7 @@ LL | topt.0.unwrap(); | ^^^^^^^^^^^^^^^ error: called `unwrap` on `topt.0` after checking its variant with `is_some` - --> tests/ui/checked_unwrap/simple_conditionals.rs:471:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:472:9 | LL | if topt.0.is_some() { | ------------------- help: try: `if let Some() = &topt.0` diff --git a/tests/ui/iter_filter_is_ok.fixed b/tests/ui/iter_filter_is_ok.fixed index 9c8f999c0b5f..957284535c03 100644 --- a/tests/ui/iter_filter_is_ok.fixed +++ b/tests/ui/iter_filter_is_ok.fixed @@ -1,6 +1,6 @@ #![warn(clippy::iter_filter_is_ok)] #![allow(clippy::needless_borrow, clippy::redundant_closure)] -#![expect(clippy::map_identity, clippy::result_filter_map)] +#![expect(clippy::map_identity, clippy::result_filter_map, clippy::unnecessary_literal_option)] fn main() { { diff --git a/tests/ui/iter_filter_is_ok.rs b/tests/ui/iter_filter_is_ok.rs index 4fb9e8f6bd19..884219f0aa19 100644 --- a/tests/ui/iter_filter_is_ok.rs +++ b/tests/ui/iter_filter_is_ok.rs @@ -1,6 +1,6 @@ #![warn(clippy::iter_filter_is_ok)] #![allow(clippy::needless_borrow, clippy::redundant_closure)] -#![expect(clippy::map_identity, clippy::result_filter_map)] +#![expect(clippy::map_identity, clippy::result_filter_map, clippy::unnecessary_literal_option)] fn main() { { diff --git a/tests/ui/iter_filter_is_some.fixed b/tests/ui/iter_filter_is_some.fixed index 009721e7f03a..a72d9494e557 100644 --- a/tests/ui/iter_filter_is_some.fixed +++ b/tests/ui/iter_filter_is_some.fixed @@ -1,6 +1,11 @@ #![warn(clippy::iter_filter_is_some)] #![allow(clippy::needless_borrow, clippy::redundant_closure)] -#![expect(clippy::map_identity, clippy::option_filter_map, clippy::unnecessary_get_then_check)] +#![expect( + clippy::map_identity, + clippy::option_filter_map, + clippy::unnecessary_get_then_check, + clippy::unnecessary_literal_option +)] use std::collections::HashMap; diff --git a/tests/ui/iter_filter_is_some.rs b/tests/ui/iter_filter_is_some.rs index 1c0b5bd954b0..3ba331195695 100644 --- a/tests/ui/iter_filter_is_some.rs +++ b/tests/ui/iter_filter_is_some.rs @@ -1,6 +1,11 @@ #![warn(clippy::iter_filter_is_some)] #![allow(clippy::needless_borrow, clippy::redundant_closure)] -#![expect(clippy::map_identity, clippy::option_filter_map, clippy::unnecessary_get_then_check)] +#![expect( + clippy::map_identity, + clippy::option_filter_map, + clippy::unnecessary_get_then_check, + clippy::unnecessary_literal_option +)] use std::collections::HashMap; diff --git a/tests/ui/iter_filter_is_some.stderr b/tests/ui/iter_filter_is_some.stderr index 8790011cfe26..905ef42f0285 100644 --- a/tests/ui/iter_filter_is_some.stderr +++ b/tests/ui/iter_filter_is_some.stderr @@ -1,5 +1,5 @@ error: `filter` for `is_some` on iterator over `Option` - --> tests/ui/iter_filter_is_some.rs:9:58 + --> tests/ui/iter_filter_is_some.rs:14:58 | LL | let _ = vec![Some(1), None, Some(3)].into_iter().filter(Option::is_some); | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` @@ -8,55 +8,55 @@ LL | let _ = vec![Some(1), None, Some(3)].into_iter().filter(Option::is_ = help: to override `-D warnings` add `#[allow(clippy::iter_filter_is_some)]` error: `filter` for `is_some` on iterator over `Option` - --> tests/ui/iter_filter_is_some.rs:12:58 + --> tests/ui/iter_filter_is_some.rs:17:58 | LL | let _ = vec![Some(1), None, Some(3)].into_iter().filter(|a| a.is_some()); | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `is_some` on iterator over `Option` - --> tests/ui/iter_filter_is_some.rs:16:58 + --> tests/ui/iter_filter_is_some.rs:21:58 | LL | let _ = vec![Some(1), None, Some(3)].into_iter().filter(|o| { o.is_some() }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `is_some` on iterator over `Option` - --> tests/ui/iter_filter_is_some.rs:23:14 + --> tests/ui/iter_filter_is_some.rs:28:14 | LL | .filter(std::option::Option::is_some); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `is_some` on iterator over `Option` - --> tests/ui/iter_filter_is_some.rs:28:14 + --> tests/ui/iter_filter_is_some.rs:33:14 | LL | .filter(|a| std::option::Option::is_some(a)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `is_some` on iterator over `Option` - --> tests/ui/iter_filter_is_some.rs:32:58 + --> tests/ui/iter_filter_is_some.rs:37:58 | LL | let _ = vec![Some(1), None, Some(3)].into_iter().filter(|a| { std::option::Option::is_some(a) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `is_some` on iterator over `Option` - --> tests/ui/iter_filter_is_some.rs:37:58 + --> tests/ui/iter_filter_is_some.rs:42:58 | LL | let _ = vec![Some(1), None, Some(3)].into_iter().filter(|&a| a.is_some()); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `is_some` on iterator over `Option` - --> tests/ui/iter_filter_is_some.rs:41:58 + --> tests/ui/iter_filter_is_some.rs:46:58 | LL | let _ = vec![Some(1), None, Some(3)].into_iter().filter(|&o| { o.is_some() }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `is_some` on iterator over `Option` - --> tests/ui/iter_filter_is_some.rs:46:58 + --> tests/ui/iter_filter_is_some.rs:51:58 | LL | let _ = vec![Some(1), None, Some(3)].into_iter().filter(|ref a| a.is_some()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `is_some` on iterator over `Option` - --> tests/ui/iter_filter_is_some.rs:50:58 + --> tests/ui/iter_filter_is_some.rs:55:58 | LL | let _ = vec![Some(1), None, Some(3)].into_iter().filter(|ref o| { o.is_some() }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` diff --git a/tests/ui/manual_assert.edition2018.fixed b/tests/ui/manual_assert.edition2018.fixed index 1bdc17025e40..ae1eb254da73 100644 --- a/tests/ui/manual_assert.edition2018.fixed +++ b/tests/ui/manual_assert.edition2018.fixed @@ -3,6 +3,7 @@ //@[edition2021] edition:2021 #![warn(clippy::manual_assert)] +#![allow(clippy::unnecessary_literal_option)] #![expect(clippy::useless_vec)] macro_rules! one { diff --git a/tests/ui/manual_assert.edition2018.stderr b/tests/ui/manual_assert.edition2018.stderr index 764f6fbf793c..c81a85527527 100644 --- a/tests/ui/manual_assert.edition2018.stderr +++ b/tests/ui/manual_assert.edition2018.stderr @@ -1,5 +1,5 @@ error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:29:5 + --> tests/ui/manual_assert.rs:30:5 | LL | / if !a.is_empty() { LL | | @@ -16,7 +16,7 @@ LL + assert!(a.is_empty(), "qaqaq{:?}", a); | error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:33:5 + --> tests/ui/manual_assert.rs:34:5 | LL | / if !a.is_empty() { LL | | @@ -31,7 +31,7 @@ LL + assert!(a.is_empty(), "qwqwq"); | error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:51:5 + --> tests/ui/manual_assert.rs:52:5 | LL | / if b.is_empty() { LL | | @@ -46,7 +46,7 @@ LL + assert!(!b.is_empty(), "panic1"); | error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:55:5 + --> tests/ui/manual_assert.rs:56:5 | LL | / if b.is_empty() && a.is_empty() { LL | | @@ -61,7 +61,7 @@ LL + assert!(!(b.is_empty() && a.is_empty()), "panic2"); | error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:59:5 + --> tests/ui/manual_assert.rs:60:5 | LL | / if a.is_empty() && !b.is_empty() { LL | | @@ -76,7 +76,7 @@ LL + assert!(!(a.is_empty() && !b.is_empty()), "panic3"); | error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:63:5 + --> tests/ui/manual_assert.rs:64:5 | LL | / if b.is_empty() || a.is_empty() { LL | | @@ -91,7 +91,7 @@ LL + assert!(!(b.is_empty() || a.is_empty()), "panic4"); | error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:67:5 + --> tests/ui/manual_assert.rs:68:5 | LL | / if a.is_empty() || !b.is_empty() { LL | | @@ -106,7 +106,7 @@ LL + assert!(!(a.is_empty() || !b.is_empty()), "panic5"); | error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:71:5 + --> tests/ui/manual_assert.rs:72:5 | LL | / if a.is_empty() { LL | | @@ -121,7 +121,7 @@ LL + assert!(!a.is_empty(), "with expansion {}", one!()); | error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:84:5 + --> tests/ui/manual_assert.rs:85:5 | LL | / if a > 2 { LL | | @@ -145,7 +145,7 @@ LL + assert!(a <= 2, "panic with comment"); | error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:99:25 + --> tests/ui/manual_assert.rs:100:25 | LL | const BAR: () = if N == 0 { | _________________________^ @@ -161,7 +161,7 @@ LL ~ assert!(N != 0, ); | error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:113:5 + --> tests/ui/manual_assert.rs:114:5 | LL | / if !is_x86_feature_detected!("ssse3") { LL | | diff --git a/tests/ui/manual_assert.edition2021.fixed b/tests/ui/manual_assert.edition2021.fixed index 1bdc17025e40..ae1eb254da73 100644 --- a/tests/ui/manual_assert.edition2021.fixed +++ b/tests/ui/manual_assert.edition2021.fixed @@ -3,6 +3,7 @@ //@[edition2021] edition:2021 #![warn(clippy::manual_assert)] +#![allow(clippy::unnecessary_literal_option)] #![expect(clippy::useless_vec)] macro_rules! one { diff --git a/tests/ui/manual_assert.edition2021.stderr b/tests/ui/manual_assert.edition2021.stderr index 764f6fbf793c..c81a85527527 100644 --- a/tests/ui/manual_assert.edition2021.stderr +++ b/tests/ui/manual_assert.edition2021.stderr @@ -1,5 +1,5 @@ error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:29:5 + --> tests/ui/manual_assert.rs:30:5 | LL | / if !a.is_empty() { LL | | @@ -16,7 +16,7 @@ LL + assert!(a.is_empty(), "qaqaq{:?}", a); | error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:33:5 + --> tests/ui/manual_assert.rs:34:5 | LL | / if !a.is_empty() { LL | | @@ -31,7 +31,7 @@ LL + assert!(a.is_empty(), "qwqwq"); | error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:51:5 + --> tests/ui/manual_assert.rs:52:5 | LL | / if b.is_empty() { LL | | @@ -46,7 +46,7 @@ LL + assert!(!b.is_empty(), "panic1"); | error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:55:5 + --> tests/ui/manual_assert.rs:56:5 | LL | / if b.is_empty() && a.is_empty() { LL | | @@ -61,7 +61,7 @@ LL + assert!(!(b.is_empty() && a.is_empty()), "panic2"); | error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:59:5 + --> tests/ui/manual_assert.rs:60:5 | LL | / if a.is_empty() && !b.is_empty() { LL | | @@ -76,7 +76,7 @@ LL + assert!(!(a.is_empty() && !b.is_empty()), "panic3"); | error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:63:5 + --> tests/ui/manual_assert.rs:64:5 | LL | / if b.is_empty() || a.is_empty() { LL | | @@ -91,7 +91,7 @@ LL + assert!(!(b.is_empty() || a.is_empty()), "panic4"); | error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:67:5 + --> tests/ui/manual_assert.rs:68:5 | LL | / if a.is_empty() || !b.is_empty() { LL | | @@ -106,7 +106,7 @@ LL + assert!(!(a.is_empty() || !b.is_empty()), "panic5"); | error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:71:5 + --> tests/ui/manual_assert.rs:72:5 | LL | / if a.is_empty() { LL | | @@ -121,7 +121,7 @@ LL + assert!(!a.is_empty(), "with expansion {}", one!()); | error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:84:5 + --> tests/ui/manual_assert.rs:85:5 | LL | / if a > 2 { LL | | @@ -145,7 +145,7 @@ LL + assert!(a <= 2, "panic with comment"); | error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:99:25 + --> tests/ui/manual_assert.rs:100:25 | LL | const BAR: () = if N == 0 { | _________________________^ @@ -161,7 +161,7 @@ LL ~ assert!(N != 0, ); | error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:113:5 + --> tests/ui/manual_assert.rs:114:5 | LL | / if !is_x86_feature_detected!("ssse3") { LL | | diff --git a/tests/ui/manual_assert.rs b/tests/ui/manual_assert.rs index 374f8448af42..2f57b9bbe5ad 100644 --- a/tests/ui/manual_assert.rs +++ b/tests/ui/manual_assert.rs @@ -3,6 +3,7 @@ //@[edition2021] edition:2021 #![warn(clippy::manual_assert)] +#![allow(clippy::unnecessary_literal_option)] #![expect(clippy::useless_vec)] macro_rules! one { diff --git a/tests/ui/manual_is_variant_and.fixed b/tests/ui/manual_is_variant_and.fixed index d042fe898816..1d1946172f4c 100644 --- a/tests/ui/manual_is_variant_and.fixed +++ b/tests/ui/manual_is_variant_and.fixed @@ -1,6 +1,6 @@ //@aux-build:option_helpers.rs #![warn(clippy::manual_is_variant_and)] -#![allow(clippy::redundant_closure)] +#![allow(clippy::redundant_closure, clippy::unnecessary_literal_option)] #[macro_use] extern crate option_helpers; diff --git a/tests/ui/manual_is_variant_and.rs b/tests/ui/manual_is_variant_and.rs index 482c539cb62e..f082e7cbeb5a 100644 --- a/tests/ui/manual_is_variant_and.rs +++ b/tests/ui/manual_is_variant_and.rs @@ -1,6 +1,6 @@ //@aux-build:option_helpers.rs #![warn(clippy::manual_is_variant_and)] -#![allow(clippy::redundant_closure)] +#![allow(clippy::redundant_closure, clippy::unnecessary_literal_option)] #[macro_use] extern crate option_helpers; diff --git a/tests/ui/manual_let_else_match.fixed b/tests/ui/manual_let_else_match.fixed index fca72e4b97ea..d013babc92ce 100644 --- a/tests/ui/manual_let_else_match.fixed +++ b/tests/ui/manual_let_else_match.fixed @@ -1,7 +1,7 @@ #![warn(clippy::manual_let_else)] // Ensure that we don't conflict with match -> if let lints #![deny(clippy::single_match, clippy::single_match_else)] -#![allow(irrefutable_let_patterns)] +#![allow(irrefutable_let_patterns, clippy::unnecessary_literal_option)] #![expect(clippy::let_unit_value, clippy::redundant_at_rest_pattern)] fn f() -> Result { diff --git a/tests/ui/manual_let_else_match.rs b/tests/ui/manual_let_else_match.rs index 4cd442164320..372c45f7d256 100644 --- a/tests/ui/manual_let_else_match.rs +++ b/tests/ui/manual_let_else_match.rs @@ -1,7 +1,7 @@ #![warn(clippy::manual_let_else)] // Ensure that we don't conflict with match -> if let lints #![deny(clippy::single_match, clippy::single_match_else)] -#![allow(irrefutable_let_patterns)] +#![allow(irrefutable_let_patterns, clippy::unnecessary_literal_option)] #![expect(clippy::let_unit_value, clippy::redundant_at_rest_pattern)] fn f() -> Result { diff --git a/tests/ui/match_like_matches_macro.fixed b/tests/ui/match_like_matches_macro.fixed index 9ca9005c8bcd..bf666a8bbdc9 100644 --- a/tests/ui/match_like_matches_macro.fixed +++ b/tests/ui/match_like_matches_macro.fixed @@ -1,5 +1,9 @@ #![warn(clippy::match_like_matches_macro)] -#![allow(irrefutable_let_patterns, clippy::redundant_guards)] +#![allow( + irrefutable_let_patterns, + clippy::redundant_guards, + clippy::unnecessary_literal_option +)] #![expect(clippy::needless_borrowed_reference)] fn main() { diff --git a/tests/ui/match_like_matches_macro.rs b/tests/ui/match_like_matches_macro.rs index 1d94afac952c..cefee0afb603 100644 --- a/tests/ui/match_like_matches_macro.rs +++ b/tests/ui/match_like_matches_macro.rs @@ -1,5 +1,9 @@ #![warn(clippy::match_like_matches_macro)] -#![allow(irrefutable_let_patterns, clippy::redundant_guards)] +#![allow( + irrefutable_let_patterns, + clippy::redundant_guards, + clippy::unnecessary_literal_option +)] #![expect(clippy::needless_borrowed_reference)] fn main() { diff --git a/tests/ui/match_like_matches_macro.stderr b/tests/ui/match_like_matches_macro.stderr index 3caa3572e43b..d21c0970850b 100644 --- a/tests/ui/match_like_matches_macro.stderr +++ b/tests/ui/match_like_matches_macro.stderr @@ -1,5 +1,5 @@ error: match expression looks like `matches!` macro - --> tests/ui/match_like_matches_macro.rs:9:14 + --> tests/ui/match_like_matches_macro.rs:13:14 | LL | let _y = match x { | ______________^ @@ -20,7 +20,7 @@ LL + let _y = matches!(x, Some(0)); | error: redundant pattern matching - --> tests/ui/match_like_matches_macro.rs:16:14 + --> tests/ui/match_like_matches_macro.rs:20:14 | LL | let _w = match x { | ______________^ @@ -41,7 +41,7 @@ LL + let _w = x.is_some(); | error: redundant pattern matching - --> tests/ui/match_like_matches_macro.rs:23:14 + --> tests/ui/match_like_matches_macro.rs:27:14 | LL | let _z = match x { | ______________^ @@ -60,7 +60,7 @@ LL + let _z = x.is_none(); | error: match expression looks like `matches!` macro - --> tests/ui/match_like_matches_macro.rs:30:15 + --> tests/ui/match_like_matches_macro.rs:34:15 | LL | let _zz = match x { | _______________^ @@ -79,7 +79,7 @@ LL + let _zz = !matches!(x, Some(r) if r == 0); | error: `if let .. else` expression looks like `matches!` macro - --> tests/ui/match_like_matches_macro.rs:37:16 + --> tests/ui/match_like_matches_macro.rs:41:16 | LL | let _zzz = if let Some(5) = x { true } else { false }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -91,7 +91,7 @@ LL + let _zzz = matches!(x, Some(5)); | error: match expression looks like `matches!` macro - --> tests/ui/match_like_matches_macro.rs:62:20 + --> tests/ui/match_like_matches_macro.rs:66:20 | LL | let _ans = match x { | ____________________^ @@ -112,7 +112,7 @@ LL + let _ans = matches!(x, E::A(_) | E::B(_)); | error: match expression looks like `matches!` macro - --> tests/ui/match_like_matches_macro.rs:73:20 + --> tests/ui/match_like_matches_macro.rs:77:20 | LL | let _ans = match x { | ____________________^ @@ -136,7 +136,7 @@ LL + let _ans = matches!(x, E::A(_) | E::B(_)); | error: match expression looks like `matches!` macro - --> tests/ui/match_like_matches_macro.rs:84:20 + --> tests/ui/match_like_matches_macro.rs:88:20 | LL | let _ans = match x { | ____________________^ @@ -157,7 +157,7 @@ LL + let _ans = !matches!(x, E::B(_) | E::C); | error: match expression looks like `matches!` macro - --> tests/ui/match_like_matches_macro.rs:145:18 + --> tests/ui/match_like_matches_macro.rs:149:18 | LL | let _z = match &z { | __________________^ @@ -176,7 +176,7 @@ LL + let _z = matches!(z, Some(3)); | error: match expression looks like `matches!` macro - --> tests/ui/match_like_matches_macro.rs:155:18 + --> tests/ui/match_like_matches_macro.rs:159:18 | LL | let _z = match &z { | __________________^ @@ -195,7 +195,7 @@ LL + let _z = matches!(&z, Some(3)); | error: match expression looks like `matches!` macro - --> tests/ui/match_like_matches_macro.rs:173:21 + --> tests/ui/match_like_matches_macro.rs:177:21 | LL | let _ = match &z { | _____________________^ @@ -214,7 +214,7 @@ LL + let _ = matches!(&z, AnEnum::X); | error: match expression looks like `matches!` macro - --> tests/ui/match_like_matches_macro.rs:188:20 + --> tests/ui/match_like_matches_macro.rs:192:20 | LL | let _res = match &val { | ____________________^ @@ -233,7 +233,7 @@ LL + let _res = matches!(&val, &Some(ref _a)); | error: match expression looks like `matches!` macro - --> tests/ui/match_like_matches_macro.rs:201:20 + --> tests/ui/match_like_matches_macro.rs:205:20 | LL | let _res = match &val { | ____________________^ @@ -252,7 +252,7 @@ LL + let _res = matches!(&val, &Some(ref _a)); | error: match expression looks like `matches!` macro - --> tests/ui/match_like_matches_macro.rs:260:14 + --> tests/ui/match_like_matches_macro.rs:264:14 | LL | let _y = match Some(5) { | ______________^ @@ -271,7 +271,7 @@ LL + let _y = matches!(Some(5), Some(0)); | error: match expression looks like `matches!` macro - --> tests/ui/match_like_matches_macro.rs:270:13 + --> tests/ui/match_like_matches_macro.rs:274:13 | LL | let _ = match opt { | _____________^ @@ -290,7 +290,7 @@ LL + let _ = matches!(opt, Some(first) if (if let Some(second) = first { tru | error: match expression looks like `matches!` macro - --> tests/ui/match_like_matches_macro.rs:291:5 + --> tests/ui/match_like_matches_macro.rs:295:5 | LL | / match typeid!(T) { LL | | _ => true, @@ -308,7 +308,7 @@ LL + matches!(typeid!(T), _); | error: `if let .. else` expression looks like `matches!` macro - --> tests/ui/match_like_matches_macro.rs:297:5 + --> tests/ui/match_like_matches_macro.rs:301:5 | LL | if let _ = typeid!(U) { true } else { false } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/match_ref_pats.fixed b/tests/ui/match_ref_pats.fixed index 58a580cc099f..f59b7650a61d 100644 --- a/tests/ui/match_ref_pats.fixed +++ b/tests/ui/match_ref_pats.fixed @@ -1,4 +1,5 @@ #![warn(clippy::match_ref_pats)] +#![allow(clippy::unnecessary_literal_option)] #![expect(clippy::diverging_sub_expression, clippy::empty_loop, clippy::enum_variant_names)] fn ref_pats() { diff --git a/tests/ui/match_ref_pats.rs b/tests/ui/match_ref_pats.rs index 8b4f7e1febf4..8207d99fdaaf 100644 --- a/tests/ui/match_ref_pats.rs +++ b/tests/ui/match_ref_pats.rs @@ -1,4 +1,5 @@ #![warn(clippy::match_ref_pats)] +#![allow(clippy::unnecessary_literal_option)] #![expect(clippy::diverging_sub_expression, clippy::empty_loop, clippy::enum_variant_names)] fn ref_pats() { diff --git a/tests/ui/match_ref_pats.stderr b/tests/ui/match_ref_pats.stderr index 0cc92391b31f..2b4ef7ef9923 100644 --- a/tests/ui/match_ref_pats.stderr +++ b/tests/ui/match_ref_pats.stderr @@ -1,5 +1,5 @@ error: you don't need to add `&` to all patterns - --> tests/ui/match_ref_pats.rs:7:9 + --> tests/ui/match_ref_pats.rs:8:9 | LL | / match v { LL | | @@ -19,7 +19,7 @@ LL ~ None => println!("none"), | error: you don't need to add `&` to both the expression and the patterns - --> tests/ui/match_ref_pats.rs:25:5 + --> tests/ui/match_ref_pats.rs:26:5 | LL | / match &w { LL | | @@ -37,7 +37,7 @@ LL ~ None => println!("none"), | error: redundant pattern matching - --> tests/ui/match_ref_pats.rs:38:12 + --> tests/ui/match_ref_pats.rs:39:12 | LL | if let &None = a { | ^^^^^ @@ -51,7 +51,7 @@ LL + if a.is_none() { | error: redundant pattern matching - --> tests/ui/match_ref_pats.rs:44:12 + --> tests/ui/match_ref_pats.rs:45:12 | LL | if let &None = &b { | ^^^^^ @@ -63,7 +63,7 @@ LL + if b.is_none() { | error: you don't need to add `&` to all patterns - --> tests/ui/match_ref_pats.rs:105:9 + --> tests/ui/match_ref_pats.rs:106:9 | LL | / match foobar_variant!(0) { LL | | diff --git a/tests/ui/nonminimal_bool_methods.fixed b/tests/ui/nonminimal_bool_methods.fixed index 9ce11b8afb86..4d50c409e8fe 100644 --- a/tests/ui/nonminimal_bool_methods.fixed +++ b/tests/ui/nonminimal_bool_methods.fixed @@ -1,5 +1,9 @@ #![warn(clippy::nonminimal_bool)] -#![expect(clippy::diverging_sub_expression, clippy::needless_ifs)] +#![expect( + clippy::diverging_sub_expression, + clippy::needless_ifs, + clippy::unnecessary_literal_option +)] fn methods_with_negation() { let a: Option = unimplemented!(); diff --git a/tests/ui/nonminimal_bool_methods.rs b/tests/ui/nonminimal_bool_methods.rs index 75ecafdc7c38..d4e93f11ebc8 100644 --- a/tests/ui/nonminimal_bool_methods.rs +++ b/tests/ui/nonminimal_bool_methods.rs @@ -1,5 +1,9 @@ #![warn(clippy::nonminimal_bool)] -#![expect(clippy::diverging_sub_expression, clippy::needless_ifs)] +#![expect( + clippy::diverging_sub_expression, + clippy::needless_ifs, + clippy::unnecessary_literal_option +)] fn methods_with_negation() { let a: Option = unimplemented!(); diff --git a/tests/ui/nonminimal_bool_methods.stderr b/tests/ui/nonminimal_bool_methods.stderr index 948c28dcb537..8ff5287b1b3b 100644 --- a/tests/ui/nonminimal_bool_methods.stderr +++ b/tests/ui/nonminimal_bool_methods.stderr @@ -1,5 +1,5 @@ error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:8:13 + --> tests/ui/nonminimal_bool_methods.rs:12:13 | LL | let _ = !a.is_some(); | ^^^^^^^^^^^^ help: try: `a.is_none()` @@ -8,25 +8,25 @@ LL | let _ = !a.is_some(); = help: to override `-D warnings` add `#[allow(clippy::nonminimal_bool)]` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:11:13 + --> tests/ui/nonminimal_bool_methods.rs:15:13 | LL | let _ = !a.is_none(); | ^^^^^^^^^^^^ help: try: `a.is_some()` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:14:13 + --> tests/ui/nonminimal_bool_methods.rs:18:13 | LL | let _ = !b.is_err(); | ^^^^^^^^^^^ help: try: `b.is_ok()` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:17:13 + --> tests/ui/nonminimal_bool_methods.rs:21:13 | LL | let _ = !b.is_ok(); | ^^^^^^^^^^ help: try: `b.is_err()` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:20:13 + --> tests/ui/nonminimal_bool_methods.rs:24:13 | LL | let _ = !(a.is_some() && !c); | ^^^^^^^^^^^^^^^^^^^^ @@ -38,7 +38,7 @@ LL + let _ = a.is_none() || c; | error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:22:13 + --> tests/ui/nonminimal_bool_methods.rs:26:13 | LL | let _ = !(a.is_some() || !c); | ^^^^^^^^^^^^^^^^^^^^ @@ -50,217 +50,217 @@ LL + let _ = a.is_none() && c; | error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:24:26 + --> tests/ui/nonminimal_bool_methods.rs:28:26 | LL | let _ = !(!c ^ c) || !a.is_some(); | ^^^^^^^^^^^^ help: try: `a.is_none()` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:26:25 + --> tests/ui/nonminimal_bool_methods.rs:30:25 | LL | let _ = (!c ^ c) || !a.is_some(); | ^^^^^^^^^^^^ help: try: `a.is_none()` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:28:23 + --> tests/ui/nonminimal_bool_methods.rs:32:23 | LL | let _ = !c ^ c || !a.is_some(); | ^^^^^^^^^^^^ help: try: `a.is_none()` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:101:8 + --> tests/ui/nonminimal_bool_methods.rs:105:8 | LL | if !res.is_ok() {} | ^^^^^^^^^^^^ help: try: `res.is_err()` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:103:8 + --> tests/ui/nonminimal_bool_methods.rs:107:8 | LL | if !res.is_err() {} | ^^^^^^^^^^^^^ help: try: `res.is_ok()` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:107:8 + --> tests/ui/nonminimal_bool_methods.rs:111:8 | LL | if !res.is_some() {} | ^^^^^^^^^^^^^^ help: try: `res.is_none()` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:109:8 + --> tests/ui/nonminimal_bool_methods.rs:113:8 | LL | if !res.is_none() {} | ^^^^^^^^^^^^^^ help: try: `res.is_some()` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:126:8 + --> tests/ui/nonminimal_bool_methods.rs:130:8 | LL | if !(a as u64 >= b) {} | ^^^^^^^^^^^^^^^^ help: try: `((a as u64) < b)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:128:8 + --> tests/ui/nonminimal_bool_methods.rs:132:8 | LL | if !((a as u64) >= b) {} | ^^^^^^^^^^^^^^^^^^ help: try: `((a as u64) < b)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:130:8 + --> tests/ui/nonminimal_bool_methods.rs:134:8 | LL | if !(a as u64 <= b) {} | ^^^^^^^^^^^^^^^^ help: try: `(a as u64 > b)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:138:8 + --> tests/ui/nonminimal_bool_methods.rs:142:8 | LL | if !(a >= b) as i32 == c {} | ^^^^^^^^^ help: try: `(a < b)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:140:8 + --> tests/ui/nonminimal_bool_methods.rs:144:8 | LL | if !(a >= b) | !(a <= c) {} | ^^^^^^^^^ help: try: `(a < b)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:140:20 + --> tests/ui/nonminimal_bool_methods.rs:144:20 | LL | if !(a >= b) | !(a <= c) {} | ^^^^^^^^^ help: try: `(a > c)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:145:8 + --> tests/ui/nonminimal_bool_methods.rs:149:8 | LL | if !res.is_ok() as i32 == c {} | ^^^^^^^^^^^^ help: try: `res.is_err()` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:147:8 + --> tests/ui/nonminimal_bool_methods.rs:151:8 | LL | if !res.is_ok() | !opt.is_none() {} | ^^^^^^^^^^^^ help: try: `res.is_err()` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:147:23 + --> tests/ui/nonminimal_bool_methods.rs:151:23 | LL | if !res.is_ok() | !opt.is_none() {} | ^^^^^^^^^^^^^^ help: try: `opt.is_some()` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:152:9 + --> tests/ui/nonminimal_bool_methods.rs:156:9 | LL | (!(4 > 3)).b() | ^^^^^^^^^^ help: try: `(4 <= 3)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:178:9 + --> tests/ui/nonminimal_bool_methods.rs:182:9 | LL | _ = !opt.is_some_and(|x| x < 1000); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x >= 1000)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:180:9 + --> tests/ui/nonminimal_bool_methods.rs:184:9 | LL | _ = !opt.is_some_and(|x| x <= 1000); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x > 1000)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:182:9 + --> tests/ui/nonminimal_bool_methods.rs:186:9 | LL | _ = !opt.is_some_and(|x| x > 1000); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x <= 1000)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:184:9 + --> tests/ui/nonminimal_bool_methods.rs:188:9 | LL | _ = !opt.is_some_and(|x| x >= 1000); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x < 1000)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:186:9 + --> tests/ui/nonminimal_bool_methods.rs:190:9 | LL | _ = !opt.is_some_and(|x| x == 1000); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x != 1000)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:188:9 + --> tests/ui/nonminimal_bool_methods.rs:192:9 | LL | _ = !opt.is_some_and(|x| x != 1000); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x == 1000)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:198:9 + --> tests/ui/nonminimal_bool_methods.rs:202:9 | LL | _ = !opt.is_none_or(|x| x < 1000); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x >= 1000)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:200:9 + --> tests/ui/nonminimal_bool_methods.rs:204:9 | LL | _ = !opt.is_none_or(|x| x <= 1000); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x > 1000)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:202:9 + --> tests/ui/nonminimal_bool_methods.rs:206:9 | LL | _ = !opt.is_none_or(|x| x > 1000); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x <= 1000)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:204:9 + --> tests/ui/nonminimal_bool_methods.rs:208:9 | LL | _ = !opt.is_none_or(|x| x >= 1000); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x < 1000)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:206:9 + --> tests/ui/nonminimal_bool_methods.rs:210:9 | LL | _ = !opt.is_none_or(|x| x == 1000); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x != 1000)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:208:9 + --> tests/ui/nonminimal_bool_methods.rs:212:9 | LL | _ = !opt.is_none_or(|x| x != 1000); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x == 1000)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:216:9 + --> tests/ui/nonminimal_bool_methods.rs:220:9 | LL | _ = !opt.is_some_and(|x| !x); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:221:9 + --> tests/ui/nonminimal_bool_methods.rs:225:9 | LL | _ = !opt.is_none_or(|x| !x); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:229:9 + --> tests/ui/nonminimal_bool_methods.rs:233:9 | LL | _ = !opt.is_some_and(|x| x.is_ok()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x.is_err())` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:231:9 + --> tests/ui/nonminimal_bool_methods.rs:235:9 | LL | _ = !opt.is_some_and(|x| x.is_err()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x.is_ok())` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:233:9 + --> tests/ui/nonminimal_bool_methods.rs:237:9 | LL | _ = !opt.is_none_or(|x| x.is_ok()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x.is_err())` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:235:9 + --> tests/ui/nonminimal_bool_methods.rs:239:9 | LL | _ = !opt.is_none_or(|x| x.is_err()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x.is_ok())` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:246:5 + --> tests/ui/nonminimal_bool_methods.rs:250:5 | LL | !(vec![1, 2, 3] <= vec![1, 2, 3, 3]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(vec![1, 2, 3] > vec![1, 2, 3, 3])` diff --git a/tests/ui/or_fun_call.fixed b/tests/ui/or_fun_call.fixed index db65a33ecdcf..c2b4a2309783 100644 --- a/tests/ui/or_fun_call.fixed +++ b/tests/ui/or_fun_call.fixed @@ -2,7 +2,8 @@ #![allow( clippy::map_or_identity, clippy::unnecessary_option_map_or_else, - clippy::unnecessary_result_map_or_else + clippy::unnecessary_result_map_or_else, + clippy::unnecessary_literal_option )] #![expect(clippy::unnecessary_literal_unwrap, clippy::useless_vec)] diff --git a/tests/ui/or_fun_call.rs b/tests/ui/or_fun_call.rs index 6c31be62f1f5..282a499bea1b 100644 --- a/tests/ui/or_fun_call.rs +++ b/tests/ui/or_fun_call.rs @@ -2,7 +2,8 @@ #![allow( clippy::map_or_identity, clippy::unnecessary_option_map_or_else, - clippy::unnecessary_result_map_or_else + clippy::unnecessary_result_map_or_else, + clippy::unnecessary_literal_option )] #![expect(clippy::unnecessary_literal_unwrap, clippy::useless_vec)] diff --git a/tests/ui/or_fun_call.stderr b/tests/ui/or_fun_call.stderr index 32d93bab3633..12a15e3e7572 100644 --- a/tests/ui/or_fun_call.stderr +++ b/tests/ui/or_fun_call.stderr @@ -1,5 +1,5 @@ error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:50:22 + --> tests/ui/or_fun_call.rs:51:22 | LL | with_constructor.unwrap_or(make()); | ^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(make)` @@ -8,7 +8,7 @@ LL | with_constructor.unwrap_or(make()); = help: to override `-D warnings` add `#[allow(clippy::or_fun_call)]` error: use of `unwrap_or` to construct default value - --> tests/ui/or_fun_call.rs:54:14 + --> tests/ui/or_fun_call.rs:55:14 | LL | with_new.unwrap_or(Vec::new()); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` @@ -17,205 +17,205 @@ LL | with_new.unwrap_or(Vec::new()); = help: to override `-D warnings` add `#[allow(clippy::unwrap_or_default)]` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:58:21 + --> tests/ui/or_fun_call.rs:59:21 | LL | with_const_args.unwrap_or(Vec::with_capacity(12)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| Vec::with_capacity(12))` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:62:14 + --> tests/ui/or_fun_call.rs:63:14 | LL | with_err.unwrap_or(make()); | ^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|_| make())` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:66:19 + --> tests/ui/or_fun_call.rs:67:19 | LL | with_err_args.unwrap_or(Vec::with_capacity(12)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|_| Vec::with_capacity(12))` error: use of `unwrap_or` to construct default value - --> tests/ui/or_fun_call.rs:70:24 + --> tests/ui/or_fun_call.rs:71:24 | LL | with_default_trait.unwrap_or(Default::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or` to construct default value - --> tests/ui/or_fun_call.rs:74:23 + --> tests/ui/or_fun_call.rs:75:23 | LL | with_default_type.unwrap_or(u64::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:94:18 + --> tests/ui/or_fun_call.rs:95:18 | LL | self_default.unwrap_or(::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(::default)` error: use of `unwrap_or` to construct default value - --> tests/ui/or_fun_call.rs:98:18 + --> tests/ui/or_fun_call.rs:99:18 | LL | real_default.unwrap_or(::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or` to construct default value - --> tests/ui/or_fun_call.rs:102:14 + --> tests/ui/or_fun_call.rs:103:14 | LL | with_vec.unwrap_or(Vec::new()); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:106:21 + --> tests/ui/or_fun_call.rs:107:21 | LL | without_default.unwrap_or(Foo::new()); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(Foo::new)` error: use of `or_insert` to construct default value - --> tests/ui/or_fun_call.rs:110:19 + --> tests/ui/or_fun_call.rs:111:19 | LL | map.entry(42).or_insert(String::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_default()` error: use of `or_insert` to construct default value - --> tests/ui/or_fun_call.rs:114:23 + --> tests/ui/or_fun_call.rs:115:23 | LL | map_vec.entry(42).or_insert(Vec::new()); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `or_default()` error: use of `or_insert` to construct default value - --> tests/ui/or_fun_call.rs:118:21 + --> tests/ui/or_fun_call.rs:119:21 | LL | btree.entry(42).or_insert(String::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_default()` error: use of `or_insert` to construct default value - --> tests/ui/or_fun_call.rs:122:25 + --> tests/ui/or_fun_call.rs:123:25 | LL | btree_vec.entry(42).or_insert(Vec::new()); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `or_default()` error: use of `unwrap_or` to construct default value - --> tests/ui/or_fun_call.rs:126:21 + --> tests/ui/or_fun_call.rs:127:21 | LL | let _ = stringy.unwrap_or(String::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: function call inside of `ok_or` - --> tests/ui/or_fun_call.rs:131:17 + --> tests/ui/or_fun_call.rs:132:17 | LL | let _ = opt.ok_or(format!("{} world.", hello)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ok_or_else(|| format!("{} world.", hello))` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:136:21 + --> tests/ui/or_fun_call.rs:137:21 | LL | let _ = Some(1).unwrap_or(map[&1]); | ^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| map[&1])` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:139:21 + --> tests/ui/or_fun_call.rs:140:21 | LL | let _ = Some(1).unwrap_or(map[&1]); | ^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| map[&1])` error: function call inside of `or` - --> tests/ui/or_fun_call.rs:164:35 + --> tests/ui/or_fun_call.rs:165:35 | LL | let _ = Some("a".to_string()).or(Some("b".to_string())); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_else(|| Some("b".to_string()))` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:206:18 + --> tests/ui/or_fun_call.rs:207:18 | LL | None.unwrap_or(ptr_to_ref(s)); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| ptr_to_ref(s))` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:214:14 + --> tests/ui/or_fun_call.rs:215:14 | LL | None.unwrap_or(unsafe { ptr_to_ref(s) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| unsafe { ptr_to_ref(s) })` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:217:14 + --> tests/ui/or_fun_call.rs:218:14 | LL | None.unwrap_or( unsafe { ptr_to_ref(s) } ); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| unsafe { ptr_to_ref(s) })` error: function call inside of `map_or` - --> tests/ui/or_fun_call.rs:293:25 + --> tests/ui/or_fun_call.rs:294:25 | LL | let _ = Some(4).map_or(g(), |v| v); | ^^^^^^^^^^^^^^^^^^ help: try: `map_or_else(g, |v| v)` error: function call inside of `map_or` - --> tests/ui/or_fun_call.rs:295:25 + --> tests/ui/or_fun_call.rs:296:25 | LL | let _ = Some(4).map_or(g(), f); | ^^^^^^^^^^^^^^ help: try: `map_or_else(g, f)` error: function call inside of `map_or` - --> tests/ui/or_fun_call.rs:298:25 + --> tests/ui/or_fun_call.rs:299:25 | LL | let _ = Some(4).map_or("asd".to_string().len() as i32, f); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map_or_else(|| "asd".to_string().len() as i32, f)` error: use of `unwrap_or_else` to construct default value - --> tests/ui/or_fun_call.rs:329:18 + --> tests/ui/or_fun_call.rs:330:18 | LL | with_new.unwrap_or_else(Vec::new); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> tests/ui/or_fun_call.rs:333:28 + --> tests/ui/or_fun_call.rs:334:28 | LL | with_default_trait.unwrap_or_else(Default::default); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> tests/ui/or_fun_call.rs:337:27 + --> tests/ui/or_fun_call.rs:338:27 | LL | with_default_type.unwrap_or_else(u64::default); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> tests/ui/or_fun_call.rs:341:22 + --> tests/ui/or_fun_call.rs:342:22 | LL | real_default.unwrap_or_else(::default); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `or_insert_with` to construct default value - --> tests/ui/or_fun_call.rs:345:23 + --> tests/ui/or_fun_call.rs:346:23 | LL | map.entry(42).or_insert_with(String::new); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_default()` error: use of `or_insert_with` to construct default value - --> tests/ui/or_fun_call.rs:349:25 + --> tests/ui/or_fun_call.rs:350:25 | LL | btree.entry(42).or_insert_with(String::new); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_default()` error: use of `unwrap_or_else` to construct default value - --> tests/ui/or_fun_call.rs:353:25 + --> tests/ui/or_fun_call.rs:354:25 | LL | let _ = stringy.unwrap_or_else(String::new); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:395:17 + --> tests/ui/or_fun_call.rs:396:17 | LL | let _ = opt.unwrap_or({ f() }); // suggest `.unwrap_or_else(f)` | ^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(f)` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:400:17 + --> tests/ui/or_fun_call.rs:401:17 | LL | let _ = opt.unwrap_or(f() + 1); // suggest `.unwrap_or_else(|| f() + 1)` | ^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| f() + 1)` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:405:17 + --> tests/ui/or_fun_call.rs:406:17 | LL | let _ = opt.unwrap_or({ | _________________^ @@ -235,79 +235,79 @@ LL ~ }); | error: function call inside of `map_or` - --> tests/ui/or_fun_call.rs:411:17 + --> tests/ui/or_fun_call.rs:412:17 | LL | let _ = opt.map_or(f() + 1, |v| v); // suggest `.map_or_else(|| f() + 1, |v| v)` | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `map_or_else(|| f() + 1, |v| v)` error: use of `unwrap_or` to construct default value - --> tests/ui/or_fun_call.rs:416:17 + --> tests/ui/or_fun_call.rs:417:17 | LL | let _ = opt.unwrap_or({ i32::default() }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:423:21 + --> tests/ui/or_fun_call.rs:424:21 | LL | let _ = opt_foo.unwrap_or(Foo { val: String::default() }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| Foo { val: String::default() })` error: function call inside of `map_or` - --> tests/ui/or_fun_call.rs:438:19 + --> tests/ui/or_fun_call.rs:439:19 | LL | let _ = x.map_or(g(), |v| v); | ^^^^^^^^^^^^^^^^^^ help: try: `map_or_else(|_| g(), |v| v)` error: function call inside of `map_or` - --> tests/ui/or_fun_call.rs:440:19 + --> tests/ui/or_fun_call.rs:441:19 | LL | let _ = x.map_or(g(), f); | ^^^^^^^^^^^^^^ help: try: `map_or_else(|_| g(), f)` error: function call inside of `map_or` - --> tests/ui/or_fun_call.rs:443:19 + --> tests/ui/or_fun_call.rs:444:19 | LL | let _ = x.map_or("asd".to_string().len() as i32, f); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map_or_else(|_| "asd".to_string().len() as i32, f)` error: function call inside of `get_or_insert` - --> tests/ui/or_fun_call.rs:454:15 + --> tests/ui/or_fun_call.rs:455:15 | LL | let _ = x.get_or_insert(g()); | ^^^^^^^^^^^^^^^^^^ help: try: `get_or_insert_with(g)` error: function call inside of `and` - --> tests/ui/or_fun_call.rs:464:15 + --> tests/ui/or_fun_call.rs:465:15 | LL | let _ = x.and(g()); | ^^^^^^^^ help: try: `and_then(|_| g())` error: function call inside of `and` - --> tests/ui/or_fun_call.rs:474:15 + --> tests/ui/or_fun_call.rs:475:15 | LL | let _ = x.and(g()); | ^^^^^^^^ help: try: `and_then(|_| g())` error: use of `unwrap_or` to construct default value - --> tests/ui/or_fun_call.rs:480:17 + --> tests/ui/or_fun_call.rs:481:17 | LL | let _ = opt.unwrap_or(Default::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:482:17 + --> tests/ui/or_fun_call.rs:483:17 | LL | let _ = res.unwrap_or(Default::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|_| Default::default())` error: use of `unwrap_or` to construct default value - --> tests/ui/or_fun_call.rs:488:17 + --> tests/ui/or_fun_call.rs:489:17 | LL | let _ = opt.unwrap_or(Default::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or` to construct default value - --> tests/ui/or_fun_call.rs:490:17 + --> tests/ui/or_fun_call.rs:491:17 | LL | let _ = res.unwrap_or(Default::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` diff --git a/tests/ui/partialeq_to_none.fixed b/tests/ui/partialeq_to_none.fixed index 9f9edb2e2448..41c247c158d9 100644 --- a/tests/ui/partialeq_to_none.fixed +++ b/tests/ui/partialeq_to_none.fixed @@ -1,4 +1,5 @@ #![warn(clippy::partialeq_to_none)] +#![allow(clippy::unnecessary_literal_option)] #![expect(clippy::eq_op, clippy::needless_ifs)] struct Foobar; diff --git a/tests/ui/partialeq_to_none.rs b/tests/ui/partialeq_to_none.rs index a82a33f154dd..f37d34748f9a 100644 --- a/tests/ui/partialeq_to_none.rs +++ b/tests/ui/partialeq_to_none.rs @@ -1,4 +1,5 @@ #![warn(clippy::partialeq_to_none)] +#![allow(clippy::unnecessary_literal_option)] #![expect(clippy::eq_op, clippy::needless_ifs)] struct Foobar; diff --git a/tests/ui/partialeq_to_none.stderr b/tests/ui/partialeq_to_none.stderr index 31b73051b0e4..b09bd7fa0f42 100644 --- a/tests/ui/partialeq_to_none.stderr +++ b/tests/ui/partialeq_to_none.stderr @@ -1,5 +1,5 @@ error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:13:8 + --> tests/ui/partialeq_to_none.rs:14:8 | LL | if f != None { "yay" } else { "nay" } | ^^^^^^^^^ help: use `Option::is_some()` instead: `f.is_some()` @@ -8,55 +8,55 @@ LL | if f != None { "yay" } else { "nay" } = help: to override `-D warnings` add `#[allow(clippy::partialeq_to_none)]` error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:44:13 + --> tests/ui/partialeq_to_none.rs:45:13 | LL | let _ = x == None; | ^^^^^^^^^ help: use `Option::is_none()` instead: `x.is_none()` error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:46:13 + --> tests/ui/partialeq_to_none.rs:47:13 | LL | let _ = x != None; | ^^^^^^^^^ help: use `Option::is_some()` instead: `x.is_some()` error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:48:13 + --> tests/ui/partialeq_to_none.rs:49:13 | LL | let _ = None == x; | ^^^^^^^^^ help: use `Option::is_none()` instead: `x.is_none()` error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:50:13 + --> tests/ui/partialeq_to_none.rs:51:13 | LL | let _ = None != x; | ^^^^^^^^^ help: use `Option::is_some()` instead: `x.is_some()` error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:53:8 + --> tests/ui/partialeq_to_none.rs:54:8 | LL | if foobar() == None {} | ^^^^^^^^^^^^^^^^ help: use `Option::is_none()` instead: `foobar().is_none()` error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:56:8 + --> tests/ui/partialeq_to_none.rs:57:8 | LL | if bar().ok() != None {} | ^^^^^^^^^^^^^^^^^^ help: use `Option::is_some()` instead: `bar().ok().is_some()` error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:59:13 + --> tests/ui/partialeq_to_none.rs:60:13 | LL | let _ = Some(1 + 2) != None; | ^^^^^^^^^^^^^^^^^^^ help: use `Option::is_some()` instead: `Some(1 + 2).is_some()` error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:62:13 + --> tests/ui/partialeq_to_none.rs:63:13 | LL | let _ = { Some(0) } == None; | ^^^^^^^^^^^^^^^^^^^ help: use `Option::is_none()` instead: `{ Some(0) }.is_none()` error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:65:13 + --> tests/ui/partialeq_to_none.rs:66:13 | LL | let _ = { | _____________^ @@ -80,31 +80,31 @@ LL ~ }.is_some(); | error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:76:13 + --> tests/ui/partialeq_to_none.rs:77:13 | LL | let _ = optref() == &&None; | ^^^^^^^^^^^^^^^^^^ help: use `Option::is_none()` instead: `optref().is_none()` error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:78:13 + --> tests/ui/partialeq_to_none.rs:79:13 | LL | let _ = &&None != optref(); | ^^^^^^^^^^^^^^^^^^ help: use `Option::is_some()` instead: `optref().is_some()` error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:80:13 + --> tests/ui/partialeq_to_none.rs:81:13 | LL | let _ = **optref() == None; | ^^^^^^^^^^^^^^^^^^ help: use `Option::is_none()` instead: `optref().is_none()` error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:82:13 + --> tests/ui/partialeq_to_none.rs:83:13 | LL | let _ = &None != *optref(); | ^^^^^^^^^^^^^^^^^^ help: use `Option::is_some()` instead: `optref().is_some()` error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:86:13 + --> tests/ui/partialeq_to_none.rs:87:13 | LL | let _ = None != *x; | ^^^^^^^^^^ help: use `Option::is_some()` instead: `(*x).is_some()` diff --git a/tests/ui/redundant_pattern_matching_drop_order.fixed b/tests/ui/redundant_pattern_matching_drop_order.fixed index 05965fd02055..180fc4b2c7ce 100644 --- a/tests/ui/redundant_pattern_matching_drop_order.fixed +++ b/tests/ui/redundant_pattern_matching_drop_order.fixed @@ -1,6 +1,6 @@ // Issue #5746 #![warn(clippy::redundant_pattern_matching)] -#![allow(clippy::needless_ifs)] +#![allow(clippy::needless_ifs, clippy::unnecessary_literal_option)] #![expect(clippy::needless_else)] use std::task::Poll::{Pending, Ready}; diff --git a/tests/ui/redundant_pattern_matching_drop_order.rs b/tests/ui/redundant_pattern_matching_drop_order.rs index 5e09cca989c5..41b178af39cc 100644 --- a/tests/ui/redundant_pattern_matching_drop_order.rs +++ b/tests/ui/redundant_pattern_matching_drop_order.rs @@ -1,6 +1,6 @@ // Issue #5746 #![warn(clippy::redundant_pattern_matching)] -#![allow(clippy::needless_ifs)] +#![allow(clippy::needless_ifs, clippy::unnecessary_literal_option)] #![expect(clippy::needless_else)] use std::task::Poll::{Pending, Ready}; diff --git a/tests/ui/redundant_pattern_matching_option.fixed b/tests/ui/redundant_pattern_matching_option.fixed index 20542cb294e5..d0e183ec2a6f 100644 --- a/tests/ui/redundant_pattern_matching_option.fixed +++ b/tests/ui/redundant_pattern_matching_option.fixed @@ -1,6 +1,10 @@ #![warn(clippy::redundant_pattern_matching)] #![allow(clippy::needless_bool)] -#![expect(clippy::match_like_matches_macro, clippy::needless_ifs)] +#![expect( + clippy::match_like_matches_macro, + clippy::needless_ifs, + clippy::unnecessary_literal_option +)] fn issue_11174(boolean: bool, maybe_some: Option) -> bool { maybe_some.is_none() && (!boolean) diff --git a/tests/ui/redundant_pattern_matching_option.rs b/tests/ui/redundant_pattern_matching_option.rs index a91e4a77fcb1..4137354c9081 100644 --- a/tests/ui/redundant_pattern_matching_option.rs +++ b/tests/ui/redundant_pattern_matching_option.rs @@ -1,6 +1,10 @@ #![warn(clippy::redundant_pattern_matching)] #![allow(clippy::needless_bool)] -#![expect(clippy::match_like_matches_macro, clippy::needless_ifs)] +#![expect( + clippy::match_like_matches_macro, + clippy::needless_ifs, + clippy::unnecessary_literal_option +)] fn issue_11174(boolean: bool, maybe_some: Option) -> bool { matches!(maybe_some, None if !boolean) diff --git a/tests/ui/redundant_pattern_matching_option.stderr b/tests/ui/redundant_pattern_matching_option.stderr index 782636af8082..25a18efcb792 100644 --- a/tests/ui/redundant_pattern_matching_option.stderr +++ b/tests/ui/redundant_pattern_matching_option.stderr @@ -1,5 +1,5 @@ error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:6:5 + --> tests/ui/redundant_pattern_matching_option.rs:10:5 | LL | matches!(maybe_some, None if !boolean) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL + maybe_some.is_none() && (!boolean) | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:11:13 + --> tests/ui/redundant_pattern_matching_option.rs:15:13 | LL | let _ = matches!(maybe_some, None if boolean || boolean2); // guard needs parentheses | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + let _ = maybe_some.is_none() && (boolean || boolean2); // guard needs p | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:27:14 + --> tests/ui/redundant_pattern_matching_option.rs:31:14 | LL | let _ = !matches!(opt, None if a); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL + let _ = !(opt.is_none() && a); | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:29:14 + --> tests/ui/redundant_pattern_matching_option.rs:33:14 | LL | let _ = &matches!(opt, None if a); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + let _ = &(opt.is_none() && a); | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:31:13 + --> tests/ui/redundant_pattern_matching_option.rs:35:13 | LL | let _ = matches!(opt, None if a) as u8; | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + let _ = (opt.is_none() && a) as u8; | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:33:13 + --> tests/ui/redundant_pattern_matching_option.rs:37:13 | LL | let _ = matches!(opt, None if a) == b; | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL + let _ = (opt.is_none() && a) == b; | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:35:13 + --> tests/ui/redundant_pattern_matching_option.rs:39:13 | LL | let _ = matches!(opt, None if a).then_some(1); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -85,7 +85,7 @@ LL + let _ = (opt.is_none() && a).then_some(1); | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:37:13 + --> tests/ui/redundant_pattern_matching_option.rs:41:13 | LL | let _ = matches!(opt, None if a); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL + let _ = opt.is_none() && a; | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:39:8 + --> tests/ui/redundant_pattern_matching_option.rs:43:8 | LL | if matches!(opt, None if a) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -109,7 +109,7 @@ LL + if opt.is_none() && a {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:41:13 + --> tests/ui/redundant_pattern_matching_option.rs:45:13 | LL | let _ = matches!(opt, None if a) && b; | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -121,7 +121,7 @@ LL + let _ = opt.is_none() && a && b; | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:43:13 + --> tests/ui/redundant_pattern_matching_option.rs:47:13 | LL | let _ = matches!(opt, None if a) || b; | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL + let _ = opt.is_none() && a || b; | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:45:25 + --> tests/ui/redundant_pattern_matching_option.rs:49:25 | LL | let _ = b.then_some(matches!(opt, None if a)); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -145,7 +145,7 @@ LL + let _ = b.then_some(opt.is_none() && a); | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:50:12 + --> tests/ui/redundant_pattern_matching_option.rs:54:12 | LL | if let None = None::<()> {} | ^^^^ @@ -157,7 +157,7 @@ LL + if None::<()>.is_none() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:53:12 + --> tests/ui/redundant_pattern_matching_option.rs:57:12 | LL | if let Some(_) = Some(42) {} | ^^^^^^^ @@ -169,7 +169,7 @@ LL + if Some(42).is_some() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:56:12 + --> tests/ui/redundant_pattern_matching_option.rs:60:12 | LL | if let Some(_) = Some(42) { | ^^^^^^^ @@ -181,7 +181,7 @@ LL + if Some(42).is_some() { | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:63:15 + --> tests/ui/redundant_pattern_matching_option.rs:67:15 | LL | while let Some(_) = Some(42) {} | ^^^^^^^ @@ -193,7 +193,7 @@ LL + while Some(42).is_some() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:66:15 + --> tests/ui/redundant_pattern_matching_option.rs:70:15 | LL | while let None = Some(42) {} | ^^^^ @@ -205,7 +205,7 @@ LL + while Some(42).is_none() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:69:15 + --> tests/ui/redundant_pattern_matching_option.rs:73:15 | LL | while let None = None::<()> {} | ^^^^ @@ -217,7 +217,7 @@ LL + while None::<()>.is_none() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:73:15 + --> tests/ui/redundant_pattern_matching_option.rs:77:15 | LL | while let Some(_) = v.pop() { | ^^^^^^^ @@ -229,7 +229,7 @@ LL + while v.pop().is_some() { | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:82:5 + --> tests/ui/redundant_pattern_matching_option.rs:86:5 | LL | / match Some(42) { LL | | @@ -249,7 +249,7 @@ LL + Some(42).is_some(); | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:88:5 + --> tests/ui/redundant_pattern_matching_option.rs:92:5 | LL | / match None::<()> { LL | | @@ -269,7 +269,7 @@ LL + None::<()>.is_none(); | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:94:13 + --> tests/ui/redundant_pattern_matching_option.rs:98:13 | LL | let _ = match None::<()> { | _____________^ @@ -290,7 +290,7 @@ LL + let _ = None::<()>.is_none(); | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:101:20 + --> tests/ui/redundant_pattern_matching_option.rs:105:20 | LL | let _ = if let Some(_) = opt { true } else { false }; | ^^^^^^^ @@ -302,7 +302,7 @@ LL + let _ = if opt.is_some() { true } else { false }; | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:108:20 + --> tests/ui/redundant_pattern_matching_option.rs:112:20 | LL | let _ = if let Some(_) = gen_opt() { | ^^^^^^^ @@ -314,7 +314,7 @@ LL + let _ = if gen_opt().is_some() { | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:111:19 + --> tests/ui/redundant_pattern_matching_option.rs:115:19 | LL | } else if let None = gen_opt() { | ^^^^ @@ -326,7 +326,7 @@ LL + } else if gen_opt().is_none() { | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:118:12 + --> tests/ui/redundant_pattern_matching_option.rs:122:12 | LL | if let Some(..) = gen_opt() {} | ^^^^^^^^ @@ -338,7 +338,7 @@ LL + if gen_opt().is_some() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:134:12 + --> tests/ui/redundant_pattern_matching_option.rs:138:12 | LL | if let Some(_) = Some(42) {} | ^^^^^^^ @@ -350,7 +350,7 @@ LL + if Some(42).is_some() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:137:12 + --> tests/ui/redundant_pattern_matching_option.rs:141:12 | LL | if let None = None::<()> {} | ^^^^ @@ -362,7 +362,7 @@ LL + if None::<()>.is_none() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:140:15 + --> tests/ui/redundant_pattern_matching_option.rs:144:15 | LL | while let Some(_) = Some(42) {} | ^^^^^^^ @@ -374,7 +374,7 @@ LL + while Some(42).is_some() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:143:15 + --> tests/ui/redundant_pattern_matching_option.rs:147:15 | LL | while let None = None::<()> {} | ^^^^ @@ -386,7 +386,7 @@ LL + while None::<()>.is_none() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:146:5 + --> tests/ui/redundant_pattern_matching_option.rs:150:5 | LL | / match Some(42) { LL | | @@ -406,7 +406,7 @@ LL + Some(42).is_some(); | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:152:5 + --> tests/ui/redundant_pattern_matching_option.rs:156:5 | LL | / match None::<()> { LL | | @@ -426,7 +426,7 @@ LL + None::<()>.is_none(); | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:161:12 + --> tests/ui/redundant_pattern_matching_option.rs:165:12 | LL | if let None = *(&None::<()>) {} | ^^^^ @@ -438,7 +438,7 @@ LL + if (&None::<()>).is_none() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:163:12 + --> tests/ui/redundant_pattern_matching_option.rs:167:12 | LL | if let None = *&None::<()> {} | ^^^^ @@ -450,7 +450,7 @@ LL + if (&None::<()>).is_none() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:170:5 + --> tests/ui/redundant_pattern_matching_option.rs:174:5 | LL | / match x { LL | | @@ -470,7 +470,7 @@ LL + x.is_some(); | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:176:5 + --> tests/ui/redundant_pattern_matching_option.rs:180:5 | LL | / match x { LL | | @@ -490,7 +490,7 @@ LL + x.is_none(); | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:182:5 + --> tests/ui/redundant_pattern_matching_option.rs:186:5 | LL | / match x { LL | | @@ -510,7 +510,7 @@ LL + x.is_none(); | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:188:5 + --> tests/ui/redundant_pattern_matching_option.rs:192:5 | LL | / match x { LL | | @@ -530,7 +530,7 @@ LL + x.is_some(); | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:204:13 + --> tests/ui/redundant_pattern_matching_option.rs:208:13 | LL | let _ = matches!(x, Some(_)); | ^^^^^^^^^^^^^^^^^^^^ @@ -542,7 +542,7 @@ LL + let _ = x.is_some(); | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:207:13 + --> tests/ui/redundant_pattern_matching_option.rs:211:13 | LL | let _ = matches!(x, None); | ^^^^^^^^^^^^^^^^^ @@ -554,7 +554,7 @@ LL + let _ = x.is_none(); | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:218:17 + --> tests/ui/redundant_pattern_matching_option.rs:222:17 | LL | let _ = matches!(*p, None); | ^^^^^^^^^^^^^^^^^^ @@ -566,7 +566,7 @@ LL + let _ = (*p).is_none(); | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:226:16 + --> tests/ui/redundant_pattern_matching_option.rs:230:16 | LL | if let Some(_) = x? { | ^^^^^^^ @@ -578,7 +578,7 @@ LL + if x?.is_some() { | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:246:16 + --> tests/ui/redundant_pattern_matching_option.rs:250:16 | LL | if let Some(_) = x.await { | ^^^^^^^ @@ -590,7 +590,7 @@ LL + if x.await.is_some() { | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:259:12 + --> tests/ui/redundant_pattern_matching_option.rs:263:12 | LL | if let Some(_) = (x! {}) {}; | ^^^^^^^ @@ -602,7 +602,7 @@ LL + if x! {}.is_some() {}; | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:261:15 + --> tests/ui/redundant_pattern_matching_option.rs:265:15 | LL | while let Some(_) = (x! {}) {} | ^^^^^^^ diff --git a/tests/ui/significant_drop_tightening.fixed b/tests/ui/significant_drop_tightening.fixed index 559c1bb94570..76c3ee8a7fa6 100644 --- a/tests/ui/significant_drop_tightening.fixed +++ b/tests/ui/significant_drop_tightening.fixed @@ -1,5 +1,5 @@ #![warn(clippy::significant_drop_tightening)] - +#![allow(clippy::unnecessary_literal_option)] use std::sync::Mutex; pub fn complex_return_triggers_the_lint() -> i32 { diff --git a/tests/ui/significant_drop_tightening.rs b/tests/ui/significant_drop_tightening.rs index dff36baf383d..fdc5059dda6c 100644 --- a/tests/ui/significant_drop_tightening.rs +++ b/tests/ui/significant_drop_tightening.rs @@ -1,5 +1,5 @@ #![warn(clippy::significant_drop_tightening)] - +#![allow(clippy::unnecessary_literal_option)] use std::sync::Mutex; pub fn complex_return_triggers_the_lint() -> i32 { diff --git a/tests/ui/unnecessary_literal_option.fixed b/tests/ui/unnecessary_literal_option.fixed index c94e3c607fee..ad880f88851d 100644 --- a/tests/ui/unnecessary_literal_option.fixed +++ b/tests/ui/unnecessary_literal_option.fixed @@ -20,5 +20,4 @@ fn main() { //~^ unnecessary_literal_option let _ = None.or(Some(1)); - -} \ No newline at end of file +} From d94ba6b5ea626520127a833d40322b44a3de2f52 Mon Sep 17 00:00:00 2001 From: Robin <1187338299@qq.com> Date: Thu, 1 Oct 2026 17:07:38 +0800 Subject: [PATCH 3/5] feat: fix dogfood ci issues --- .../src/methods/unnecessary_literal_option.rs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/clippy_lints/src/methods/unnecessary_literal_option.rs b/clippy_lints/src/methods/unnecessary_literal_option.rs index 3da74f30c25b..15ecd6b74d64 100644 --- a/clippy_lints/src/methods/unnecessary_literal_option.rs +++ b/clippy_lints/src/methods/unnecessary_literal_option.rs @@ -62,22 +62,14 @@ pub(super) fn check( let help_message = format!("used `{method}()` on `{constructor}` value"); let (suggestion_message, suggestions) = match (constructor, method, ty) { - (sym::Some, sym::is_some, _) => ( + (sym::Some, sym::is_some, _) | (sym::None, sym::is_none, _) => ( "replace this with `true`".to_string(), Some(vec![(expr.span, "true".to_string())]), ), - (sym::Some, sym::is_none, _) => ( + (sym::Some, sym::is_none, _) | (sym::None, sym::is_some, _) => ( "replace this with `false`".to_string(), Some(vec![(expr.span, "false".to_string())]), ), - (sym::None, sym::is_some, _) => ( - "replace this with `false`".to_string(), - Some(vec![(expr.span, "false".to_string())]), - ), - (sym::None, sym::is_none, _) => ( - "replace this with `true`".to_string(), - Some(vec![(expr.span, "true".to_string())]), - ), (sym::Some, sym::or | sym::or_else, _) => ( format!("remove this `.{method}()` call"), Some(vec![(expr.span.with_lo(recv.span.hi()), String::new())]), From 53912dffad4464959171dae368739a3b86162eef Mon Sep 17 00:00:00 2001 From: Robin <1187338299@qq.com> Date: Thu, 1 Oct 2026 17:24:59 +0800 Subject: [PATCH 4/5] feat: update lint order for fixing lint-attributes-organization ci issues --- tests/ui/checked_unwrap/complex_conditionals_nested.rs | 4 ++-- tests/ui/checked_unwrap/simple_conditionals.rs | 4 ++-- tests/ui/or_fun_call.fixed | 4 ++-- tests/ui/or_fun_call.rs | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/ui/checked_unwrap/complex_conditionals_nested.rs b/tests/ui/checked_unwrap/complex_conditionals_nested.rs index 0015bd0b8a6d..46aef0661e67 100644 --- a/tests/ui/checked_unwrap/complex_conditionals_nested.rs +++ b/tests/ui/checked_unwrap/complex_conditionals_nested.rs @@ -2,8 +2,8 @@ #![warn(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] #![expect( clippy::branches_sharing_code, - clippy::unnecessary_literal_unwrap, - clippy::unnecessary_literal_option + clippy::unnecessary_literal_option, + clippy::unnecessary_literal_unwrap )] fn test_nested() { diff --git a/tests/ui/checked_unwrap/simple_conditionals.rs b/tests/ui/checked_unwrap/simple_conditionals.rs index 17b242fa6b5d..638745dbce8c 100644 --- a/tests/ui/checked_unwrap/simple_conditionals.rs +++ b/tests/ui/checked_unwrap/simple_conditionals.rs @@ -4,8 +4,8 @@ clippy::branches_sharing_code, clippy::if_same_then_else, clippy::self_assignment, - clippy::unnecessary_literal_unwrap, - clippy::unnecessary_literal_option + clippy::unnecessary_literal_option, + clippy::unnecessary_literal_unwrap )] macro_rules! m { diff --git a/tests/ui/or_fun_call.fixed b/tests/ui/or_fun_call.fixed index c2b4a2309783..a74d4be0bca7 100644 --- a/tests/ui/or_fun_call.fixed +++ b/tests/ui/or_fun_call.fixed @@ -1,9 +1,9 @@ #![warn(clippy::or_fun_call)] #![allow( clippy::map_or_identity, + clippy::unnecessary_literal_option, clippy::unnecessary_option_map_or_else, - clippy::unnecessary_result_map_or_else, - clippy::unnecessary_literal_option + clippy::unnecessary_result_map_or_else )] #![expect(clippy::unnecessary_literal_unwrap, clippy::useless_vec)] diff --git a/tests/ui/or_fun_call.rs b/tests/ui/or_fun_call.rs index 282a499bea1b..9ab790a2b123 100644 --- a/tests/ui/or_fun_call.rs +++ b/tests/ui/or_fun_call.rs @@ -1,9 +1,9 @@ #![warn(clippy::or_fun_call)] #![allow( clippy::map_or_identity, + clippy::unnecessary_literal_option, clippy::unnecessary_option_map_or_else, - clippy::unnecessary_result_map_or_else, - clippy::unnecessary_literal_option + clippy::unnecessary_result_map_or_else )] #![expect(clippy::unnecessary_literal_unwrap, clippy::useless_vec)] From e17cc83396b138b75c5e3cbe8d7a7a5d6bd1e220 Mon Sep 17 00:00:00 2001 From: Robin <1187338299@qq.com> Date: Thu, 1 Oct 2026 17:31:28 +0800 Subject: [PATCH 5/5] fix ci issues --- tests/ui/or_fun_call.fixed | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/or_fun_call.fixed b/tests/ui/or_fun_call.fixed index a74d4be0bca7..ccc33864839b 100644 --- a/tests/ui/or_fun_call.fixed +++ b/tests/ui/or_fun_call.fixed @@ -1,7 +1,7 @@ #![warn(clippy::or_fun_call)] #![allow( clippy::map_or_identity, - clippy::unnecessary_literal_option, + clippy::unnecessary_literal_option, clippy::unnecessary_option_map_or_else, clippy::unnecessary_result_map_or_else )]