Skip to content

Commit 9e14e5d

Browse files
committed
new lint unnecessary_map_or
1 parent a79db2a commit 9e14e5d

File tree

77 files changed

+508
-146
lines changed

Some content is hidden

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

77 files changed

+508
-146
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5740,6 +5740,7 @@ Released 2018-09-13
57405740
[`unnecessary_lazy_evaluations`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_lazy_evaluations
57415741
[`unnecessary_literal_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_literal_unwrap
57425742
[`unnecessary_map_on_constructor`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_map_on_constructor
5743+
[`unnecessary_map_or`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_map_or
57435744
[`unnecessary_mut_passed`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_mut_passed
57445745
[`unnecessary_operation`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_operation
57455746
[`unnecessary_owned_empty_strings`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_owned_empty_strings

clippy_dev/src/setup/vscode.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ fn delete_vs_task_file(path: &Path) -> bool {
8484
/// It may fail silently.
8585
fn try_delete_vs_directory_if_empty() {
8686
let path = Path::new(VSCODE_DIR);
87-
if path.read_dir().map_or(false, |mut iter| iter.next().is_none()) {
87+
if path.read_dir().is_ok_and(|mut iter| iter.next().is_none()) {
8888
// The directory is empty. We just try to delete it but allow a silence
8989
// fail as an empty `.vscode` directory is still valid
9090
let _silence_result = fs::remove_dir(path);

clippy_lints/src/attrs/useless_attribute.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub(super) fn check(cx: &LateContext<'_>, item: &Item<'_>, attrs: &[Attribute])
1616
return;
1717
}
1818
if let Some(lint_list) = &attr.meta_item_list() {
19-
if attr.ident().map_or(false, |ident| is_lint_level(ident.name, attr.id)) {
19+
if attr.ident().is_some_and(|ident| is_lint_level(ident.name, attr.id)) {
2020
for lint in lint_list {
2121
match item.kind {
2222
ItemKind::Use(..) => {
@@ -25,7 +25,7 @@ pub(super) fn check(cx: &LateContext<'_>, item: &Item<'_>, attrs: &[Attribute])
2525
|| is_word(lint, sym!(unreachable_pub))
2626
|| is_word(lint, sym!(unused))
2727
|| is_word(lint, sym!(unused_import_braces))
28-
|| extract_clippy_lint(lint).map_or(false, |s| {
28+
|| extract_clippy_lint(lint).is_some_and(|s| {
2929
matches!(
3030
s.as_str(),
3131
"wildcard_imports"

clippy_lints/src/attrs/utils.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ fn is_relevant_block(cx: &LateContext<'_>, typeck_results: &ty::TypeckResults<'_
5050
block
5151
.expr
5252
.as_ref()
53-
.map_or(false, |e| is_relevant_expr(cx, typeck_results, e)),
53+
.is_some_and(|e| is_relevant_expr(cx, typeck_results, e)),
5454
|stmt| match &stmt.kind {
5555
StmtKind::Local(_) => true,
5656
StmtKind::Expr(expr) | StmtKind::Semi(expr) => is_relevant_expr(cx, typeck_results, expr),
@@ -60,7 +60,7 @@ fn is_relevant_block(cx: &LateContext<'_>, typeck_results: &ty::TypeckResults<'_
6060
}
6161

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

clippy_lints/src/bool_assert_comparison.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ fn is_impl_not_trait_with_bool_out<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -
6060
trait_id,
6161
)
6262
})
63-
.map_or(false, |assoc_item| {
63+
.is_some_and(|assoc_item| {
6464
let proj = Ty::new_projection(cx.tcx, assoc_item.def_id, cx.tcx.mk_args_trait(ty, []));
6565
let nty = cx.tcx.normalize_erasing_regions(cx.param_env, proj);
6666

clippy_lints/src/booleans.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ fn implements_ord(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
577577
let ty = cx.typeck_results().expr_ty(expr);
578578
cx.tcx
579579
.get_diagnostic_item(sym::Ord)
580-
.map_or(false, |id| implements_trait(cx, ty, id, &[]))
580+
.is_some_and(|id| implements_trait(cx, ty, id, &[]))
581581
}
582582

583583
struct NotSimplificationVisitor<'a, 'tcx> {

clippy_lints/src/box_default.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl LateLintPass<'_> for BoxDefault {
5050
// And that method is `new`
5151
&& seg.ident.name == sym::new
5252
// And the call is that of a `Box` method
53-
&& path_def_id(cx, ty).map_or(false, |id| Some(id) == cx.tcx.lang_items().owned_box())
53+
&& path_def_id(cx, ty).is_some_and(|id| Some(id) == cx.tcx.lang_items().owned_box())
5454
// And the single argument to the call is another function call
5555
// This is the `T::default()` of `Box::new(T::default())`
5656
&& let ExprKind::Call(arg_path, inner_call_args) = arg.kind
@@ -60,6 +60,7 @@ impl LateLintPass<'_> for BoxDefault {
6060
// or that we are inside a `vec!` macro expansion
6161
&& (expr.span.eq_ctxt(arg.span) || is_local_vec_expn(cx, arg, expr))
6262
// And the argument is equivalent to `Default::default()`
63+
&& path_def_id(cx, ty).is_some_and(|id| Some(id) == cx.tcx.lang_items().owned_box())
6364
&& is_default_equivalent(cx, arg)
6465
{
6566
span_lint_and_sugg(
@@ -118,9 +119,9 @@ fn explicit_default_type<'a>(arg_path: &'a Expr<'_>) -> Option<&'a Ty<'a>> {
118119
}
119120

120121
fn is_local_vec_expn(cx: &LateContext<'_>, expr: &Expr<'_>, ref_expr: &Expr<'_>) -> bool {
121-
macro_backtrace(expr.span).next().map_or(false, |call| {
122-
cx.tcx.is_diagnostic_item(sym::vec_macro, call.def_id) && call.span.eq_ctxt(ref_expr.span)
123-
})
122+
macro_backtrace(expr.span)
123+
.next()
124+
.is_some_and(|call| cx.tcx.is_diagnostic_item(sym::vec_macro, call.def_id) && call.span.eq_ctxt(ref_expr.span))
124125
}
125126

126127
#[derive(Default)]

clippy_lints/src/casts/unnecessary_cast.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,7 @@ pub(super) fn check<'tcx>(
159159
// The same is true if the expression encompassing the cast expression is a unary
160160
// expression or an addressof expression.
161161
let needs_block = matches!(cast_expr.kind, ExprKind::Unary(..) | ExprKind::AddrOf(..))
162-
|| get_parent_expr(cx, expr)
163-
.map_or(false, |e| matches!(e.kind, ExprKind::Unary(..) | ExprKind::AddrOf(..)));
162+
|| get_parent_expr(cx, expr).is_some_and(|e| matches!(e.kind, ExprKind::Unary(..) | ExprKind::AddrOf(..)));
164163

165164
span_lint_and_sugg(
166165
cx,

clippy_lints/src/comparison_chain.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl<'tcx> LateLintPass<'tcx> for ComparisonChain {
110110
let is_ord = cx
111111
.tcx
112112
.get_diagnostic_item(sym::Ord)
113-
.map_or(false, |id| implements_trait(cx, ty, id, &[]));
113+
.is_some_and(|id| implements_trait(cx, ty, id, &[]));
114114

115115
if !is_ord {
116116
return;

clippy_lints/src/copies.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ fn lint_branches_sharing_code<'tcx>(
272272
let span = span.with_hi(last_block.span.hi());
273273
// Improve formatting if the inner block has indention (i.e. normal Rust formatting)
274274
let test_span = Span::new(span.lo() - BytePos(4), span.lo(), span.ctxt(), span.parent());
275-
let span = if snippet_opt(cx, test_span).map_or(false, |snip| snip == " ") {
275+
let span = if snippet_opt(cx, test_span).is_some_and(|snip| snip == " ") {
276276
span.with_lo(test_span.lo())
277277
} else {
278278
span
@@ -353,7 +353,7 @@ fn eq_binding_names(s: &Stmt<'_>, names: &[(HirId, Symbol)]) -> bool {
353353
let mut i = 0usize;
354354
let mut res = true;
355355
l.pat.each_binding_or_first(&mut |_, _, _, name| {
356-
if names.get(i).map_or(false, |&(_, n)| n == name.name) {
356+
if names.get(i).is_some_and(|&(_, n)| n == name.name) {
357357
i += 1;
358358
} else {
359359
res = false;
@@ -397,12 +397,10 @@ fn eq_stmts(
397397
let new_bindings = &moved_bindings[old_count..];
398398
blocks
399399
.iter()
400-
.all(|b| get_stmt(b).map_or(false, |s| eq_binding_names(s, new_bindings)))
400+
.all(|b| get_stmt(b).is_some_and(|s| eq_binding_names(s, new_bindings)))
401401
} else {
402402
true
403-
}) && blocks
404-
.iter()
405-
.all(|b| get_stmt(b).map_or(false, |s| eq.eq_stmt(s, stmt)))
403+
}) && blocks.iter().all(|b| get_stmt(b).is_some_and(|s| eq.eq_stmt(s, stmt)))
406404
}
407405

408406
#[expect(clippy::too_many_lines)]
@@ -459,9 +457,7 @@ fn scan_block_for_eq<'tcx>(
459457
// x + 50
460458
let expr_hash_eq = if let Some(e) = block.expr {
461459
let hash = hash_expr(cx, e);
462-
blocks
463-
.iter()
464-
.all(|b| b.expr.map_or(false, |e| hash_expr(cx, e) == hash))
460+
blocks.iter().all(|b| b.expr.is_some_and(|e| hash_expr(cx, e) == hash))
465461
} else {
466462
blocks.iter().all(|b| b.expr.is_none())
467463
};
@@ -522,7 +518,7 @@ fn scan_block_for_eq<'tcx>(
522518
});
523519
if let Some(e) = block.expr {
524520
for block in blocks {
525-
if block.expr.map_or(false, |expr| !eq.eq_expr(expr, e)) {
521+
if block.expr.is_some_and(|expr| !eq.eq_expr(expr, e)) {
526522
moved_locals.truncate(moved_locals_at_start);
527523
return BlockEq {
528524
start_end_eq,
@@ -541,7 +537,7 @@ fn scan_block_for_eq<'tcx>(
541537
}
542538

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

547543
symbols

clippy_lints/src/declared_lints.rs

+1
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
463463
crate::methods::UNNECESSARY_LAZY_EVALUATIONS_INFO,
464464
crate::methods::UNNECESSARY_LITERAL_UNWRAP_INFO,
465465
crate::methods::UNNECESSARY_RESULT_MAP_OR_ELSE_INFO,
466+
crate::methods::UNNECESSARY_MAP_OR_INFO,
466467
crate::methods::UNNECESSARY_SORT_BY_INFO,
467468
crate::methods::UNNECESSARY_TO_OWNED_INFO,
468469
crate::methods::UNWRAP_OR_DEFAULT_INFO,

clippy_lints/src/default_numeric_fallback.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,6 @@ impl<'tcx> From<Ty<'tcx>> for ExplicitTyBound {
253253

254254
impl<'tcx> From<Option<Ty<'tcx>>> for ExplicitTyBound {
255255
fn from(v: Option<Ty<'tcx>>) -> Self {
256-
Self(v.map_or(false, Ty::is_numeric))
256+
Self(v.is_some_and(Ty::is_numeric))
257257
}
258258
}

clippy_lints/src/derivable_impls.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ fn is_path_self(e: &Expr<'_>) -> bool {
7979
fn contains_trait_object(ty: Ty<'_>) -> bool {
8080
match ty.kind() {
8181
ty::Ref(_, ty, _) => contains_trait_object(*ty),
82-
ty::Adt(def, args) => def.is_box() && args[0].as_type().map_or(false, contains_trait_object),
82+
ty::Adt(def, args) => def.is_box() && args[0].as_type().is_some_and(contains_trait_object),
8383
ty::Dynamic(..) => true,
8484
_ => false,
8585
}

clippy_lints/src/derive.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ fn check_copy_clone<'tcx>(cx: &LateContext<'tcx>, item: &Item<'_>, trait_ref: &h
326326
// there's a Copy impl for any instance of the adt.
327327
if !is_copy(cx, ty) {
328328
if ty_subs.non_erasable_generics(cx.tcx, ty_adt.did()).next().is_some() {
329-
let has_copy_impl = cx.tcx.all_local_trait_impls(()).get(&copy_id).map_or(false, |impls| {
329+
let has_copy_impl = cx.tcx.all_local_trait_impls(()).get(&copy_id).is_some_and(|impls| {
330330
impls.iter().any(|&id| {
331331
matches!(cx.tcx.type_of(id).instantiate_identity().kind(), ty::Adt(adt, _)
332332
if ty_adt.did() == adt.did())

clippy_lints/src/drop_forget_ref.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef {
111111
MEM_FORGET,
112112
Cow::Owned(format!(
113113
"usage of `mem::forget` on {}",
114-
if arg_ty.ty_adt_def().map_or(false, |def| def.has_dtor(cx.tcx)) {
114+
if arg_ty.ty_adt_def().is_some_and(|def| def.has_dtor(cx.tcx)) {
115115
"`Drop` type"
116116
} else {
117117
"type with `Drop` fields"

clippy_lints/src/eta_reduction.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction {
174174
cx.param_env,
175175
Binder::bind_with_vars(callee_ty_adjusted, List::empty()),
176176
ImplPolarity::Positive,
177-
) && path_to_local(callee).map_or(false, |l| {
178-
local_used_in(cx, l, args) || local_used_after_expr(cx, l, expr)
179-
}) {
177+
) && path_to_local(callee)
178+
.is_some_and(|l| local_used_in(cx, l, args) || local_used_after_expr(cx, l, expr))
179+
{
180180
// Mutable closure is used after current expr; we cannot consume it.
181181
snippet = format!("&mut {snippet}");
182182
}

clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ fn raw_ptr_arg(cx: &LateContext<'_>, arg: &hir::Param<'_>) -> Option<hir::HirId>
8787
}
8888

8989
fn check_arg(cx: &LateContext<'_>, raw_ptrs: &HirIdSet, arg: &hir::Expr<'_>) {
90-
if path_to_local(arg).map_or(false, |id| raw_ptrs.contains(&id)) {
90+
if path_to_local(arg).is_some_and(|id| raw_ptrs.contains(&id)) {
9191
span_lint(
9292
cx,
9393
NOT_UNSAFE_PTR_ARG_DEREF,

clippy_lints/src/infinite_iter.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,13 @@ fn is_infinite(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness {
172172
if let ExprKind::Path(ref qpath) = path.kind {
173173
cx.qpath_res(qpath, path.hir_id)
174174
.opt_def_id()
175-
.map_or(false, |id| cx.tcx.is_diagnostic_item(sym::iter_repeat, id))
175+
.is_some_and(|id| cx.tcx.is_diagnostic_item(sym::iter_repeat, id))
176176
.into()
177177
} else {
178178
Finite
179179
}
180180
},
181-
ExprKind::Struct(..) => higher::Range::hir(expr).map_or(false, |r| r.end.is_none()).into(),
181+
ExprKind::Struct(..) => higher::Range::hir(expr).is_some_and(|r| r.end.is_none()).into(),
182182
_ => Finite,
183183
}
184184
}
@@ -240,9 +240,7 @@ fn complete_infinite_iter(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness {
240240
let not_double_ended = cx
241241
.tcx
242242
.get_diagnostic_item(sym::DoubleEndedIterator)
243-
.map_or(false, |id| {
244-
!implements_trait(cx, cx.typeck_results().expr_ty(receiver), id, &[])
245-
});
243+
.is_some_and(|id| !implements_trait(cx, cx.typeck_results().expr_ty(receiver), id, &[]));
246244
if not_double_ended {
247245
return is_infinite(cx, receiver);
248246
}

clippy_lints/src/item_name_repetitions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,8 @@ fn check_enum_start(cx: &LateContext<'_>, item_name: &str, variant: &Variant<'_>
292292
let item_name_chars = item_name.chars().count();
293293

294294
if count_match_start(item_name, name).char_count == item_name_chars
295-
&& name.chars().nth(item_name_chars).map_or(false, |c| !c.is_lowercase())
296-
&& name.chars().nth(item_name_chars + 1).map_or(false, |c| !c.is_numeric())
295+
&& name.chars().nth(item_name_chars).is_some_and(|c| !c.is_lowercase())
296+
&& name.chars().nth(item_name_chars + 1).is_some_and(|c| !c.is_numeric())
297297
{
298298
span_lint_hir(
299299
cx,

clippy_lints/src/iter_not_returning_iterator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ fn check_sig(cx: &LateContext<'_>, name: &str, sig: &FnSig<'_>, fn_id: LocalDefI
7878
if cx
7979
.tcx
8080
.get_diagnostic_item(sym::Iterator)
81-
.map_or(false, |iter_id| !implements_trait(cx, ret_ty, iter_id, &[]))
81+
.is_some_and(|iter_id| !implements_trait(cx, ret_ty, iter_id, &[]))
8282
{
8383
span_lint(
8484
cx,

clippy_lints/src/len_zero.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
616616

617617
let ty = &cx.typeck_results().expr_ty(expr).peel_refs();
618618
match ty.kind() {
619-
ty::Dynamic(tt, ..) => tt.principal().map_or(false, |principal| {
619+
ty::Dynamic(tt, ..) => tt.principal().is_some_and(|principal| {
620620
let is_empty = sym!(is_empty);
621621
cx.tcx
622622
.associated_items(principal.def_id())

clippy_lints/src/lifetimes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ fn elision_suggestions(
283283
suggestions.extend(
284284
usages
285285
.iter()
286-
.filter(|usage| named_lifetime(usage).map_or(false, |id| elidable_lts.contains(&id)))
286+
.filter(|usage| named_lifetime(usage).is_some_and(|id| elidable_lts.contains(&id)))
287287
.map(|usage| {
288288
match cx.tcx.parent_hir_node(usage.hir_id) {
289289
Node::Ty(Ty {

clippy_lints/src/loops/manual_find.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub(super) fn check<'tcx>(
5858
.tcx
5959
.lang_items()
6060
.copy_trait()
61-
.map_or(false, |id| implements_trait(cx, ty, id, &[]))
61+
.is_some_and(|id| implements_trait(cx, ty, id, &[]))
6262
{
6363
snippet.push_str(
6464
&format!(

clippy_lints/src/loops/manual_memcpy.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ fn get_assignments<'a, 'tcx>(
416416
.chain(*expr)
417417
.filter(move |e| {
418418
if let ExprKind::AssignOp(_, place, _) = e.kind {
419-
path_to_local(place).map_or(false, |id| {
419+
path_to_local(place).is_some_and(|id| {
420420
!loop_counters
421421
.iter()
422422
// skip the first item which should be `StartKind::Range`

clippy_lints/src/loops/mut_range_bound.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ impl BreakAfterExprVisitor {
134134
break_after_expr: false,
135135
};
136136

137-
get_enclosing_block(cx, hir_id).map_or(false, |block| {
137+
get_enclosing_block(cx, hir_id).is_some_and(|block| {
138138
visitor.visit_block(block);
139139
visitor.break_after_expr
140140
})

clippy_lints/src/loops/same_item_push.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub(super) fn check<'tcx>(
5050
.tcx
5151
.lang_items()
5252
.clone_trait()
53-
.map_or(false, |id| implements_trait(cx, ty, id, &[]))
53+
.is_some_and(|id| implements_trait(cx, ty, id, &[]))
5454
{
5555
// Make sure that the push does not involve possibly mutating values
5656
match pushed_item.kind {

clippy_lints/src/loops/utils.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,10 @@ impl<'tcx> Visitor<'tcx> for LoopNestVisitor {
312312
/// If `arg` was the argument to a `for` loop, return the "cleanest" way of writing the
313313
/// actual `Iterator` that the loop uses.
314314
pub(super) fn make_iterator_snippet(cx: &LateContext<'_>, arg: &Expr<'_>, applic_ref: &mut Applicability) -> String {
315-
let impls_iterator = cx.tcx.get_diagnostic_item(sym::Iterator).map_or(false, |id| {
316-
implements_trait(cx, cx.typeck_results().expr_ty(arg), id, &[])
317-
});
315+
let impls_iterator = cx
316+
.tcx
317+
.get_diagnostic_item(sym::Iterator)
318+
.is_some_and(|id| implements_trait(cx, cx.typeck_results().expr_ty(arg), id, &[]));
318319
if impls_iterator {
319320
format!(
320321
"{}",

clippy_lints/src/manual_clamp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ impl TypeClampability {
192192
} else if cx
193193
.tcx
194194
.get_diagnostic_item(sym::Ord)
195-
.map_or(false, |id| implements_trait(cx, ty, id, &[]))
195+
.is_some_and(|id| implements_trait(cx, ty, id, &[]))
196196
{
197197
Some(TypeClampability::Ord)
198198
} else {

clippy_lints/src/manual_strip.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ fn eq_pattern_length<'tcx>(cx: &LateContext<'tcx>, pattern: &Expr<'_>, expr: &'t
161161
..
162162
}) = expr.kind
163163
{
164-
constant_length(cx, pattern).map_or(false, |length| *n == length)
164+
constant_length(cx, pattern).is_some_and(|length| *n == length)
165165
} else {
166-
len_arg(cx, expr).map_or(false, |arg| eq_expr_value(cx, pattern, arg))
166+
len_arg(cx, expr).is_some_and(|arg| eq_expr_value(cx, pattern, arg))
167167
}
168168
}
169169

clippy_lints/src/matches/match_like_matches.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ where
7474
&& b0 != b1
7575
&& (first_guard.is_none() || iter.len() == 0)
7676
&& first_attrs.is_empty()
77-
&& iter.all(|arm| find_bool_lit(&arm.2.kind).map_or(false, |b| b == b0) && arm.3.is_none() && arm.0.is_empty())
77+
&& iter.all(|arm| find_bool_lit(&arm.2.kind).is_some_and(|b| b == b0) && arm.3.is_none() && arm.0.is_empty())
7878
{
7979
if let Some(last_pat) = last_pat_opt {
8080
if !is_wild(last_pat) {

0 commit comments

Comments
 (0)