From f6fe6ebc1e2e1e05f6d6462afdd22d22fccae45a Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 11 Sep 2024 10:35:02 +0200 Subject: [PATCH] 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() {} | ^^^^^^^^^^^^^^^^^^^ ``` --- compiler/rustc_builtin_macros/src/test.rs | 2 ++ tests/ui/lint/lint-missing-doc-test.rs | 3 +++ 2 files changed, 5 insertions(+) diff --git a/compiler/rustc_builtin_macros/src/test.rs b/compiler/rustc_builtin_macros/src/test.rs index 1b76a5f3234a2..ab3517d362721 100644 --- a/compiler/rustc_builtin_macros/src/test.rs +++ b/compiler/rustc_builtin_macros/src/test.rs @@ -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( diff --git a/tests/ui/lint/lint-missing-doc-test.rs b/tests/ui/lint/lint-missing-doc-test.rs index 93d4e4a44e928..466b79c0fb949 100644 --- a/tests/ui/lint/lint-missing-doc-test.rs +++ b/tests/ui/lint/lint-missing-doc-test.rs @@ -3,3 +3,6 @@ //@ check-pass //@ compile-flags: --test -Dmissing_docs + +#[test] +fn test() {}