Skip to content

Commit 1bf4600

Browse files
committed
Enable useless_let_if_seq
1 parent ef8ed88 commit 1bf4600

File tree

7 files changed

+23
-22
lines changed

7 files changed

+23
-22
lines changed

clippy_lints/src/loops/never_loop.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,14 @@ pub(super) fn check<'tcx>(
3737
{
3838
// If the block contains a break or continue, or if the loop has a label, `MachineApplicable` is not
3939
// appropriate.
40-
let mut app = if !contains_any_break_or_continue(block) && label.is_none() {
40+
let app = if !contains_any_break_or_continue(block) && label.is_none() {
4141
Applicability::MachineApplicable
42+
} else if !never_spans.is_empty() {
43+
Applicability::HasPlaceholders
4244
} else {
4345
Applicability::Unspecified
4446
};
4547

46-
if !never_spans.is_empty() {
47-
app = Applicability::HasPlaceholders;
48-
}
49-
5048
let mut suggestions = vec![(
5149
for_span.with_hi(iterator.span.hi()),
5250
for_to_if_let_sugg(cx, iterator, pat),

clippy_lints/src/matches/match_like_matches.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,14 @@ where
113113
};
114114

115115
// strip potential borrows (#6503), but only if the type is a reference
116-
let mut ex_new = ex;
117-
if let ExprKind::AddrOf(BorrowKind::Ref, .., ex_inner) = ex.kind
116+
let ex_new = if let ExprKind::AddrOf(BorrowKind::Ref, .., ex_inner) = ex.kind
118117
&& let ty::Ref(..) = cx.typeck_results().expr_ty(ex_inner).kind()
119118
{
120-
ex_new = ex_inner;
121-
}
119+
ex_inner
120+
} else {
121+
ex
122+
};
123+
122124
span_lint_and_sugg(
123125
cx,
124126
MATCH_LIKE_MATCHES_MACRO,

clippy_lints/src/needless_for_each.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessForEach {
7676
// and suggesting `for … in … { unsafe { } }` is a little ugly.
7777
&& !matches!(body.value.kind, ExprKind::Block(Block { rules: BlockCheckMode::UnsafeBlock(_), .. }, ..))
7878
{
79+
#[expect(clippy::useless_let_if_seq, reason = "suggestion is less readable")]
7980
let mut applicability = Applicability::MachineApplicable;
8081

8182
// If any closure parameter has an explicit type specified, applying the lint would necessarily

clippy_lints/src/operators/cmp_owned.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ fn check_op(cx: &LateContext<'_>, expr: &Expr<'_>, other: &Expr<'_>, left: bool)
9393

9494
let arg_snip = snippet(cx, arg_span, "..");
9595
let expr_snip;
96+
#[expect(clippy::useless_let_if_seq, reason = "too complicated to fix")]
9697
let eq_impl;
9798
if with_deref.is_implemented() && !arg_ty.peel_refs().is_str() {
9899
expr_snip = format!("*{arg_snip}");

clippy_lints/src/redundant_type_annotations.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,12 @@ impl LateLintPass<'_> for RedundantTypeAnnotations {
151151
}
152152
},
153153
hir::ExprKind::MethodCall(_, _, _, _) => {
154-
let mut is_ref = false;
155-
let mut ty_kind = &ty.kind;
156-
157154
// If the annotation is a ref we "peel" it
158-
if let hir::TyKind::Ref(_, mut_ty) = &ty.kind {
159-
is_ref = true;
160-
ty_kind = &mut_ty.ty.kind;
161-
}
155+
let (is_ref, ty_kind) = if let hir::TyKind::Ref(_, mut_ty) = &ty.kind {
156+
(true, &mut_ty.ty.kind)
157+
} else {
158+
(false, &ty.kind)
159+
};
162160

163161
if let hir::TyKind::Path(ty_path) = ty_kind
164162
&& let hir::QPath::Resolved(_, resolved_path_ty) = ty_path

tests/compile-test.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -356,14 +356,13 @@ fn main() {
356356
_ => panic!("unknown speedtest: {speedtest} || accepted speedtests are: [ui, cargo, toml, internal]"),
357357
};
358358

359-
let iterations;
360-
if let Ok(iterations_str) = std::env::var("SPEEDTEST_ITERATIONS") {
361-
iterations = iterations_str
359+
let iterations = if let Ok(iterations_str) = std::env::var("SPEEDTEST_ITERATIONS") {
360+
iterations_str
362361
.parse::<u64>()
363-
.unwrap_or_else(|_| panic!("Couldn't parse `{iterations_str}`, please use a valid u64"));
362+
.unwrap_or_else(|_| panic!("Couldn't parse `{iterations_str}`, please use a valid u64"))
364363
} else {
365-
iterations = 1000;
366-
}
364+
1000
365+
};
367366

368367
let mut sum = 0;
369368
for _ in 0..iterations {

tests/dogfood.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ fn run_clippy_for_package(project: &str) -> bool {
103103
"clippy::significant_drop_tightening",
104104
"-D",
105105
"clippy::tuple_array_conversions",
106+
"-D",
107+
"clippy::useless_let_if_seq",
106108
]);
107109
if !cfg!(feature = "internal") {
108110
// running a clippy built without internal lints on the clippy source

0 commit comments

Comments
 (0)