summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/clippy_lints/src/matches/match_as_ref.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/clippy/clippy_lints/src/matches/match_as_ref.rs')
-rw-r--r--src/tools/clippy/clippy_lints/src/matches/match_as_ref.rs43
1 files changed, 20 insertions, 23 deletions
diff --git a/src/tools/clippy/clippy_lints/src/matches/match_as_ref.rs b/src/tools/clippy/clippy_lints/src/matches/match_as_ref.rs
index d51cca040..3f737da92 100644
--- a/src/tools/clippy/clippy_lints/src/matches/match_as_ref.rs
+++ b/src/tools/clippy/clippy_lints/src/matches/match_as_ref.rs
@@ -26,18 +26,16 @@ pub(crate) fn check(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr:
let output_ty = cx.typeck_results().expr_ty(expr);
let input_ty = cx.typeck_results().expr_ty(ex);
- let cast = if_chain! {
- if let ty::Adt(_, args) = input_ty.kind();
- let input_ty = args.type_at(0);
- if let ty::Adt(_, args) = output_ty.kind();
- let output_ty = args.type_at(0);
- if let ty::Ref(_, output_ty, _) = *output_ty.kind();
- if input_ty != output_ty;
- then {
- ".map(|x| x as _)"
- } else {
- ""
- }
+ let cast = if let ty::Adt(_, args) = input_ty.kind()
+ && let input_ty = args.type_at(0)
+ && let ty::Adt(_, args) = output_ty.kind()
+ && let output_ty = args.type_at(0)
+ && let ty::Ref(_, output_ty, _) = *output_ty.kind()
+ && input_ty != output_ty
+ {
+ ".map(|x| x as _)"
+ } else {
+ ""
};
let mut applicability = Applicability::MachineApplicable;
@@ -67,17 +65,16 @@ fn is_none_arm(cx: &LateContext<'_>, arm: &Arm<'_>) -> bool {
// Checks if arm has the form `Some(ref v) => Some(v)` (checks for `ref` and `ref mut`)
fn is_ref_some_arm(cx: &LateContext<'_>, arm: &Arm<'_>) -> Option<Mutability> {
- if_chain! {
- if let PatKind::TupleStruct(ref qpath, [first_pat, ..], _) = arm.pat.kind;
- if is_res_lang_ctor(cx, cx.qpath_res(qpath, arm.pat.hir_id), LangItem::OptionSome);
- if let PatKind::Binding(BindingAnnotation(ByRef::Yes, mutabl), .., ident, _) = first_pat.kind;
- if let ExprKind::Call(e, [arg]) = peel_blocks(arm.body).kind;
- if is_res_lang_ctor(cx, path_res(cx, e), LangItem::OptionSome);
- if let ExprKind::Path(QPath::Resolved(_, path2)) = arg.kind;
- if path2.segments.len() == 1 && ident.name == path2.segments[0].ident.name;
- then {
- return Some(mutabl)
- }
+ if let PatKind::TupleStruct(ref qpath, [first_pat, ..], _) = arm.pat.kind
+ && is_res_lang_ctor(cx, cx.qpath_res(qpath, arm.pat.hir_id), LangItem::OptionSome)
+ && let PatKind::Binding(BindingAnnotation(ByRef::Yes, mutabl), .., ident, _) = first_pat.kind
+ && let ExprKind::Call(e, [arg]) = peel_blocks(arm.body).kind
+ && is_res_lang_ctor(cx, path_res(cx, e), LangItem::OptionSome)
+ && let ExprKind::Path(QPath::Resolved(_, path2)) = arg.kind
+ && path2.segments.len() == 1
+ && ident.name == path2.segments[0].ident.name
+ {
+ return Some(mutabl);
}
None
}