Fix false positive in string_add.

This commit is contained in:
daxpedda 2019-12-04 21:50:28 +01:00
parent 374db5c0b7
commit d11b958faf
No known key found for this signature in database
GPG Key ID: 43D62A3EA388E46F
2 changed files with 16 additions and 1 deletions

View File

@ -8,7 +8,9 @@ use syntax::source_map::Spanned;
use if_chain::if_chain;
use crate::utils::SpanlessEq;
use crate::utils::{get_parent_expr, is_allowed, match_type, paths, span_lint, span_lint_and_sugg, walk_ptrs_ty};
use crate::utils::{
get_parent_expr, in_macro, is_allowed, match_type, paths, span_lint, span_lint_and_sugg, walk_ptrs_ty,
};
declare_clippy_lint! {
/// **What it does:** Checks for string appends of the form `x = x + y` (without
@ -80,6 +82,10 @@ declare_lint_pass!(StringAdd => [STRING_ADD, STRING_ADD_ASSIGN]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for StringAdd {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
if in_macro(e.span) {
return;
}
if let ExprKind::Binary(
Spanned {
node: BinOpKind::Add, ..

View File

@ -16,4 +16,13 @@ fn main() {
let mut x = 1;
x = x + 1;
assert_eq!(2, x);
macro_rules! mac {
() => {
let y = "".to_owned();
let z = y + "...";
};
}
mac!();
}