Skip to content

Commit 4877263

Browse files
committed
fix all warnings caused by new lint
1 parent 128dcd4 commit 4877263

Some content is hidden

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

66 files changed

+124
-140
lines changed

clippy_dev/src/setup/vscode.rs

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -501,15 +501,15 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
501501
return;
502502
}
503503
if let Some(lint_list) = &attr.meta_item_list() {
504-
if attr.ident().map_or(false, |ident| is_lint_level(ident.name)) {
504+
if attr.ident().is_some_and(|ident| is_lint_level(ident.name)) {
505505
for lint in lint_list {
506506
match item.kind {
507507
ItemKind::Use(..) => {
508508
if is_word(lint, sym::unused_imports)
509509
|| is_word(lint, sym::deprecated)
510510
|| is_word(lint, sym!(unreachable_pub))
511511
|| is_word(lint, sym!(unused))
512-
|| extract_clippy_lint(lint).map_or(false, |s| {
512+
|| extract_clippy_lint(lint).is_some_and(|s| {
513513
matches!(
514514
s.as_str(),
515515
"wildcard_imports"
@@ -715,7 +715,7 @@ fn is_relevant_block(cx: &LateContext<'_>, typeck_results: &ty::TypeckResults<'_
715715
block
716716
.expr
717717
.as_ref()
718-
.map_or(false, |e| is_relevant_expr(cx, typeck_results, e)),
718+
.is_some_and(|e| is_relevant_expr(cx, typeck_results, e)),
719719
|stmt| match &stmt.kind {
720720
StmtKind::Local(_) => true,
721721
StmtKind::Expr(expr) | StmtKind::Semi(expr) => is_relevant_expr(cx, typeck_results, expr),
@@ -725,7 +725,7 @@ fn is_relevant_block(cx: &LateContext<'_>, typeck_results: &ty::TypeckResults<'_
725725
}
726726

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

clippy_lints/src/bool_assert_comparison.rs

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ fn implements_ord(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
492492
let ty = cx.typeck_results().expr_ty(expr);
493493
cx.tcx
494494
.get_diagnostic_item(sym::Ord)
495-
.map_or(false, |id| implements_trait(cx, ty, id, &[]))
495+
.is_some_and(|id| implements_trait(cx, ty, id, &[]))
496496
}
497497

498498
struct NotSimplificationVisitor<'a, 'tcx> {

clippy_lints/src/box_default.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl LateLintPass<'_> for BoxDefault {
4747
&& !in_external_macro(cx.sess(), expr.span)
4848
&& (expr.span.eq_ctxt(arg.span) || is_vec_expn(cx, arg))
4949
&& seg.ident.name == sym::new
50-
&& path_def_id(cx, ty).map_or(false, |id| Some(id) == cx.tcx.lang_items().owned_box())
50+
&& path_def_id(cx, ty).is_some_and(|id| Some(id) == cx.tcx.lang_items().owned_box())
5151
&& is_default_equivalent(cx, arg)
5252
{
5353
span_lint_and_sugg(
@@ -84,7 +84,7 @@ fn is_plain_default(cx: &LateContext<'_>, arg_path: &Expr<'_>) -> bool {
8484
fn is_vec_expn(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
8585
macro_backtrace(expr.span)
8686
.next()
87-
.map_or(false, |call| cx.tcx.is_diagnostic_item(sym::vec_macro, call.def_id))
87+
.is_some_and(|call| cx.tcx.is_diagnostic_item(sym::vec_macro, call.def_id))
8888
}
8989

9090
#[derive(Default)]

clippy_lints/src/casts/unnecessary_cast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ pub(super) fn check<'tcx>(
160160
expr.span,
161161
&format!("casting to the same type is unnecessary (`{cast_from}` -> `{cast_to}`)"),
162162
"try",
163-
if get_parent_expr(cx, expr).map_or(false, |e| matches!(e.kind, ExprKind::AddrOf(..))) {
163+
if get_parent_expr(cx, expr).is_some_and(|e| matches!(e.kind, ExprKind::AddrOf(..))) {
164164
format!("{{ {cast_str} }}")
165165
} else {
166166
cast_str

clippy_lints/src/comparison_chain.rs

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ fn lint_branches_sharing_code<'tcx>(
273273
let span = span.with_hi(last_block.span.hi());
274274
// Improve formatting if the inner block has indention (i.e. normal Rust formatting)
275275
let test_span = Span::new(span.lo() - BytePos(4), span.lo(), span.ctxt(), span.parent());
276-
let span = if snippet_opt(cx, test_span).map_or(false, |snip| snip == " ") {
276+
let span = if snippet_opt(cx, test_span).is_some_and(|snip| snip == " ") {
277277
span.with_lo(test_span.lo())
278278
} else {
279279
span
@@ -354,7 +354,7 @@ fn eq_binding_names(s: &Stmt<'_>, names: &[(HirId, Symbol)]) -> bool {
354354
let mut i = 0usize;
355355
let mut res = true;
356356
l.pat.each_binding_or_first(&mut |_, _, _, name| {
357-
if names.get(i).map_or(false, |&(_, n)| n == name.name) {
357+
if names.get(i).is_some_and(|&(_, n)| n == name.name) {
358358
i += 1;
359359
} else {
360360
res = false;
@@ -398,12 +398,10 @@ fn eq_stmts(
398398
let new_bindings = &moved_bindings[old_count..];
399399
blocks
400400
.iter()
401-
.all(|b| get_stmt(b).map_or(false, |s| eq_binding_names(s, new_bindings)))
401+
.all(|b| get_stmt(b).is_some_and(|s| eq_binding_names(s, new_bindings)))
402402
} else {
403403
true
404-
}) && blocks
405-
.iter()
406-
.all(|b| get_stmt(b).map_or(false, |s| eq.eq_stmt(s, stmt)))
404+
}) && blocks.iter().all(|b| get_stmt(b).is_some_and(|s| eq.eq_stmt(s, stmt)))
407405
}
408406

409407
#[expect(clippy::too_many_lines)]
@@ -460,9 +458,7 @@ fn scan_block_for_eq<'tcx>(
460458
// x + 50
461459
let expr_hash_eq = if let Some(e) = block.expr {
462460
let hash = hash_expr(cx, e);
463-
blocks
464-
.iter()
465-
.all(|b| b.expr.map_or(false, |e| hash_expr(cx, e) == hash))
461+
blocks.iter().all(|b| b.expr.is_some_and(|e| hash_expr(cx, e) == hash))
466462
} else {
467463
blocks.iter().all(|b| b.expr.is_none())
468464
};
@@ -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/default_numeric_fallback.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,6 @@ impl<'tcx> From<Ty<'tcx>> for ExplicitTyBound {
229229

230230
impl<'tcx> From<Option<Ty<'tcx>>> for ExplicitTyBound {
231231
fn from(v: Option<Ty<'tcx>>) -> Self {
232-
Self(v.map_or(false, Ty::is_numeric))
232+
Self(v.is_some_and(Ty::is_numeric))
233233
}
234234
}

clippy_lints/src/derivable_impls.rs

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

0 commit comments

Comments
 (0)