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,

0 commit comments

Comments
 (0)