From e90a0be923906ded7c79d6168a11b8b68d85fd72 Mon Sep 17 00:00:00 2001
From: Oliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Date: Tue, 17 May 2016 16:34:15 +0200
Subject: [PATCH] simplify `mut_mut` lint

---
 src/mut_mut.rs | 64 ++++++++++++++++++--------------------------------
 1 file changed, 23 insertions(+), 41 deletions(-)

diff --git a/src/mut_mut.rs b/src/mut_mut.rs
index 7b7b5ecdf4e7..4147e288c4f6 100644
--- a/src/mut_mut.rs
+++ b/src/mut_mut.rs
@@ -28,50 +28,32 @@ impl LintPass for MutMut {
 
 impl LateLintPass for MutMut {
     fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
-        check_expr_mut(cx, expr)
-    }
-
-    fn check_ty(&mut self, cx: &LateContext, ty: &Ty) {
-        unwrap_mut(ty).and_then(unwrap_mut).map_or((), |_| {
-            span_lint(cx, MUT_MUT, ty.span, "generally you want to avoid `&mut &mut _` if possible");
-        });
-    }
-}
-
-fn check_expr_mut(cx: &LateContext, expr: &Expr) {
-    fn unwrap_addr(expr: &Expr) -> Option<&Expr> {
-        match expr.node {
-            ExprAddrOf(MutMutable, ref e) => Some(e),
-            _ => None,
+        if in_external_macro(cx, expr.span) {
+            return;
         }
-    }
 
-    if in_external_macro(cx, expr.span) {
-        return;
+        if let ExprAddrOf(MutMutable, ref e) = expr.node {
+            if let ExprAddrOf(MutMutable, _) = e.node {
+                span_lint(cx,
+                          MUT_MUT,
+                          expr.span,
+                          "generally you want to avoid `&mut &mut _` if possible");
+            } else {
+                if let TyRef(_, TypeAndMut { mutbl: MutMutable, .. }) = cx.tcx.expr_ty(e).sty {
+                    span_lint(cx,
+                              MUT_MUT,
+                              expr.span,
+                              "this expression mutably borrows a mutable reference. Consider reborrowing");
+                }
+            }
+        }
     }
 
-    unwrap_addr(expr).map_or((), |e| {
-        unwrap_addr(e).map_or_else(|| {
-                                       if let TyRef(_, TypeAndMut { mutbl: MutMutable, .. }) = cx.tcx.expr_ty(e).sty {
-                                           span_lint(cx,
-                                                     MUT_MUT,
-                                                     expr.span,
-                                                     "this expression mutably borrows a mutable reference. Consider \
-                                                      reborrowing");
-                                       }
-                                   },
-                                   |_| {
-                                       span_lint(cx,
-                                                 MUT_MUT,
-                                                 expr.span,
-                                                 "generally you want to avoid `&mut &mut _` if possible");
-                                   })
-    })
-}
-
-fn unwrap_mut(ty: &Ty) -> Option<&Ty> {
-    match ty.node {
-        TyRptr(_, MutTy { ty: ref pty, mutbl: MutMutable }) => Some(pty),
-        _ => None,
+    fn check_ty(&mut self, cx: &LateContext, ty: &Ty) {
+        if let TyRptr(_, MutTy { ty: ref pty, mutbl: MutMutable }) = ty.node {
+            if let TyRptr(_, MutTy { mutbl: MutMutable, .. }) = pty.node {
+                span_lint(cx, MUT_MUT, ty.span, "generally you want to avoid `&mut &mut _` if possible");
+            }
+        }
     }
 }