From d11b958faf4e1b9fe791eff9485a4abec28ca541 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Wed, 4 Dec 2019 21:50:28 +0100 Subject: [PATCH] Fix false positive in `string_add`. --- clippy_lints/src/strings.rs | 8 +++++++- tests/ui/string_add.rs | 9 +++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/strings.rs b/clippy_lints/src/strings.rs index 5261d858566..c1d441c3935 100644 --- a/clippy_lints/src/strings.rs +++ b/clippy_lints/src/strings.rs @@ -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, .. diff --git a/tests/ui/string_add.rs b/tests/ui/string_add.rs index c9dd13eea8a..55f44432bb2 100644 --- a/tests/ui/string_add.rs +++ b/tests/ui/string_add.rs @@ -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!(); }