mirror of
https://github.com/rust-lang/rust-clippy
synced 2025-02-17 06:28:42 +00:00
fixed formatting
This commit is contained in:
parent
2d55381a96
commit
f0182ca6c8
1 changed files with 24 additions and 24 deletions
|
@ -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 }
|
||||
|
|
Loading…
Add table
Reference in a new issue