Skip to content

Commit 5ff804e

Browse files
committed
misc: move infallible stuff out of the way
1 parent fb82de5 commit 5ff804e

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

clippy_lints/src/matches/match_as_ref.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,18 @@ pub(crate) fn check(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr:
2121
} else {
2222
None
2323
}
24+
&& let output_ty = cx.typeck_results().expr_ty(expr)
25+
&& let input_ty = cx.typeck_results().expr_ty(ex)
26+
&& let Some(input_ty) = option_arg_ty(cx, input_ty)
27+
&& let Some(output_ty) = option_arg_ty(cx, output_ty)
28+
&& let ty::Ref(_, output_ty, _) = *output_ty.kind()
2429
{
2530
let method = match arm_ref_mutbl {
2631
Mutability::Not => "as_ref",
2732
Mutability::Mut => "as_mut",
2833
};
2934

30-
let output_ty = cx.typeck_results().expr_ty(expr);
31-
let input_ty = cx.typeck_results().expr_ty(ex);
32-
33-
let cast = if let Some(input_ty) = option_arg_ty(cx, input_ty)
34-
&& let Some(output_ty) = option_arg_ty(cx, output_ty)
35-
&& let ty::Ref(_, output_ty, _) = *output_ty.kind()
36-
&& input_ty != output_ty
37-
{
38-
".map(|x| x as _)"
39-
} else {
40-
""
41-
};
35+
let cast = if input_ty == output_ty { "" } else { ".map(|x| x as _)" };
4236

4337
let mut applicability = Applicability::MachineApplicable;
4438
span_lint_and_then(

0 commit comments

Comments
 (0)