1
Fork 0

Use span_lint_and_sugg

This commit is contained in:
Seo Sanghyeon 2017-06-22 03:04:04 +09:00
parent 88101d5b78
commit 745233f3ab
12 changed files with 91 additions and 122 deletions

View file

@ -1,6 +1,6 @@
use syntax::ast::{Expr, ExprKind, UnOp};
use rustc::lint::*;
use utils::{span_lint_and_then, snippet};
use utils::{span_lint_and_sugg, snippet};
/// **What it does:** Checks for usage of `*&` and `*&mut` in expressions.
///
@ -40,9 +40,8 @@ impl EarlyLintPass for Pass {
fn check_expr(&mut self, cx: &EarlyContext, e: &Expr) {
if let ExprKind::Unary(UnOp::Deref, ref deref_target) = e.node {
if let ExprKind::AddrOf(_, ref addrof_target) = without_parens(deref_target).node {
span_lint_and_then(cx, DEREF_ADDROF, e.span, "immediately dereferencing a reference", |db| {
db.span_suggestion(e.span, "try this", format!("{}", snippet(cx, addrof_target.span, "_")));
});
span_lint_and_sugg(cx, DEREF_ADDROF, e.span, "immediately dereferencing a reference",
"try this", format!("{}", snippet(cx, addrof_target.span, "_")));
}
}
}