From 51f6aeae51e220f990799a2f4b377ade40b72a49 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Thu, 11 May 2017 16:37:46 +0200 Subject: [PATCH] Reduce code duplication --- clippy_lints/src/misc.rs | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index c2fc932a6785..3a202c189ec2 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -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 {