Improved suggestion on misrefactored_assign_op lint. Fixes #1239
This commit is contained in:
parent
39d1d6081f
commit
b7cb0752ff
3 changed files with 60 additions and 13 deletions
|
|
@ -87,19 +87,23 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
|
|||
});
|
||||
if let hir::ExprBinary(binop, ref l, ref r) = rhs.node {
|
||||
if op.node == binop.node {
|
||||
let lint = |assignee: &hir::Expr, rhs: &hir::Expr| {
|
||||
let lint = |assignee: &hir::Expr, rhs_other: &hir::Expr| {
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
MISREFACTORED_ASSIGN_OP,
|
||||
expr.span,
|
||||
"variable appears on both sides of an assignment operation",
|
||||
|db| if let (Some(snip_a), Some(snip_r)) =
|
||||
(snippet_opt(cx, assignee.span), snippet_opt(cx, rhs.span))
|
||||
(snippet_opt(cx, assignee.span), snippet_opt(cx, rhs_other.span))
|
||||
{
|
||||
let a = &sugg::Sugg::hir(cx, assignee, "..");
|
||||
let r = &sugg::Sugg::hir(cx, rhs, "..");
|
||||
db.span_suggestion(
|
||||
expr.span,
|
||||
"replace it with",
|
||||
format!("{} {}= {}", snip_a, op.node.as_str(), snip_r),
|
||||
&format!("Did you mean {} = {} {} {} or {} = {}? Consider replacing it with",
|
||||
snip_a, snip_a, op.node.as_str(), snip_r,
|
||||
snip_a, sugg::make_binop(higher::binop(op.node), a, r)),
|
||||
format!("{} {}= {}", snip_a, op.node.as_str(), snip_r)
|
||||
);
|
||||
},
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue