From a1a8627dd789bd7444c78b7a5d360328709a54eb Mon Sep 17 00:00:00 2001 From: Urgau Date: Mon, 9 Sep 2024 13:43:25 +0200 Subject: [PATCH] Allow `missing_docs` lint on the generated test harness --- compiler/rustc_builtin_macros/src/test_harness.rs | 4 +++- compiler/rustc_span/src/symbol.rs | 1 + tests/pretty/tests-are-sorted.pp | 1 + tests/ui/lint/lint-missing-doc-test.rs | 5 +++++ 4 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 tests/ui/lint/lint-missing-doc-test.rs diff --git a/compiler/rustc_builtin_macros/src/test_harness.rs b/compiler/rustc_builtin_macros/src/test_harness.rs index a9e44345811..a694d3b8c28 100644 --- a/compiler/rustc_builtin_macros/src/test_harness.rs +++ b/compiler/rustc_builtin_macros/src/test_harness.rs @@ -326,6 +326,8 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P { let main_attr = ecx.attr_word(sym::rustc_main, sp); // #[coverage(off)] let coverage_attr = ecx.attr_nested_word(sym::coverage, sym::off, sp); + // #[allow(missing_docs)] + let missing_docs_attr = ecx.attr_nested_word(sym::allow, sym::missing_docs, sp); // pub fn main() { ... } let main_ret_ty = ecx.ty(sp, ast::TyKind::Tup(ThinVec::new())); @@ -355,7 +357,7 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P { let main = P(ast::Item { ident: main_id, - attrs: thin_vec![main_attr, coverage_attr], + attrs: thin_vec![main_attr, coverage_attr, missing_docs_attr], id: ast::DUMMY_NODE_ID, kind: main, vis: ast::Visibility { span: sp, kind: ast::VisibilityKind::Public, tokens: None }, diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 36b31d10c4d..db4f44ebcbc 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1235,6 +1235,7 @@ symbols! { mir_unwind_unreachable, mir_variant, miri, + missing_docs, mmx_reg, modifiers, module, diff --git a/tests/pretty/tests-are-sorted.pp b/tests/pretty/tests-are-sorted.pp index 816cd5a5c07..a4b15dde453 100644 --- a/tests/pretty/tests-are-sorted.pp +++ b/tests/pretty/tests-are-sorted.pp @@ -83,6 +83,7 @@ pub const a_test: test::TestDescAndFn = fn a_test() {} #[rustc_main] #[coverage(off)] +#[allow(missing_docs)] pub fn main() -> () { extern crate test; test::test_main_static(&[&a_test, &m_test, &z_test]) diff --git a/tests/ui/lint/lint-missing-doc-test.rs b/tests/ui/lint/lint-missing-doc-test.rs new file mode 100644 index 00000000000..93d4e4a44e9 --- /dev/null +++ b/tests/ui/lint/lint-missing-doc-test.rs @@ -0,0 +1,5 @@ +//! This test checks that denying the missing_docs lint does not trigger +//! on the generated test harness. + +//@ check-pass +//@ compile-flags: --test -Dmissing_docs