diff --git a/clippy_lints/src/doc/include_in_doc_without_cfg.rs b/clippy_lints/src/doc/include_in_doc_without_cfg.rs index f8b9d316b832..0f490eb09e3c 100644 --- a/clippy_lints/src/doc/include_in_doc_without_cfg.rs +++ b/clippy_lints/src/doc/include_in_doc_without_cfg.rs @@ -9,7 +9,8 @@ use super::DOC_INCLUDE_WITHOUT_CFG; pub fn check(cx: &LateContext<'_>, attrs: &[Attribute]) { for attr in attrs { - if let AttrKind::Normal(ref normal) = attr.kind + if !attr.span.from_expansion() + && let AttrKind::Normal(ref normal) = attr.kind && normal.item.path == sym::doc && let AttrArgs::Eq(_, AttrArgsEq::Hir(ref meta)) = normal.item.args && !attr.span.contains(meta.span) diff --git a/tests/ui/doc/doc_include_without_cfg.fixed b/tests/ui/doc/doc_include_without_cfg.fixed index e9db318b7f44..74378808b077 100644 --- a/tests/ui/doc/doc_include_without_cfg.fixed +++ b/tests/ui/doc/doc_include_without_cfg.fixed @@ -8,6 +8,20 @@ #![doc = "some doc"] //! more doc +// Should not lint! +macro_rules! tst { + ($(#[$attr:meta])*) => { + $(#[$attr])* + fn blue() { + println!("Hello, world!"); + } + } +} + +tst! { + /// This is a test with no included file +} + #[cfg_attr(doc, doc = include_str!("../approx_const.rs"))] //~ doc_include_without_cfg // Should not lint. #[cfg_attr(feature = "whatever", doc = include_str!("../approx_const.rs"))] diff --git a/tests/ui/doc/doc_include_without_cfg.rs b/tests/ui/doc/doc_include_without_cfg.rs index 306a32743016..8a042a7f7a2e 100644 --- a/tests/ui/doc/doc_include_without_cfg.rs +++ b/tests/ui/doc/doc_include_without_cfg.rs @@ -8,6 +8,20 @@ #![doc = "some doc"] //! more doc +// Should not lint! +macro_rules! tst { + ($(#[$attr:meta])*) => { + $(#[$attr])* + fn blue() { + println!("Hello, world!"); + } + } +} + +tst! { + /// This is a test with no included file +} + #[doc = include_str!("../approx_const.rs")] //~ doc_include_without_cfg // Should not lint. #[cfg_attr(feature = "whatever", doc = include_str!("../approx_const.rs"))] diff --git a/tests/ui/doc/doc_include_without_cfg.stderr b/tests/ui/doc/doc_include_without_cfg.stderr index 46152eee5558..b53e4a0737f7 100644 --- a/tests/ui/doc/doc_include_without_cfg.stderr +++ b/tests/ui/doc/doc_include_without_cfg.stderr @@ -8,7 +8,7 @@ LL | #![doc = include_str!("../approx_const.rs")] = help: to override `-D warnings` add `#[allow(clippy::doc_include_without_cfg)]` error: included a file in documentation unconditionally - --> tests/ui/doc/doc_include_without_cfg.rs:11:1 + --> tests/ui/doc/doc_include_without_cfg.rs:25:1 | LL | #[doc = include_str!("../approx_const.rs")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `cfg_attr(doc, doc = "...")`: `#[cfg_attr(doc, doc = include_str!("../approx_const.rs"))]`