Skip to content

Commit 42cba02

Browse files
Add regression test for doc_include_without_cfg lint
1 parent 3c7dbb9 commit 42cba02

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#![warn(clippy::doc_include_without_cfg)]
2+
// Should not lint.
3+
#![doc(html_playground_url = "https://playground.example.com/")]
4+
#![cfg_attr(doc, doc = include_str!("../approx_const.rs"))] //~ doc_include_without_cfg
5+
// Should not lint.
6+
#![cfg_attr(feature = "whatever", doc = include_str!("../approx_const.rs"))]
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+
#[cfg_attr(doc, doc = include_str!("../approx_const.rs"))]
15+
#[doc = "some doc"]
16+
/// more doc
17+
fn main() {
18+
// test code goes here
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#![warn(clippy::doc_include_without_cfg)]
2+
// Should not lint.
3+
#![doc(html_playground_url = "https://playground.example.com/")]
4+
#![doc = include_str!("../approx_const.rs")] //~ doc_include_without_cfg
5+
// Should not lint.
6+
#![cfg_attr(feature = "whatever", doc = include_str!("../approx_const.rs"))]
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+
#[cfg_attr(doc, doc = include_str!("../approx_const.rs"))]
15+
#[doc = "some doc"]
16+
/// more doc
17+
fn main() {
18+
// test code goes here
19+
}
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:4: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+

tests/ui/missing_doc_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![warn(clippy::missing_docs_in_private_items)]
2+
#![allow(clippy::doc_include_without_cfg)]
23
#![doc = include_str!("../../README.md")]
34

45
fn main() {}

0 commit comments

Comments
 (0)