fixed formatting

This commit is contained in:
llogiq 2015-08-12 15:57:50 +02:00
parent 2d55381a96
commit f0182ca6c8
1 changed files with 24 additions and 24 deletions

View File

@ -18,9 +18,9 @@ declare_lint! {
}
declare_lint! {
pub STRING_ADD,
Allow,
"Warn on `x + ..` where x is a `String`"
pub STRING_ADD,
Allow,
"Warn on `x + ..` where x is a `String`"
}
#[derive(Copy, Clone)]
@ -32,26 +32,26 @@ impl LintPass for StringAdd {
}
fn check_expr(&mut self, cx: &Context, e: &Expr) {
if let &ExprBinary(Spanned{ node: BiAdd, .. }, ref left, _) = &e.node {
if is_string(cx, left) {
if let Allow = cx.current_level(STRING_ADD_ASSIGN) {
// the string_add_assign is allow, so no duplicates
} else {
let parent = get_parent_expr(cx, e);
if let Some(ref p) = parent {
if let &ExprAssign(ref target, _) = &p.node {
// avoid duplicate matches
if is_exp_equal(target, left) { return; }
}
}
}
//TODO check for duplicates
span_lint(cx, STRING_ADD, e.span,
"you add something to a string. \
Consider using `String::push_str()` instead.")
}
}
}
if let &ExprBinary(Spanned{ node: BiAdd, .. }, ref left, _) = &e.node {
if is_string(cx, left) {
if let Allow = cx.current_level(STRING_ADD_ASSIGN) {
// the string_add_assign is allow, so no duplicates
} else {
let parent = get_parent_expr(cx, e);
if let Some(ref p) = parent {
if let &ExprAssign(ref target, _) = &p.node {
// avoid duplicate matches
if is_exp_equal(target, left) { return; }
}
}
}
//TODO check for duplicates
span_lint(cx, STRING_ADD, e.span,
"you add something to a string. \
Consider using `String::push_str()` instead.")
}
}
}
}
@ -75,7 +75,7 @@ impl LintPass for StringAddAssign {
}
fn is_string(cx: &Context, e: &Expr) -> bool {
let ty = walk_ptrs_ty(cx.tcx.expr_ty(e));
let ty = walk_ptrs_ty(cx.tcx.expr_ty(e));
if let TyStruct(did, _) = ty.sty {
match_def_path(cx, did.did, &["collections", "string", "String"])
} else { false }