Skip to content

Commit 5111470

Browse files
Do not emit include_in_doc_without_cfg inside macros
1 parent fbf36cc commit 5111470

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

clippy_lints/src/doc/include_in_doc_without_cfg.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ use super::DOC_INCLUDE_WITHOUT_CFG;
99

1010
pub fn check(cx: &LateContext<'_>, attrs: &[Attribute]) {
1111
for attr in attrs {
12-
if let AttrKind::Normal(ref normal) = attr.kind
12+
if !attr.span.from_expansion()
13+
&& let AttrKind::Normal(ref normal) = attr.kind
1314
&& normal.item.path == sym::doc
1415
&& let AttrArgs::Eq(_, AttrArgsEq::Hir(ref meta)) = normal.item.args
1516
&& !attr.span.contains(meta.span)

tests/ui/doc/doc_include_without_cfg.fixed

+14
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@
88
#![doc = "some doc"]
99
//! more doc
1010

11+
// Should not lint!
12+
macro_rules! tst {
13+
($(#[$attr:meta])*) => {
14+
$(#[$attr])*
15+
fn blue() {
16+
println!("Hello, world!");
17+
}
18+
}
19+
}
20+
21+
tst! {
22+
/// This is a test with no included file
23+
}
24+
1125
#[cfg_attr(doc, doc = include_str!("../approx_const.rs"))] //~ doc_include_without_cfg
1226
// Should not lint.
1327
#[cfg_attr(feature = "whatever", doc = include_str!("../approx_const.rs"))]

tests/ui/doc/doc_include_without_cfg.rs

+14
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@
88
#![doc = "some doc"]
99
//! more doc
1010
11+
// Should not lint!
12+
macro_rules! tst {
13+
($(#[$attr:meta])*) => {
14+
$(#[$attr])*
15+
fn blue() {
16+
println!("Hello, world!");
17+
}
18+
}
19+
}
20+
21+
tst! {
22+
/// This is a test with no included file
23+
}
24+
1125
#[doc = include_str!("../approx_const.rs")] //~ doc_include_without_cfg
1226
// Should not lint.
1327
#[cfg_attr(feature = "whatever", doc = include_str!("../approx_const.rs"))]

tests/ui/doc/doc_include_without_cfg.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LL | #![doc = include_str!("../approx_const.rs")]
88
= help: to override `-D warnings` add `#[allow(clippy::doc_include_without_cfg)]`
99

1010
error: included a file in documentation unconditionally
11-
--> tests/ui/doc/doc_include_without_cfg.rs:11:1
11+
--> tests/ui/doc/doc_include_without_cfg.rs:25:1
1212
|
1313
LL | #[doc = include_str!("../approx_const.rs")]
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `cfg_attr(doc, doc = "...")`: `#[cfg_attr(doc, doc = include_str!("../approx_const.rs"))]`

0 commit comments

Comments
 (0)