1
Fork 0

Rollup merge of #130219 - ogoffart:missing-docs-test, r=Urgau

Fix false positive with `missing_docs` and `#[test]`

Since #130025, the compiler don't ignore missing_docs when compiling the tests. But there is now a false positive warning for every `#[test]`

For example, this code
```rust
//! Crate docs

fn just_a_test() {}
```

Would emit this warning when running `cargo test`

```
warning: missing documentation for a constant
 --> src/lib.rs:5:1
  |
4 | #[test]
  | ------- in this procedural macro expansion
5 | fn just_a_test() {}
  | ^^^^^^^^^^^^^^^^^^^
```
This commit is contained in:
Matthias Krüger 2024-09-11 20:04:25 +02:00 committed by GitHub
commit 66727ea1a2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 15 additions and 6 deletions

View file

@ -12,6 +12,7 @@ extern crate std;
extern crate test;
#[cfg(test)]
#[rustc_test_marker = "m_test"]
#[doc(hidden)]
pub const m_test: test::TestDescAndFn =
test::TestDescAndFn {
desc: test::TestDesc {
@ -36,6 +37,7 @@ fn m_test() {}
extern crate test;
#[cfg(test)]
#[rustc_test_marker = "z_test"]
#[doc(hidden)]
pub const z_test: test::TestDescAndFn =
test::TestDescAndFn {
desc: test::TestDesc {
@ -61,6 +63,7 @@ fn z_test() {}
extern crate test;
#[cfg(test)]
#[rustc_test_marker = "a_test"]
#[doc(hidden)]
pub const a_test: test::TestDescAndFn =
test::TestDescAndFn {
desc: test::TestDesc {
@ -83,7 +86,7 @@ pub const a_test: test::TestDescAndFn =
fn a_test() {}
#[rustc_main]
#[coverage(off)]
#[allow(missing_docs)]
#[doc(hidden)]
pub fn main() -> () {
extern crate test;
test::test_main_static(&[&a_test, &m_test, &z_test])

View file

@ -2,4 +2,9 @@
//! on the generated test harness.
//@ check-pass
//@ compile-flags: --test -Dmissing_docs
//@ compile-flags: --test
#![forbid(missing_docs)]
#[test]
fn test() {}