Skip to content

Commit 3f1c202

Browse files
committed
Simplify instances of Option::map_or(true, …) in Clippy sources
1 parent f0426c3 commit 3f1c202

34 files changed

+39
-42
lines changed

clippy_config/src/msrvs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl Msrv {
121121
}
122122

123123
pub fn meets(&self, required: RustcVersion) -> bool {
124-
self.current().map_or(true, |msrv| msrv >= required)
124+
self.current().is_none_or(|msrv| msrv >= required)
125125
}
126126

127127
fn parse_attr(sess: &Session, attrs: &[Attribute]) -> Option<RustcVersion> {

clippy_lints/src/approx_const.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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
}

0 commit comments

Comments
 (0)