Reduce code duplication

This commit is contained in:
Oliver Schneider 2017-05-11 16:37:46 +02:00
parent 8300f0c080
commit 51f6aeae51
No known key found for this signature in database
GPG key ID: A69F8D225B3AD7D9

View 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 {