Skip to content

Commit 0fdba39

Browse files
ogoffartshrirambalaji
authored andcommitted
Fix false positive with missing_docs and #[test]
Since rust-lang#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() {} | ^^^^^^^^^^^^^^^^^^^ ```
1 parent e5a0ced commit 0fdba39

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

compiler/rustc_builtin_macros/src/test.rs

+2
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ pub(crate) fn expand_test_or_bench(
277277
cx.attr_nested_word(sym::cfg, sym::test, attr_sp),
278278
// #[rustc_test_marker = "test_case_sort_key"]
279279
cx.attr_name_value_str(sym::rustc_test_marker, test_path_symbol, attr_sp),
280+
// #[allow(missing_docs)]
281+
cx.attr_nested_word(sym::allow, sym::missing_docs, attr_sp),
280282
],
281283
// const $ident: test::TestDescAndFn =
282284
ast::ItemKind::Const(

tests/pretty/tests-are-sorted.pp

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
extern crate test;
1313
#[cfg(test)]
1414
#[rustc_test_marker = "m_test"]
15+
#[allow(missing_docs)]
1516
pub const m_test: test::TestDescAndFn =
1617
test::TestDescAndFn {
1718
desc: test::TestDesc {
@@ -36,6 +37,7 @@
3637
extern crate test;
3738
#[cfg(test)]
3839
#[rustc_test_marker = "z_test"]
40+
#[allow(missing_docs)]
3941
pub const z_test: test::TestDescAndFn =
4042
test::TestDescAndFn {
4143
desc: test::TestDesc {
@@ -61,6 +63,7 @@
6163
extern crate test;
6264
#[cfg(test)]
6365
#[rustc_test_marker = "a_test"]
66+
#[allow(missing_docs)]
6467
pub const a_test: test::TestDescAndFn =
6568
test::TestDescAndFn {
6669
desc: test::TestDesc {

tests/ui/lint/lint-missing-doc-test.rs

+3
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@
33
44
//@ check-pass
55
//@ compile-flags: --test -Dmissing_docs
6+
7+
#[test]
8+
fn test() {}

0 commit comments

Comments
 (0)