Skip to content

Commit 0b4c281

Browse files
Rollup merge of rust-lang#130219 - ogoffart:missing-docs-test, r=Urgau
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() {} | ^^^^^^^^^^^^^^^^^^^ ```
2 parents c60f562 + cc34d64 commit 0b4c281

File tree

5 files changed

+15
-6
lines changed

5 files changed

+15
-6
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+
// #[doc(hidden)]
281+
cx.attr_nested_word(sym::doc, sym::hidden, attr_sp),
280282
],
281283
// const $ident: test::TestDescAndFn =
282284
ast::ItemKind::Const(

compiler/rustc_builtin_macros/src/test_harness.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,8 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
326326
let main_attr = ecx.attr_word(sym::rustc_main, sp);
327327
// #[coverage(off)]
328328
let coverage_attr = ecx.attr_nested_word(sym::coverage, sym::off, sp);
329-
// #[allow(missing_docs)]
330-
let missing_docs_attr = ecx.attr_nested_word(sym::allow, sym::missing_docs, sp);
329+
// #[doc(hidden)]
330+
let doc_hidden_attr = ecx.attr_nested_word(sym::doc, sym::hidden, sp);
331331

332332
// pub fn main() { ... }
333333
let main_ret_ty = ecx.ty(sp, ast::TyKind::Tup(ThinVec::new()));
@@ -357,7 +357,7 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
357357

358358
let main = P(ast::Item {
359359
ident: main_id,
360-
attrs: thin_vec![main_attr, coverage_attr, missing_docs_attr],
360+
attrs: thin_vec![main_attr, coverage_attr, doc_hidden_attr],
361361
id: ast::DUMMY_NODE_ID,
362362
kind: main,
363363
vis: ast::Visibility { span: sp, kind: ast::VisibilityKind::Public, tokens: None },

compiler/rustc_span/src/symbol.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,6 @@ symbols! {
12361236
mir_unwind_unreachable,
12371237
mir_variant,
12381238
miri,
1239-
missing_docs,
12401239
mmx_reg,
12411240
modifiers,
12421241
module,

tests/pretty/tests-are-sorted.pp

+4-1
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+
#[doc(hidden)]
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+
#[doc(hidden)]
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+
#[doc(hidden)]
6467
pub const a_test: test::TestDescAndFn =
6568
test::TestDescAndFn {
6669
desc: test::TestDesc {
@@ -83,7 +86,7 @@
8386
fn a_test() {}
8487
#[rustc_main]
8588
#[coverage(off)]
86-
#[allow(missing_docs)]
89+
#[doc(hidden)]
8790
pub fn main() -> () {
8891
extern crate test;
8992
test::test_main_static(&[&a_test, &m_test, &z_test])

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,9 @@
22
//! on the generated test harness.
33
44
//@ check-pass
5-
//@ compile-flags: --test -Dmissing_docs
5+
//@ compile-flags: --test
6+
7+
#![forbid(missing_docs)]
8+
9+
#[test]
10+
fn test() {}

0 commit comments

Comments
 (0)