Skip to content

Commit

Permalink
Add regression test for doc_include_without_cfg lint
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Oct 29, 2024
1 parent 21bab8b commit d25f4be
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/ui/doc/doc_include_without_cfg.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#![warn(clippy::doc_include_without_cfg)]

#![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"))]
// Should not lint.
#![cfg_attr(doc, doc = include_str!("../approx_const.rs"))]
#![doc = "some doc"]
//! more doc
#[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"))]
// Should not lint.
#[cfg_attr(doc, doc = include_str!("../approx_const.rs"))]
#[doc = "some doc"]
/// more doc
fn main() {
// test code goes here
}
20 changes: 20 additions & 0 deletions tests/ui/doc/doc_include_without_cfg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#![warn(clippy::doc_include_without_cfg)]

#![doc = include_str!("../approx_const.rs")] //~ doc_include_without_cfg
// Should not lint.
#![cfg_attr(feature = "whatever", doc = include_str!("../approx_const.rs"))]
// Should not lint.
#![cfg_attr(doc, doc = include_str!("../approx_const.rs"))]
#![doc = "some doc"]
//! more doc
#[doc = include_str!("../approx_const.rs")] //~ doc_include_without_cfg
// Should not lint.
#[cfg_attr(feature = "whatever", doc = include_str!("../approx_const.rs"))]
// Should not lint.
#[cfg_attr(doc, doc = include_str!("../approx_const.rs"))]
#[doc = "some doc"]
/// more doc
fn main() {
// test code goes here
}
17 changes: 17 additions & 0 deletions tests/ui/doc/doc_include_without_cfg.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error: included a file in documentation unconditionally
--> tests/ui/doc/doc_include_without_cfg.rs:3:1
|
LL | #![doc = include_str!("../approx_const.rs")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `cfg_attr(doc, doc = "...")`: `#![cfg_attr(doc, doc = include_str!("../approx_const.rs"))]`
|
= note: `-D clippy::doc-include-without-cfg` implied by `-D warnings`
= 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
|
LL | #[doc = include_str!("../approx_const.rs")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `cfg_attr(doc, doc = "...")`: `#[cfg_attr(doc, doc = include_str!("../approx_const.rs"))]`

error: aborting due to 2 previous errors

0 comments on commit d25f4be

Please sign in to comment.