]> git.lizzy.rs Git - rust.git/commitdiff
Reduce code duplication
authorOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Thu, 11 May 2017 14:37:46 +0000 (16:37 +0200)
committerOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Thu, 11 May 2017 17:00:14 +0000 (19:00 +0200)
clippy_lints/src/misc.rs

index c2fc932a67856a2c81bf67fc70f0ee92d555f8b3..3a202c189ec2e123a24bda39fcad6c28725d8f21 100644 (file)
@@ -456,26 +456,16 @@ fn check_to_owned(cx: &LateContext, expr: &Expr, other: &Expr, left: bool, op: S
         return;
     }
 
-    if left {
-        span_lint(cx,
-                  CMP_OWNED,
-                  expr.span,
-                  &format!("this creates an owned instance just for comparison. Consider using `{} {} {}` to \
-                            compare without allocation",
-                           snip,
-                           snippet(cx, op, "=="),
-                           snippet(cx, other.span, "..")));
-    } else {
-        span_lint(cx,
-                  CMP_OWNED,
-                  expr.span,
-                  &format!("this creates an owned instance just for comparison. Consider using `{} {} {}` to \
-                            compare without allocation",
-                           snippet(cx, other.span, ".."),
-                           snippet(cx, op, "=="),
-                           snip));
-    }
-
+    let other = snippet(cx, other.span, "..");
+    let (snip, other) = if left { (snip, other) } else { (other, snip) };
+    span_lint(cx,
+                CMP_OWNED,
+                expr.span,
+                &format!("this creates an owned instance just for comparison. Consider using `{} {} {}` to \
+                        compare without allocation",
+                        snip,
+                        snippet(cx, op, "=="),
+                        other));
 }
 
 fn is_str_arg(cx: &LateContext, args: &[Expr]) -> bool {