Skip to content

Commit 1329847

Browse files
committed
Use is_some_and in clippy
1 parent 73bc754 commit 1329847

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+97
-103
lines changed

src/tools/clippy/book/src/development/common_tools_writing_lints.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl LateLintPass<'_> for MyStructLint {
140140
// we are looking for the `DefId` of `Drop` trait in lang items
141141
.drop_trait()
142142
// then we use it with our type `ty` by calling `implements_trait` from Clippy's utils
143-
.map_or(false, |id| implements_trait(cx, ty, id, &[])) {
143+
.is_some_and(|id| implements_trait(cx, ty, id, &[])) {
144144
// `expr` implements `Drop` trait
145145
}
146146

src/tools/clippy/clippy_dev/src/bless.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub fn bless(ignore_timestamp: bool) {
2020
WalkDir::new(build_dir())
2121
.into_iter()
2222
.map(Result::unwrap)
23-
.filter(|entry| entry.path().extension().map_or(false, |ext| extensions.contains(&ext)))
23+
.filter(|entry| entry.path().extension().is_some_and(|ext| extensions.contains(&ext)))
2424
.for_each(|entry| update_reference_file(&entry, ignore_timestamp));
2525
}
2626

src/tools/clippy/clippy_dev/src/setup/vscode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ fn delete_vs_task_file(path: &Path) -> bool {
9393
/// It may fail silently.
9494
fn try_delete_vs_directory_if_empty() {
9595
let path = Path::new(VSCODE_DIR);
96-
if path.read_dir().map_or(false, |mut iter| iter.next().is_none()) {
96+
if path.read_dir().is_some_and(|mut iter| iter.next().is_none()) {
9797
// The directory is empty. We just try to delete it but allow a silence
9898
// fail as an empty `.vscode` directory is still valid
9999
let _silence_result = fs::remove_dir(path);

src/tools/clippy/clippy_lints/src/attrs.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,15 +336,15 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
336336
return;
337337
}
338338
if let Some(lint_list) = &attr.meta_item_list() {
339-
if attr.ident().map_or(false, |ident| is_lint_level(ident.name)) {
339+
if attr.ident().is_some_and(|ident| is_lint_level(ident.name)) {
340340
for lint in lint_list {
341341
match item.kind {
342342
ItemKind::Use(..) => {
343343
if is_word(lint, sym::unused_imports)
344344
|| is_word(lint, sym::deprecated)
345345
|| is_word(lint, sym!(unreachable_pub))
346346
|| is_word(lint, sym!(unused))
347-
|| extract_clippy_lint(lint).map_or(false, |s| {
347+
|| extract_clippy_lint(lint).is_some_and(|s| {
348348
matches!(
349349
s.as_str(),
350350
"wildcard_imports" | "enum_glob_use" | "redundant_pub_crate",
@@ -493,7 +493,7 @@ fn is_relevant_block(cx: &LateContext<'_>, typeck_results: &ty::TypeckResults<'_
493493
block
494494
.expr
495495
.as_ref()
496-
.map_or(false, |e| is_relevant_expr(cx, typeck_results, e)),
496+
.is_some_and(|e| is_relevant_expr(cx, typeck_results, e)),
497497
|stmt| match &stmt.kind {
498498
StmtKind::Local(_) => true,
499499
StmtKind::Expr(expr) | StmtKind::Semi(expr) => is_relevant_expr(cx, typeck_results, expr),
@@ -503,7 +503,7 @@ fn is_relevant_block(cx: &LateContext<'_>, typeck_results: &ty::TypeckResults<'_
503503
}
504504

505505
fn is_relevant_expr(cx: &LateContext<'_>, typeck_results: &ty::TypeckResults<'_>, expr: &Expr<'_>) -> bool {
506-
if macro_backtrace(expr.span).last().map_or(false, |macro_call| {
506+
if macro_backtrace(expr.span).last().is_some_and(|macro_call| {
507507
is_panic(cx, macro_call.def_id) || cx.tcx.item_name(macro_call.def_id) == sym::unreachable
508508
}) {
509509
return false;

src/tools/clippy/clippy_lints/src/bool_assert_comparison.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ fn is_impl_not_trait_with_bool_out(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
5858
trait_id,
5959
)
6060
})
61-
.map_or(false, |assoc_item| {
61+
.is_some_and(|assoc_item| {
6262
let proj = cx.tcx.mk_projection(assoc_item.def_id, cx.tcx.mk_substs_trait(ty, &[]));
6363
let nty = cx.tcx.normalize_erasing_regions(cx.param_env, proj);
6464

src/tools/clippy/clippy_lints/src/booleans.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> {
482482

483483
fn implements_ord<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) -> bool {
484484
let ty = cx.typeck_results().expr_ty(expr);
485-
get_trait_def_id(cx, &paths::ORD).map_or(false, |id| implements_trait(cx, ty, id, &[]))
485+
get_trait_def_id(cx, &paths::ORD).is_some_and(|&id| implements_trait(cx, ty, id, &[]))
486486
}
487487

488488
struct NotSimplificationVisitor<'a, 'tcx> {

src/tools/clippy/clippy_lints/src/comparison_chain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl<'tcx> LateLintPass<'tcx> for ComparisonChain {
106106

107107
// Check that the type being compared implements `core::cmp::Ord`
108108
let ty = cx.typeck_results().expr_ty(lhs1);
109-
let is_ord = get_trait_def_id(cx, &paths::ORD).map_or(false, |id| implements_trait(cx, ty, id, &[]));
109+
let is_ord = get_trait_def_id(cx, &paths::ORD).is_some_and(|&id| implements_trait(cx, ty, id, &[]));
110110

111111
if !is_ord {
112112
return;

src/tools/clippy/clippy_lints/src/copies.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ fn scan_block_for_eq(cx: &LateContext<'_>, _conds: &[&Expr<'_>], block: &Block<'
466466
}
467467

468468
fn check_for_warn_of_moved_symbol(cx: &LateContext<'_>, symbols: &[(HirId, Symbol)], if_expr: &Expr<'_>) -> bool {
469-
get_enclosing_block(cx, if_expr.hir_id).map_or(false, |block| {
469+
get_enclosing_block(cx, if_expr.hir_id).is_some_and(|block| {
470470
let ignore_span = block.span.shrink_to_lo().to(if_expr.span);
471471

472472
symbols

src/tools/clippy/clippy_lints/src/derive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ fn check_copy_clone<'tcx>(cx: &LateContext<'tcx>, item: &Item<'_>, trait_ref: &h
352352
// there's a Copy impl for any instance of the adt.
353353
if !is_copy(cx, ty) {
354354
if ty_subs.non_erasable_generics().next().is_some() {
355-
let has_copy_impl = cx.tcx.all_local_trait_impls(()).get(&copy_id).map_or(false, |impls| {
355+
let has_copy_impl = cx.tcx.all_local_trait_impls(()).get(&copy_id).is_some_and(|impls| {
356356
impls
357357
.iter()
358358
.any(|&id| matches!(cx.tcx.type_of(id).kind(), ty::Adt(adt, _) if ty_adt.did() == adt.did()))

src/tools/clippy/clippy_lints/src/enum_variants.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ fn check_enum_start(cx: &LateContext<'_>, item_name: &str, variant: &Variant<'_>
132132
let item_name_chars = item_name.chars().count();
133133

134134
if count_match_start(item_name, name).char_count == item_name_chars
135-
&& name.chars().nth(item_name_chars).map_or(false, |c| !c.is_lowercase())
136-
&& name.chars().nth(item_name_chars + 1).map_or(false, |c| !c.is_numeric())
135+
&& name.chars().nth(item_name_chars).is_some_and(|c| !c.is_lowercase())
136+
&& name.chars().nth(item_name_chars + 1).is_some_and(|c| !c.is_numeric())
137137
{
138138
span_lint(
139139
cx,

src/tools/clippy/clippy_lints/src/eta_reduction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction {
126126
if_chain! {
127127
if let ty::Closure(_, substs) = callee_ty.peel_refs().kind();
128128
if substs.as_closure().kind() == ClosureKind::FnMut;
129-
if path_to_local(callee).map_or(false, |l| local_used_after_expr(cx, l, expr));
129+
if path_to_local(callee).is_some_and(|&l| local_used_after_expr(cx, l, expr));
130130

131131
then {
132132
// Mutable closure is used after current expr; we cannot consume it.

src/tools/clippy/clippy_lints/src/if_let_mutex.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl<'tcx> Visitor<'tcx> for ArmVisitor<'_, 'tcx> {
121121
impl<'tcx, 'l> ArmVisitor<'tcx, 'l> {
122122
fn same_mutex(&self, cx: &LateContext<'_>, op_mutex: &Expr<'_>) -> bool {
123123
self.found_mutex
124-
.map_or(false, |arm_mutex| SpanlessEq::new(cx).eq_expr(op_mutex, arm_mutex))
124+
.is_some_and(|arm_mutex| SpanlessEq::new(cx).eq_expr(op_mutex, arm_mutex))
125125
}
126126
}
127127

src/tools/clippy/clippy_lints/src/infinite_iter.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,9 @@ fn is_infinite(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness {
169169
ExprKind::Block(block, _) => block.expr.as_ref().map_or(Finite, |e| is_infinite(cx, e)),
170170
ExprKind::Box(e) | ExprKind::AddrOf(BorrowKind::Ref, _, e) => is_infinite(cx, e),
171171
ExprKind::Call(path, _) => path_def_id(cx, path)
172-
.map_or(false, |id| match_def_path(cx, id, &paths::ITER_REPEAT))
172+
.is_some_and(|&id| match_def_path(cx, id, &paths::ITER_REPEAT))
173173
.into(),
174-
ExprKind::Struct(..) => higher::Range::hir(expr).map_or(false, |r| r.end.is_none()).into(),
174+
ExprKind::Struct(..) => higher::Range::hir(expr).is_some_and(|r| r.end.is_none()).into(),
175175
_ => Finite,
176176
}
177177
}
@@ -233,9 +233,7 @@ fn complete_infinite_iter(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness {
233233
let not_double_ended = cx
234234
.tcx
235235
.get_diagnostic_item(sym::DoubleEndedIterator)
236-
.map_or(false, |id| {
237-
!implements_trait(cx, cx.typeck_results().expr_ty(&args[0]), id, &[])
238-
});
236+
.is_some_and(|&id| !implements_trait(cx, cx.typeck_results().expr_ty(&args[0]), id, &[]));
239237
if not_double_ended {
240238
return is_infinite(cx, &args[0]);
241239
}

src/tools/clippy/clippy_lints/src/iter_not_returning_iterator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ fn check_sig(cx: &LateContext<'_>, name: &str, sig: &FnSig<'_>, fn_id: LocalDefI
7474
if cx
7575
.tcx
7676
.get_diagnostic_item(sym::Iterator)
77-
.map_or(false, |iter_id| !implements_trait(cx, ret_ty, iter_id, &[]))
77+
.is_some_and(|&iter_id| !implements_trait(cx, ret_ty, iter_id, &[]))
7878
{
7979
span_lint(
8080
cx,

src/tools/clippy/clippy_lints/src/len_zero.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
480480

481481
let ty = &cx.typeck_results().expr_ty(expr).peel_refs();
482482
match ty.kind() {
483-
ty::Dynamic(tt, ..) => tt.principal().map_or(false, |principal| {
483+
ty::Dynamic(tt, ..) => tt.principal().is_some_and(|principal| {
484484
let is_empty = sym!(is_empty);
485485
cx.tcx
486486
.associated_items(principal.def_id())

src/tools/clippy/clippy_lints/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#![feature(box_patterns)]
44
#![feature(control_flow_enum)]
55
#![feature(drain_filter)]
6+
#![feature(is_some_with)]
67
#![feature(iter_intersperse)]
78
#![feature(let_chains)]
89
#![feature(let_else)]

src/tools/clippy/clippy_lints/src/lifetimes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> {
413413
.tcx
414414
.lang_items()
415415
.require(item)
416-
.map_or(false, |id| Some(id) == trait_ref.trait_def_id())
416+
.is_ok_and(|&id| Some(id) == trait_ref.trait_def_id())
417417
}) {
418418
let mut sub_visitor = RefVisitor::new(self.cx);
419419
sub_visitor.visit_trait_ref(trait_ref);

src/tools/clippy/clippy_lints/src/loops/explicit_iter_loop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fn is_iterable_array<'tcx>(ty: Ty<'tcx>, cx: &LateContext<'tcx>) -> bool {
6969
match ty.kind() {
7070
ty::Array(_, n) => n
7171
.try_eval_usize(cx.tcx, cx.param_env)
72-
.map_or(false, |val| (0..=32).contains(&val)),
72+
.is_some_and(|val| (0..=32).contains(val)),
7373
_ => false,
7474
}
7575
}

src/tools/clippy/clippy_lints/src/loops/manual_memcpy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ fn get_assignments<'a, 'tcx>(
418418
.chain((*expr).into_iter())
419419
.filter(move |e| {
420420
if let ExprKind::AssignOp(_, place, _) = e.kind {
421-
path_to_local(place).map_or(false, |id| {
421+
path_to_local(place).is_some_and(|&id| {
422422
!loop_counters
423423
.iter()
424424
// skip the first item which should be `StartKind::Range`

src/tools/clippy/clippy_lints/src/loops/mut_range_bound.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl BreakAfterExprVisitor {
139139
break_after_expr: false,
140140
};
141141

142-
get_enclosing_block(cx, hir_id).map_or(false, |block| {
142+
get_enclosing_block(cx, hir_id).is_some_and(|block| {
143143
visitor.visit_block(block);
144144
visitor.break_after_expr
145145
})

src/tools/clippy/clippy_lints/src/loops/same_item_push.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub(super) fn check<'tcx>(
5353
.tcx
5454
.lang_items()
5555
.clone_trait()
56-
.map_or(false, |id| implements_trait(cx, ty, id, &[]));
56+
.is_some_and(|&id| implements_trait(cx, ty, id, &[]));
5757
then {
5858
// Make sure that the push does not involve possibly mutating values
5959
match pushed_item.kind {

src/tools/clippy/clippy_lints/src/loops/utils.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,10 @@ impl<'tcx> Visitor<'tcx> for LoopNestVisitor {
321321
/// If `arg` was the argument to a `for` loop, return the "cleanest" way of writing the
322322
/// actual `Iterator` that the loop uses.
323323
pub(super) fn make_iterator_snippet(cx: &LateContext<'_>, arg: &Expr<'_>, applic_ref: &mut Applicability) -> String {
324-
let impls_iterator = cx.tcx.get_diagnostic_item(sym::Iterator).map_or(false, |id| {
325-
implements_trait(cx, cx.typeck_results().expr_ty(arg), id, &[])
326-
});
324+
let impls_iterator = cx
325+
.tcx
326+
.get_diagnostic_item(sym::Iterator)
327+
.is_some_and(|&id| implements_trait(cx, cx.typeck_results().expr_ty(arg), id, &[]));
327328
if impls_iterator {
328329
format!(
329330
"{}",

src/tools/clippy/clippy_lints/src/loops/while_let_loop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ fn extract_first_expr<'tcx>(block: &Block<'tcx>) -> Option<&'tcx Expr<'tcx>> {
6565
fn is_simple_break_expr(expr: &Expr<'_>) -> bool {
6666
match expr.kind {
6767
ExprKind::Break(dest, ref passed_expr) if dest.label.is_none() && passed_expr.is_none() => true,
68-
ExprKind::Block(b, _) => extract_first_expr(b).map_or(false, is_simple_break_expr),
68+
ExprKind::Block(b, _) => extract_first_expr(b).is_some_and(|e| is_simple_break_expr(e)),
6969
_ => false,
7070
}
7171
}

src/tools/clippy/clippy_lints/src/manual_strip.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@ fn eq_pattern_length<'tcx>(cx: &LateContext<'tcx>, pattern: &Expr<'_>, expr: &'t
160160
..
161161
}) = expr.kind
162162
{
163-
constant_length(cx, pattern).map_or(false, |length| length == n)
163+
constant_length(cx, pattern).is_some_and(|&length| length == n)
164164
} else {
165-
len_arg(cx, expr).map_or(false, |arg| eq_expr_value(cx, pattern, arg))
165+
len_arg(cx, expr).is_some_and(|arg| eq_expr_value(cx, pattern, arg))
166166
}
167167
}
168168

src/tools/clippy/clippy_lints/src/map_clone.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl<'tcx> LateLintPass<'tcx> for MapClone {
9292
if ident_eq(name, obj) && method.ident.name == sym::clone;
9393
if let Some(fn_id) = cx.typeck_results().type_dependent_def_id(closure_expr.hir_id);
9494
if let Some(trait_id) = cx.tcx.trait_of_item(fn_id);
95-
if cx.tcx.lang_items().clone_trait().map_or(false, |id| id == trait_id);
95+
if cx.tcx.lang_items().clone_trait().is_some_and(|&id| id == trait_id);
9696
// no autoderefs
9797
if !cx.typeck_results().expr_adjustments(obj).iter()
9898
.any(|a| matches!(a.kind, Adjust::Deref(Some(..))));

src/tools/clippy/clippy_lints/src/matches/match_like_matches.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ where
8888
if first_attrs.is_empty();
8989
if iter
9090
.all(|arm| {
91-
find_bool_lit(&arm.2.kind, is_if_let).map_or(false, |b| b == b0) && arm.3.is_none() && arm.0.is_empty()
91+
find_bool_lit(&arm.2.kind, is_if_let).is_some_and(|&b| b == b0) && arm.3.is_none() && arm.0.is_empty()
9292
});
9393
then {
9494
if let Some(last_pat) = last_pat_opt {

src/tools/clippy/clippy_lints/src/matches/redundant_pattern_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ fn temporaries_need_ordered_drop<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<
9090
.cx
9191
.typeck_results()
9292
.type_dependent_def_id(expr.hir_id)
93-
.map_or(false, |id| self.cx.tcx.fn_sig(id).skip_binder().inputs()[0].is_ref());
93+
.is_some_and(|id| self.cx.tcx.fn_sig(id).skip_binder().inputs()[0].is_ref());
9494
if self_by_ref && needs_ordered_drop(self.cx, self.cx.typeck_results().expr_ty(self_arg)) {
9595
self.res = true;
9696
} else {

src/tools/clippy/clippy_lints/src/mem_forget.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl<'tcx> LateLintPass<'tcx> for MemForget {
3535
if cx.tcx.is_diagnostic_item(sym::mem_forget, def_id) {
3636
let forgot_ty = cx.typeck_results().expr_ty(first_arg);
3737

38-
if forgot_ty.ty_adt_def().map_or(false, |def| def.has_dtor(cx.tcx)) {
38+
if forgot_ty.ty_adt_def().is_some_and(|def| def.has_dtor(cx.tcx)) {
3939
span_lint(cx, MEM_FORGET, e.span, "usage of `mem::forget` on `Drop` type");
4040
}
4141
}

src/tools/clippy/clippy_lints/src/methods/err_expect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,5 @@ fn get_data_type<'a>(cx: &LateContext<'_>, ty: Ty<'a>) -> Option<Ty<'a>> {
5656
fn has_debug_impl<'tcx>(ty: Ty<'tcx>, cx: &LateContext<'tcx>) -> bool {
5757
cx.tcx
5858
.get_diagnostic_item(sym::Debug)
59-
.map_or(false, |debug| implements_trait(cx, ty, debug, &[]))
59+
.is_some_and(|&debug| implements_trait(cx, ty, debug, &[]))
6060
}

src/tools/clippy/clippy_lints/src/methods/expect_fun_call.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub(super) fn check<'tcx>(
8484
hir::ExprKind::MethodCall(..) => {
8585
cx.typeck_results()
8686
.type_dependent_def_id(arg.hir_id)
87-
.map_or(false, |method_id| {
87+
.is_some_and(|method_id| {
8888
matches!(
8989
cx.tcx.fn_sig(method_id).output().skip_binder().kind(),
9090
ty::Ref(re, ..) if re.is_static()

src/tools/clippy/clippy_lints/src/methods/filter_next.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ pub(super) fn check<'tcx>(
1616
filter_arg: &'tcx hir::Expr<'_>,
1717
) {
1818
// lint if caller of `.filter().next()` is an Iterator
19-
let recv_impls_iterator = cx.tcx.get_diagnostic_item(sym::Iterator).map_or(false, |id| {
20-
implements_trait(cx, cx.typeck_results().expr_ty(recv), id, &[])
21-
});
19+
let recv_impls_iterator = cx
20+
.tcx
21+
.get_diagnostic_item(sym::Iterator)
22+
.is_some_and(|&id| implements_trait(cx, cx.typeck_results().expr_ty(recv), id, &[]));
2223
if recv_impls_iterator {
2324
let msg = "called `filter(..).next()` on an `Iterator`. This is more succinctly expressed by calling \
2425
`.find(..)` instead";

src/tools/clippy/clippy_lints/src/methods/manual_str_repeat.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ fn parse_repeat_arg(cx: &LateContext<'_>, e: &Expr<'_>) -> Option<RepeatKind> {
3737
} else {
3838
let ty = cx.typeck_results().expr_ty(e);
3939
if is_type_diagnostic_item(cx, ty, sym::String)
40-
|| (is_type_lang_item(cx, ty, LangItem::OwnedBox) && get_ty_param(ty).map_or(false, Ty::is_str))
41-
|| (match_type(cx, ty, &paths::COW) && get_ty_param(ty).map_or(false, Ty::is_str))
40+
|| (is_type_lang_item(cx, ty, LangItem::OwnedBox) && get_ty_param(ty).is_some_and(|ty| ty.is_str()))
41+
|| (match_type(cx, ty, &paths::COW) && get_ty_param(ty).is_some_and(|ty| ty.is_str()))
4242
{
4343
Some(RepeatKind::String)
4444
} else {

src/tools/clippy/clippy_lints/src/methods/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2923,7 +2923,7 @@ impl SelfKind {
29232923
ty.boxed_ty() == parent_ty
29242924
} else if is_type_diagnostic_item(cx, ty, sym::Rc) || is_type_diagnostic_item(cx, ty, sym::Arc) {
29252925
if let ty::Adt(_, substs) = ty.kind() {
2926-
substs.types().next().map_or(false, |t| t == parent_ty)
2926+
substs.types().next().is_some_and(|&t| t == parent_ty)
29272927
} else {
29282928
false
29292929
}

src/tools/clippy/clippy_lints/src/methods/ok_expect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@ fn get_error_type<'a>(cx: &LateContext<'_>, ty: Ty<'a>) -> Option<Ty<'a>> {
4242
fn has_debug_impl<'tcx>(ty: Ty<'tcx>, cx: &LateContext<'tcx>) -> bool {
4343
cx.tcx
4444
.get_diagnostic_item(sym::Debug)
45-
.map_or(false, |debug| implements_trait(cx, ty, debug, &[]))
45+
.is_some_and(|&debug| implements_trait(cx, ty, debug, &[]))
4646
}

src/tools/clippy/clippy_lints/src/methods/option_as_ref_deref.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ pub(super) fn check<'tcx>(
4848
hir::ExprKind::Path(ref expr_qpath) => cx
4949
.qpath_res(expr_qpath, map_arg.hir_id)
5050
.opt_def_id()
51-
.map_or(false, |fun_def_id| {
52-
deref_aliases.iter().any(|path| match_def_path(cx, fun_def_id, path))
53-
}),
51+
.is_some_and(|&fun_def_id| deref_aliases.iter().any(|path| match_def_path(cx, fun_def_id, path))),
5452
hir::ExprKind::Closure { body, .. } => {
5553
let closure_body = cx.tcx.hir().body(body);
5654
let closure_expr = peel_blocks(&closure_body.value);

src/tools/clippy/clippy_lints/src/methods/str_splitn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ fn parse_iter_usage<'tcx>(
372372
&& cx
373373
.typeck_results()
374374
.type_dependent_def_id(e.hir_id)
375-
.map_or(false, |id| is_diag_item_method(cx, id, sym::Option)) =>
375+
.is_some_and(|&id| is_diag_item_method(cx, id, sym::Option)) =>
376376
{
377377
(Some(UnwrapKind::Unwrap), e.span)
378378
},

0 commit comments

Comments
 (0)