Skip to content

Commit d3edd05

Browse files
authored
Handle Option::map_or(true, …) in unnecessary_map_or lint (#13653)
changelog: [`unnecessary_map_or`]: handle `Option::map_or(true, …)`
2 parents 0712689 + de03a05 commit d3edd05

38 files changed

+136
-57
lines changed

clippy_lints/src/approx_const.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl ApproxConstant {
9191
let s = s.as_str();
9292
if s.parse::<f64>().is_ok() {
9393
for &(constant, name, min_digits, msrv) in &KNOWN_CONSTS {
94-
if is_approx_const(constant, s, min_digits) && msrv.map_or(true, |msrv| self.msrv.meets(msrv)) {
94+
if is_approx_const(constant, s, min_digits) && msrv.is_none_or(|msrv| self.msrv.meets(msrv)) {
9595
span_lint_and_help(
9696
cx,
9797
APPROX_CONSTANT,

clippy_lints/src/assigning_clones.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,13 @@ impl<'tcx> LateLintPass<'tcx> for AssigningClones {
100100
// TODO: This check currently bails if the local variable has no initializer.
101101
// That is overly conservative - the lint should fire even if there was no initializer,
102102
// but the variable has been initialized before `lhs` was evaluated.
103-
&& path_to_local(lhs).map_or(true, |lhs| local_is_initialized(cx, lhs))
103+
&& path_to_local(lhs).is_none_or(|lhs| local_is_initialized(cx, lhs))
104104
&& let Some(resolved_impl) = cx.tcx.impl_of_method(resolved_fn.def_id())
105105
// Derived forms don't implement `clone_from`/`clone_into`.
106106
// See https://github.com/rust-lang/rust/pull/98445#issuecomment-1190681305
107107
&& !cx.tcx.is_builtin_derived(resolved_impl)
108108
// Don't suggest calling a function we're implementing.
109-
&& resolved_impl.as_local().map_or(true, |block_id| {
109+
&& resolved_impl.as_local().is_none_or(|block_id| {
110110
cx.tcx.hir().parent_owner_iter(e.hir_id).all(|(id, _)| id.def_id != block_id)
111111
})
112112
&& let resolved_assoc_items = cx.tcx.associated_items(resolved_impl)

clippy_lints/src/borrow_deref_ref.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl<'tcx> LateLintPass<'tcx> for BorrowDerefRef {
5757
&& !addrof_target.span.from_expansion()
5858
&& let ref_ty = cx.typeck_results().expr_ty(deref_target)
5959
&& let ty::Ref(_, inner_ty, Mutability::Not) = ref_ty.kind()
60-
&& get_parent_expr(cx, e).map_or(true, |parent| {
60+
&& get_parent_expr(cx, e).is_none_or(|parent| {
6161
match parent.kind {
6262
// `*&*foo` should lint `deref_addrof` instead.
6363
ExprKind::Unary(UnOp::Deref, _) => is_lint_allowed(cx, DEREF_ADDROF, parent.hir_id),

clippy_lints/src/cargo/common_metadata.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ fn missing_warning(cx: &LateContext<'_>, package: &cargo_metadata::Package, fiel
4343
}
4444

4545
fn is_empty_str<T: AsRef<std::ffi::OsStr>>(value: Option<&T>) -> bool {
46-
value.map_or(true, |s| s.as_ref().is_empty())
46+
value.is_none_or(|s| s.as_ref().is_empty())
4747
}
4848

4949
fn is_empty_vec(value: &[String]) -> bool {

clippy_lints/src/casts/cast_possible_truncation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ pub(super) fn check(
134134
};
135135
let to_nbits = utils::int_ty_to_nbits(cast_to, cx.tcx);
136136

137-
let cast_from_ptr_size = def.repr().int.map_or(true, |ty| matches!(ty, IntegerType::Pointer(_),));
137+
let cast_from_ptr_size = def.repr().int.is_none_or(|ty| matches!(ty, IntegerType::Pointer(_),));
138138
let suffix = match (cast_from_ptr_size, is_isize_or_usize(cast_to)) {
139139
(_, false) if from_nbits > to_nbits => "",
140140
(false, true) if from_nbits > 64 => "",

clippy_lints/src/copies.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ fn lint_if_same_then_else(cx: &LateContext<'_>, conds: &[&Expr<'_>], blocks: &[&
212212
.array_windows::<2>()
213213
.enumerate()
214214
.fold(true, |all_eq, (i, &[lhs, rhs])| {
215-
if eq.eq_block(lhs, rhs) && !contains_let(conds[i]) && conds.get(i + 1).map_or(true, |e| !contains_let(e)) {
215+
if eq.eq_block(lhs, rhs) && !contains_let(conds[i]) && conds.get(i + 1).is_none_or(|e| !contains_let(e)) {
216216
span_lint_and_note(
217217
cx,
218218
IF_SAME_THEN_ELSE,
@@ -470,7 +470,7 @@ fn scan_block_for_eq<'tcx>(
470470
b.stmts
471471
// the bounds check will catch the underflow
472472
.get(b.stmts.len().wrapping_sub(offset + 1))
473-
.map_or(true, |s| hash != hash_stmt(cx, s))
473+
.is_none_or(|s| hash != hash_stmt(cx, s))
474474
})
475475
})
476476
.map_or(block.stmts.len() - start_end_eq, |(i, _)| i);

clippy_lints/src/dereference.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
452452
));
453453
} else if stability.is_deref_stable()
454454
// Auto-deref doesn't combine with other adjustments
455-
&& next_adjust.map_or(true, |a| matches!(a.kind, Adjust::Deref(_) | Adjust::Borrow(_)))
455+
&& next_adjust.is_none_or(|a| matches!(a.kind, Adjust::Deref(_) | Adjust::Borrow(_)))
456456
&& iter.all(|a| matches!(a.kind, Adjust::Deref(_) | Adjust::Borrow(_)))
457457
{
458458
self.state = Some((State::Borrow { mutability }, StateData {

clippy_lints/src/eta_reduction.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ fn check_inputs(
276276
&& typeck
277277
.expr_adjustments(arg)
278278
.last()
279-
.map_or(true, |a| a.target == typeck.expr_ty(arg))
279+
.is_none_or(|a| a.target == typeck.expr_ty(arg))
280280
})
281281
}
282282

clippy_lints/src/excessive_bools.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ impl<'tcx> LateLintPass<'tcx> for ExcessiveBools {
165165
&& fn_header.abi == Abi::Rust
166166
&& fn_decl.inputs.len() as u64 > self.max_fn_params_bools
167167
&& get_parent_as_impl(cx.tcx, cx.tcx.local_def_id_to_hir_id(def_id))
168-
.map_or(true, |impl_item| impl_item.of_trait.is_none())
168+
.is_none_or(|impl_item| impl_item.of_trait.is_none())
169169
{
170170
check_fn_decl(cx, fn_decl, span, self.max_fn_params_bools);
171171
}

clippy_lints/src/from_over_into.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl<'tcx> LateLintPass<'tcx> for FromOverInto {
9292
|diag| {
9393
// If the target type is likely foreign mention the orphan rules as it's a common source of
9494
// confusion
95-
if path_def_id(cx, target_ty.peel_refs()).map_or(true, |id| !id.is_local()) {
95+
if path_def_id(cx, target_ty.peel_refs()).is_none_or(|id| !id.is_local()) {
9696
diag.help(
9797
"`impl From<Local> for Foreign` is allowed by the orphan rules, for more information see\n\
9898
https://doc.rust-lang.org/reference/items/implementations.html#trait-implementation-coherence"

clippy_lints/src/if_let_mutex.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ fn mutex_lock_call<'tcx>(
9797
&& path.ident.as_str() == "lock"
9898
&& let ty = cx.typeck_results().expr_ty(self_arg).peel_refs()
9999
&& is_type_diagnostic_item(cx, ty, sym::Mutex)
100-
&& op_mutex.map_or(true, |op| eq_expr_value(cx, self_arg, op))
100+
&& op_mutex.is_none_or(|op| eq_expr_value(cx, self_arg, op))
101101
{
102102
ControlFlow::Break(self_arg)
103103
} else {

clippy_lints/src/loops/explicit_iter_loop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub(super) fn check(
2929
if !msrv.meets(msrvs::ARRAY_INTO_ITERATOR) {
3030
return;
3131
}
32-
} else if count.try_to_target_usize(cx.tcx).map_or(true, |x| x > 32) && !msrv.meets(msrvs::ARRAY_IMPL_ANY_LEN) {
32+
} else if count.try_to_target_usize(cx.tcx).is_none_or(|x| x > 32) && !msrv.meets(msrvs::ARRAY_IMPL_ANY_LEN) {
3333
return;
3434
}
3535
}

clippy_lints/src/matches/collapsible_match.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,13 @@ fn check_arm<'tcx>(
7272
(Some(a), Some(b)) => SpanlessEq::new(cx).eq_expr(a, b),
7373
}
7474
// the binding must not be used in the if guard
75-
&& outer_guard.map_or(
76-
true,
75+
&& outer_guard.is_none_or(
7776
|e| !is_local_used(cx, e, binding_id)
7877
)
7978
// ...or anywhere in the inner expression
8079
&& match inner {
8180
IfLetOrMatch::IfLet(_, _, body, els, _) => {
82-
!is_local_used(cx, body, binding_id) && els.map_or(true, |e| !is_local_used(cx, e, binding_id))
81+
!is_local_used(cx, body, binding_id) && els.is_none_or(|e| !is_local_used(cx, e, binding_id))
8382
},
8483
IfLetOrMatch::Match(_, arms, ..) => !arms.iter().any(|arm| is_local_used(cx, arm, binding_id)),
8584
}

clippy_lints/src/methods/clone_on_copy.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub(super) fn check(
3030
.type_dependent_def_id(expr.hir_id)
3131
.and_then(|id| cx.tcx.trait_of_item(id))
3232
.zip(cx.tcx.lang_items().clone_trait())
33-
.map_or(true, |(x, y)| x != y)
33+
.is_none_or(|(x, y)| x != y)
3434
{
3535
return;
3636
}

clippy_lints/src/methods/mod.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -4107,24 +4107,32 @@ declare_clippy_lint! {
41074107
/// ### Why is this bad?
41084108
/// Calls such as `opt.map_or(false, |val| val == 5)` are needlessly long and cumbersome,
41094109
/// and can be reduced to, for example, `opt == Some(5)` assuming `opt` implements `PartialEq`.
4110+
/// Also, calls such as `opt.map_or(true, |val| val == 5)` can be reduced to
4111+
/// `opt.is_none_or(|val| val == 5)`.
41104112
/// This lint offers readability and conciseness improvements.
41114113
///
41124114
/// ### Example
41134115
/// ```no_run
4114-
/// pub fn a(x: Option<i32>) -> bool {
4115-
/// x.map_or(false, |n| n == 5)
4116+
/// pub fn a(x: Option<i32>) -> (bool, bool) {
4117+
/// (
4118+
/// x.map_or(false, |n| n == 5),
4119+
/// x.map_or(true, |n| n > 5),
4120+
/// )
41164121
/// }
41174122
/// ```
41184123
/// Use instead:
41194124
/// ```no_run
4120-
/// pub fn a(x: Option<i32>) -> bool {
4121-
/// x == Some(5)
4125+
/// pub fn a(x: Option<i32>) -> (bool, bool) {
4126+
/// (
4127+
/// x == Some(5),
4128+
/// x.is_none_or(|n| n > 5),
4129+
/// )
41224130
/// }
41234131
/// ```
41244132
#[clippy::version = "1.75.0"]
41254133
pub UNNECESSARY_MAP_OR,
41264134
style,
4127-
"reduce unnecessary pattern matching for constructs that implement `PartialEq`"
4135+
"reduce unnecessary calls to `.map_or(bool, …)`"
41284136
}
41294137

41304138
declare_clippy_lint! {
@@ -4531,7 +4539,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
45314539
&& method_config.output_type.matches(&sig.decl.output)
45324540
// in case there is no first arg, since we already have checked the number of arguments
45334541
// it's should be always true
4534-
&& first_arg_ty_opt.map_or(true, |first_arg_ty| method_config
4542+
&& first_arg_ty_opt.is_none_or(|first_arg_ty| method_config
45354543
.self_kind.matches(cx, self_ty, first_arg_ty)
45364544
)
45374545
&& fn_header_equals(method_config.fn_header, sig.header)

clippy_lints/src/methods/unnecessary_filter_map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>, a
2323
if let hir::ExprKind::Closure(&hir::Closure { body, .. }) = arg.kind {
2424
let body = cx.tcx.hir().body(body);
2525
let arg_id = body.params[0].pat.hir_id;
26-
let mutates_arg = mutated_variables(body.value, cx).map_or(true, |used_mutably| used_mutably.contains(&arg_id));
26+
let mutates_arg = mutated_variables(body.value, cx).is_none_or(|used_mutably| used_mutably.contains(&arg_id));
2727
let (clone_or_copy_needed, _) = clone_or_copy_needed(cx, body.params[0].pat, body.value);
2828

2929
let (mut found_mapping, mut found_filtering) = check_expression(cx, arg_id, body.value);

clippy_lints/src/methods/unnecessary_map_or.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub(super) fn check<'a>(
6060
Some(_) | None => return,
6161
};
6262

63-
let (sugg, method) = if let ExprKind::Closure(map_closure) = map.kind
63+
let (sugg, method, applicability) = if let ExprKind::Closure(map_closure) = map.kind
6464
&& let closure_body = cx.tcx.hir().body(map_closure.body)
6565
&& let closure_body_value = closure_body.value.peel_blocks()
6666
&& let ExprKind::Binary(op, l, r) = closure_body_value.kind
@@ -100,7 +100,7 @@ pub(super) fn check<'a>(
100100
.maybe_par()
101101
.into_string();
102102

103-
(binop, "a standard comparison")
103+
(binop, "a standard comparison", Applicability::MaybeIncorrect)
104104
} else if !def_bool
105105
&& msrv.meets(msrvs::OPTION_RESULT_IS_VARIANT_AND)
106106
&& let Some(recv_callsite) = snippet_opt(cx, recv.span.source_callsite())
@@ -110,6 +110,18 @@ pub(super) fn check<'a>(
110110
(
111111
format!("{recv_callsite}.{suggested_name}({span_callsite})",),
112112
suggested_name,
113+
Applicability::MachineApplicable,
114+
)
115+
} else if def_bool
116+
&& matches!(variant, Variant::Some)
117+
&& msrv.meets(msrvs::IS_NONE_OR)
118+
&& let Some(recv_callsite) = snippet_opt(cx, recv.span.source_callsite())
119+
&& let Some(span_callsite) = snippet_opt(cx, map.span.source_callsite())
120+
{
121+
(
122+
format!("{recv_callsite}.is_none_or({span_callsite})"),
123+
"is_none_or",
124+
Applicability::MachineApplicable,
113125
)
114126
} else {
115127
return;
@@ -126,6 +138,6 @@ pub(super) fn check<'a>(
126138
"this `map_or` is redundant",
127139
format!("use {method} instead"),
128140
sugg,
129-
Applicability::MaybeIncorrect,
141+
applicability,
130142
);
131143
}

clippy_lints/src/misc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ fn used_underscore_binding<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
351351
/// `unused_variables`'s idea
352352
/// of what it means for an expression to be "used".
353353
fn is_used(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
354-
get_parent_expr(cx, expr).map_or(true, |parent| match parent.kind {
354+
get_parent_expr(cx, expr).is_none_or(|parent| match parent.kind {
355355
ExprKind::Assign(_, rhs, _) | ExprKind::AssignOp(_, _, rhs) => SpanlessEq::new(cx).eq_expr(rhs, expr),
356356
_ => is_used(cx, parent),
357357
})

clippy_lints/src/needless_borrows_for_generic_args.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ fn referent_used_exactly_once<'tcx>(
362362
let body_owner_local_def_id = cx.tcx.hir().enclosing_body_owner(reference.hir_id);
363363
if possible_borrowers
364364
.last()
365-
.map_or(true, |&(local_def_id, _)| local_def_id != body_owner_local_def_id)
365+
.is_none_or(|&(local_def_id, _)| local_def_id != body_owner_local_def_id)
366366
{
367367
possible_borrowers.push((body_owner_local_def_id, PossibleBorrowerMap::new(cx, mir)));
368368
}

clippy_lints/src/no_effect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ fn has_no_effect(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
238238
ExprKind::Struct(_, fields, ref base) => {
239239
!has_drop(cx, cx.typeck_results().expr_ty(expr))
240240
&& fields.iter().all(|field| has_no_effect(cx, field.expr))
241-
&& base.as_ref().map_or(true, |base| has_no_effect(cx, base))
241+
&& base.as_ref().is_none_or(|base| has_no_effect(cx, base))
242242
},
243243
ExprKind::Call(callee, args) => {
244244
if let ExprKind::Path(ref qpath) = callee.kind {

clippy_lints/src/non_copy_const.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst<'tcx> {
335335
// i.e. having an enum doesn't necessary mean a type has a frozen variant.
336336
// And, implementing it isn't a trivial task; it'll probably end up
337337
// re-implementing the trait predicate evaluation specific to `Freeze`.
338-
&& body_id_opt.map_or(true, |body_id| Self::is_value_unfrozen_poly(cx, body_id, normalized))
338+
&& body_id_opt.is_none_or(|body_id| Self::is_value_unfrozen_poly(cx, body_id, normalized))
339339
{
340340
lint(cx, Source::Assoc { item: trait_item.span });
341341
}

clippy_lints/src/only_used_in_recursion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ impl Params {
200200
if self
201201
.get_by_fn(param.fn_id, usage.idx)
202202
// If the parameter can't be found, then it's used for more than just recursion.
203-
.map_or(true, |p| self.try_disable_lint_for_param(p, eval_stack))
203+
.is_none_or(|p| self.try_disable_lint_for_param(p, eval_stack))
204204
{
205205
param.apply_lint.set(false);
206206
eval_stack.pop();

clippy_lints/src/operators/assign_op_pattern.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub(super) fn check<'tcx>(
2727
if let Some((_, lang_item)) = binop_traits(op.node)
2828
&& let Some(trait_id) = cx.tcx.lang_items().get(lang_item)
2929
&& let parent_fn = cx.tcx.hir().get_parent_item(e.hir_id).def_id
30-
&& trait_ref_of_method(cx, parent_fn).map_or(true, |t| t.path.res.def_id() != trait_id)
30+
&& trait_ref_of_method(cx, parent_fn).is_none_or(|t| t.path.res.def_id() != trait_id)
3131
&& implements_trait(cx, ty, trait_id, &[rty.into()])
3232
{
3333
// Primitive types execute assign-ops right-to-left. Every other type is left-to-right.

clippy_lints/src/ptr.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -541,9 +541,7 @@ fn check_mut_from_ref<'tcx>(cx: &LateContext<'tcx>, sig: &FnSig<'_>, body: Optio
541541
.collect();
542542
if let Some(args) = args
543543
&& !args.is_empty()
544-
&& body.map_or(true, |body| {
545-
sig.header.safety == Safety::Unsafe || contains_unsafe_block(cx, body.value)
546-
})
544+
&& body.is_none_or(|body| sig.header.safety == Safety::Unsafe || contains_unsafe_block(cx, body.value))
547545
{
548546
span_lint_and_then(
549547
cx,

clippy_lints/src/redundant_async_block.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ fn desugar_async_block<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Op
8888
cx.typeck_results()
8989
.closure_min_captures
9090
.get(def_id)
91-
.map_or(true, |m| {
91+
.is_none_or(|m| {
9292
m.values().all(|places| {
9393
places
9494
.iter()

clippy_lints/src/single_call_fn.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl SingleCallFn {
9393
.tcx
9494
.hir()
9595
.maybe_body_owned_by(fn_def_id)
96-
.map_or(true, |body| is_in_test_function(cx.tcx, body.value.hir_id))
96+
.is_none_or(|body| is_in_test_function(cx.tcx, body.value.hir_id))
9797
|| match cx.tcx.hir_node(fn_hir_id) {
9898
Node::Item(item) => is_from_proc_macro(cx, item),
9999
Node::ImplItem(item) => is_from_proc_macro(cx, item),

clippy_lints/src/undocumented_unsafe_blocks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ fn is_unsafe_from_proc_macro(cx: &LateContext<'_>, span: Span) -> bool {
337337
.src
338338
.as_deref()
339339
.and_then(|src| src.get(file_pos.pos.to_usize()..))
340-
.map_or(true, |src| !src.starts_with("unsafe"))
340+
.is_none_or(|src| !src.starts_with("unsafe"))
341341
}
342342

343343
// Checks if any parent {expression, statement, block, local, const, static}

clippy_lints/src/unit_types/let_unit_value.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ fn expr_needs_inferred_result<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -
145145
}
146146
while let Some(id) = locals_to_check.pop() {
147147
if let Node::LetStmt(l) = cx.tcx.parent_hir_node(id) {
148-
if !l.ty.map_or(true, |ty| matches!(ty.kind, TyKind::Infer)) {
148+
if !l.ty.is_none_or(|ty| matches!(ty.kind, TyKind::Infer)) {
149149
return false;
150150
}
151151
if let Some(e) = l.init {

clippy_lints/src/upper_case_acronyms.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ fn check_ident(cx: &LateContext<'_>, ident: &Ident, hir_id: HirId, be_aggressive
9393
while let Some(c) = s.next() {
9494
r.push(
9595
if replace(&mut prev_upper, c.is_ascii_uppercase())
96-
&& s.clone().next().map_or(true, |c| c.is_ascii_uppercase())
96+
&& s.clone().next().is_none_or(|c| c.is_ascii_uppercase())
9797
{
9898
c.to_ascii_lowercase()
9999
} else {

clippy_lints/src/use_self.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
9494
&& let parameters = &item_path.segments.last().expect(SEGMENTS_MSG).args
9595
&& parameters
9696
.as_ref()
97-
.map_or(true, |params| params.parenthesized == GenericArgsParentheses::No)
97+
.is_none_or(|params| params.parenthesized == GenericArgsParentheses::No)
9898
&& !item.span.from_expansion()
9999
&& !is_from_proc_macro(cx, item)
100100
// expensive, should be last check

clippy_utils/src/consts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ impl Constant<'_> {
226226
.zip(r)
227227
.zip(tys)
228228
.map(|((li, ri), cmp_type)| Self::partial_cmp(tcx, cmp_type, li, ri))
229-
.find(|r| r.map_or(true, |o| o != Ordering::Equal))
229+
.find(|r| r.is_none_or(|o| o != Ordering::Equal))
230230
.unwrap_or_else(|| Some(l.len().cmp(&r.len()))),
231231
_ => None,
232232
},
@@ -236,7 +236,7 @@ impl Constant<'_> {
236236
};
237237
iter::zip(l, r)
238238
.map(|(li, ri)| Self::partial_cmp(tcx, cmp_type, li, ri))
239-
.find(|r| r.map_or(true, |o| o != Ordering::Equal))
239+
.find(|r| r.is_none_or(|o| o != Ordering::Equal))
240240
.unwrap_or_else(|| Some(l.len().cmp(&r.len())))
241241
},
242242
(Self::Repeat(lv, ls), Self::Repeat(rv, rs)) => {

0 commit comments

Comments
 (0)