Skip to content

Commit d25f4be

Browse files
Add regression test for doc_include_without_cfg lint
1 parent 21bab8b commit d25f4be

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#![warn(clippy::doc_include_without_cfg)]
2+
3+
#![cfg_attr(doc, doc = include_str!("../approx_const.rs"))] //~ doc_include_without_cfg
4+
// Should not lint.
5+
#![cfg_attr(feature = "whatever", doc = include_str!("../approx_const.rs"))]
6+
// Should not lint.
7+
#![cfg_attr(doc, doc = include_str!("../approx_const.rs"))]
8+
#![doc = "some doc"]
9+
//! more doc
10+
11+
#[cfg_attr(doc, doc = include_str!("../approx_const.rs"))] //~ doc_include_without_cfg
12+
// Should not lint.
13+
#[cfg_attr(feature = "whatever", doc = include_str!("../approx_const.rs"))]
14+
// Should not lint.
15+
#[cfg_attr(doc, doc = include_str!("../approx_const.rs"))]
16+
#[doc = "some doc"]
17+
/// more doc
18+
fn main() {
19+
// test code goes here
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#![warn(clippy::doc_include_without_cfg)]
2+
3+
#![doc = include_str!("../approx_const.rs")] //~ doc_include_without_cfg
4+
// Should not lint.
5+
#![cfg_attr(feature = "whatever", doc = include_str!("../approx_const.rs"))]
6+
// Should not lint.
7+
#![cfg_attr(doc, doc = include_str!("../approx_const.rs"))]
8+
#![doc = "some doc"]
9+
//! more doc
10+
11+
#[doc = include_str!("../approx_const.rs")] //~ doc_include_without_cfg
12+
// Should not lint.
13+
#[cfg_attr(feature = "whatever", doc = include_str!("../approx_const.rs"))]
14+
// Should not lint.
15+
#[cfg_attr(doc, doc = include_str!("../approx_const.rs"))]
16+
#[doc = "some doc"]
17+
/// more doc
18+
fn main() {
19+
// test code goes here
20+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error: included a file in documentation unconditionally
2+
--> tests/ui/doc/doc_include_without_cfg.rs:3:1
3+
|
4+
LL | #![doc = include_str!("../approx_const.rs")]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `cfg_attr(doc, doc = "...")`: `#![cfg_attr(doc, doc = include_str!("../approx_const.rs"))]`
6+
|
7+
= note: `-D clippy::doc-include-without-cfg` implied by `-D warnings`
8+
= help: to override `-D warnings` add `#[allow(clippy::doc_include_without_cfg)]`
9+
10+
error: included a file in documentation unconditionally
11+
--> tests/ui/doc/doc_include_without_cfg.rs:11:1
12+
|
13+
LL | #[doc = include_str!("../approx_const.rs")]
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `cfg_attr(doc, doc = "...")`: `#[cfg_attr(doc, doc = include_str!("../approx_const.rs"))]`
15+
16+
error: aborting due to 2 previous errors
17+

0 commit comments

Comments
 (0)