get snippets inside the suggestions-closure

This commit is contained in:
Oliver Schneider
2016-07-20 13:29:01 +02:00
parent e3559ec4fc
commit 3ea9a249bc

View File

@@ -1,6 +1,6 @@
use rustc::hir; use rustc::hir;
use rustc::lint::*; use rustc::lint::*;
use utils::{span_lint_and_then, span_lint, snippet_opt, SpanlessEq, get_trait_def_id, implements_trait}; use utils::{span_lint_and_then, snippet_opt, SpanlessEq, get_trait_def_id, implements_trait};
use utils::{higher, sugg}; use utils::{higher, sugg};
/// **What it does:** This lint checks for `+=` operations and similar. /// **What it does:** This lint checks for `+=` operations and similar.
@@ -104,23 +104,18 @@ impl LateLintPass for AssignOps {
BitXor: BiBitXor, BitXor: BiBitXor,
Shr: BiShr, Shr: BiShr,
Shl: BiShl) { Shl: BiShl) {
if let (Some(snip_a), Some(snip_r)) = (snippet_opt(cx, assignee.span), span_lint_and_then(cx,
snippet_opt(cx, rhs.span)) { ASSIGN_OP_PATTERN,
span_lint_and_then(cx, expr.span,
ASSIGN_OP_PATTERN, "manual implementation of an assign operation",
expr.span, |db| {
"manual implementation of an assign operation", if let (Some(snip_a), Some(snip_r)) = (snippet_opt(cx, assignee.span),
|db| { snippet_opt(cx, rhs.span)) {
db.span_suggestion(expr.span, db.span_suggestion(expr.span,
"replace it with", "replace it with",
format!("{} {}= {}", snip_a, op.node.as_str(), snip_r)); format!("{} {}= {}", snip_a, op.node.as_str(), snip_r));
}); }
} else { });
span_lint(cx,
ASSIGN_OP_PATTERN,
expr.span,
"manual implementation of an assign operation");
}
} }
}; };
// a = a op b // a = a op b