about summary refs log tree commit diff
path: root/clippy_lints
diff options
context:
space:
mode:
authorDevin Ragotzy <devin.ragotzy@gmail.com>2021-07-24 07:03:52 -0400
committerDevin Ragotzy <devin.ragotzy@gmail.com>2021-07-24 07:30:22 -0400
commit44d37a44bc9d6382424c903a624080bd8d9fa966 (patch)
tree3e045b22a0fe9d08669e19e1a2752f736006a90b /clippy_lints
parentf5c3ed4463acfcfd014a40f743b0a4863863e0f8 (diff)
downloadrust-44d37a44bc9d6382424c903a624080bd8d9fa966.tar.gz
rust-44d37a44bc9d6382424c903a624080bd8d9fa966.zip
Lint inside macro when owned by current crate
Diffstat (limited to 'clippy_lints')
-rw-r--r--clippy_lints/src/nonstandard_macro_braces.rs9
1 files changed, 8 insertions, 1 deletions
diff --git a/clippy_lints/src/nonstandard_macro_braces.rs b/clippy_lints/src/nonstandard_macro_braces.rs
index 5d6d1018a68..2a318946656 100644
--- a/clippy_lints/src/nonstandard_macro_braces.rs
+++ b/clippy_lints/src/nonstandard_macro_braces.rs
@@ -93,14 +93,21 @@ impl EarlyLintPass for MacroBraces {
 }
 
 fn is_offending_macro<'a>(cx: &EarlyContext<'_>, span: Span, mac_braces: &'a MacroBraces) -> Option<MacroInfo<'a>> {
+    let unnested_or_local = || {
+        let nested = in_macro(span.ctxt().outer_expn_data().call_site);
+        let in_local_macro = nested
+            && matches!(span.macro_backtrace().last().and_then(|e| e.macro_def_id), Some(defid) if defid.is_local());
+        !nested || in_local_macro
+    };
     if_chain! {
         // Make sure we are only one level deep otherwise there are to many FP's
-        if in_macro(span) && !in_macro(span.ctxt().outer_expn_data().call_site);
+        if in_macro(span);
         if let Some((name, braces)) = find_matching_macro(span, &mac_braces.macro_braces);
         if let Some(snip) = snippet_opt(cx, span.ctxt().outer_expn_data().call_site);
         // we must check only invocation sites
         // https://github.com/rust-lang/rust-clippy/issues/7422
         if snip.starts_with(&format!("{}!", name));
+        if unnested_or_local();
         // make formatting consistent
         let c = snip.replace(" ", "");
         if !c.starts_with(&format!("{}!{}", name, braces.0));