Skip to content

Commit d11b958

Browse files
committed
Fix false positive in string_add.
1 parent 374db5c commit d11b958

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

clippy_lints/src/strings.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ use syntax::source_map::Spanned;
88
use if_chain::if_chain;
99

1010
use crate::utils::SpanlessEq;
11-
use crate::utils::{get_parent_expr, is_allowed, match_type, paths, span_lint, span_lint_and_sugg, walk_ptrs_ty};
11+
use crate::utils::{
12+
get_parent_expr, in_macro, is_allowed, match_type, paths, span_lint, span_lint_and_sugg, walk_ptrs_ty,
13+
};
1214

1315
declare_clippy_lint! {
1416
/// **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]);
8082

8183
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for StringAdd {
8284
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
85+
if in_macro(e.span) {
86+
return;
87+
}
88+
8389
if let ExprKind::Binary(
8490
Spanned {
8591
node: BinOpKind::Add, ..

tests/ui/string_add.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,13 @@ fn main() {
1616
let mut x = 1;
1717
x = x + 1;
1818
assert_eq!(2, x);
19+
20+
macro_rules! mac {
21+
() => {
22+
let y = "".to_owned();
23+
let z = y + "...";
24+
};
25+
}
26+
27+
mac!();
1928
}

0 commit comments

Comments
 (0)