Skip to content

Commit

Permalink
Fix false positive with missing_docs and #[test]
Browse files Browse the repository at this point in the history
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() {}
  | ^^^^^^^^^^^^^^^^^^^
```
  • Loading branch information
ogoffart committed Sep 11, 2024
1 parent 4c5fc2c commit 6eddbb7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions compiler/rustc_builtin_macros/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ pub(crate) fn expand_test_or_bench(
cx.attr_nested_word(sym::cfg, sym::test, attr_sp),
// #[rustc_test_marker = "test_case_sort_key"]
cx.attr_name_value_str(sym::rustc_test_marker, test_path_symbol, attr_sp),
// #[allow(missing_docs)]
cx.attr_nested_word(sym::allow, sym::missing_docs, attr_sp),
],
// const $ident: test::TestDescAndFn =
ast::ItemKind::Const(
Expand Down
3 changes: 3 additions & 0 deletions tests/pretty/tests-are-sorted.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
extern crate test;
#[cfg(test)]
#[rustc_test_marker = "m_test"]
#[allow(missing_docs)]
pub const m_test: test::TestDescAndFn =
test::TestDescAndFn {
desc: test::TestDesc {
Expand All @@ -36,6 +37,7 @@
extern crate test;
#[cfg(test)]
#[rustc_test_marker = "z_test"]
#[allow(missing_docs)]
pub const z_test: test::TestDescAndFn =
test::TestDescAndFn {
desc: test::TestDesc {
Expand All @@ -61,6 +63,7 @@
extern crate test;
#[cfg(test)]
#[rustc_test_marker = "a_test"]
#[allow(missing_docs)]
pub const a_test: test::TestDescAndFn =
test::TestDescAndFn {
desc: test::TestDesc {
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/lint/lint-missing-doc-test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@

//@ check-pass
//@ compile-flags: --test -Dmissing_docs

#[test]
fn test() {}

0 comments on commit 6eddbb7

Please sign in to comment.