Skip to content

Commit 9d6617c

Browse files
committed
Manual collapsing of if and if let expressions containing comments
Those are warned about but not autofixed as the comments inside the `if` conditions would be lost.
1 parent 36c415b commit 9d6617c

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

clippy_lints/src/casts/cast_ptr_alignment.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,15 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) {
1919
cx.typeck_results().expr_ty(expr),
2020
);
2121
lint_cast_ptr_alignment(cx, expr, cast_from, cast_to);
22-
} else if let ExprKind::MethodCall(method_path, self_arg, [], _) = &expr.kind {
23-
if method_path.ident.name.as_str() == "cast"
22+
} else if let ExprKind::MethodCall(method_path, self_arg, [], _) = &expr.kind
23+
&& method_path.ident.name.as_str() == "cast"
2424
&& let Some(generic_args) = method_path.args
2525
&& let [GenericArg::Type(cast_to)] = generic_args.args
2626
// There probably is no obvious reason to do this, just to be consistent with `as` cases.
2727
&& !is_hir_ty_cfg_dependant(cx, cast_to.as_unambig_ty())
28-
{
29-
let (cast_from, cast_to) = (cx.typeck_results().expr_ty(self_arg), cx.typeck_results().expr_ty(expr));
30-
lint_cast_ptr_alignment(cx, expr, cast_from, cast_to);
31-
}
28+
{
29+
let (cast_from, cast_to) = (cx.typeck_results().expr_ty(self_arg), cx.typeck_results().expr_ty(expr));
30+
lint_cast_ptr_alignment(cx, expr, cast_from, cast_to);
3231
}
3332
}
3433

clippy_lints/src/mem_replace.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,14 +305,12 @@ impl<'tcx> LateLintPass<'tcx> for MemReplace {
305305
&& let ExprKind::Path(ref func_qpath) = func.kind
306306
&& let Some(def_id) = cx.qpath_res(func_qpath, func.hir_id).opt_def_id()
307307
&& cx.tcx.is_diagnostic_item(sym::mem_replace, def_id)
308-
{
309308
// Check that second argument is `Option::None`
310-
if !check_replace_option_with_none(cx, src, dest, expr.span)
309+
&& !check_replace_option_with_none(cx, src, dest, expr.span)
311310
&& !check_replace_option_with_some(cx, src, dest, expr.span, &self.msrv)
312311
&& !check_replace_with_default(cx, src, dest, expr, &self.msrv)
313-
{
314-
check_replace_with_uninit(cx, src, dest, expr.span);
315-
}
312+
{
313+
check_replace_with_uninit(cx, src, dest, expr.span);
316314
}
317315
}
318316
extract_msrv_attr!(LateContext);

clippy_lints/src/missing_fields_in_debug.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,11 @@ impl<'tcx> LateLintPass<'tcx> for MissingFieldsInDebug {
224224
// NB: can't call cx.typeck_results() as we are not in a body
225225
&& let typeck_results = cx.tcx.typeck_body(*body_id)
226226
&& should_lint(cx, typeck_results, block)
227-
{
227+
&&
228228
// we intentionally only lint structs, see lint description
229-
if let ItemKind::Struct(data, _) = &self_item.kind {
230-
check_struct(cx, typeck_results, block, self_ty, item, data);
231-
}
229+
let ItemKind::Struct(data, _) = &self_item.kind
230+
{
231+
check_struct(cx, typeck_results, block, self_ty, item, data);
232232
}
233233
}
234234
}

0 commit comments

Comments
 (0)