Skip to content

Commit 33855f8

Browse files
committed
Auto merge of rust-lang#130025 - Urgau:missing_docs-expect, r=petrochenkov
Also emit `missing_docs` lint with `--test` to fulfil expectations This PR removes the "test harness" suppression of the `missing_docs` lint to be able to fulfil `#[expect]` (expectations) as it is now "relevant". I think the goal was to maybe avoid false-positive while linting on public items under `#[cfg(test)]` but with effective visibility we should no longer have any false-positive. Another possibility would be to query the lint level and only emit the lint if it's of expect level, but that is even more hacky. Fixes rust-lang#130021 try-job: x86_64-gnu-aux
2 parents f827364 + 0f9cb07 commit 33855f8

File tree

11 files changed

+41
-7
lines changed

11 files changed

+41
-7
lines changed

Diff for: compiler/rustc_builtin_macros/src/test_harness.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -326,6 +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);
329331

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

356358
let main = P(ast::Item {
357359
ident: main_id,
358-
attrs: thin_vec![main_attr, coverage_attr],
360+
attrs: thin_vec![main_attr, coverage_attr, missing_docs_attr],
359361
id: ast::DUMMY_NODE_ID,
360362
kind: main,
361363
vis: ast::Visibility { span: sp, kind: ast::VisibilityKind::Public, tokens: None },

Diff for: compiler/rustc_lint/src/builtin.rs

-6
Original file line numberDiff line numberDiff line change
@@ -426,12 +426,6 @@ impl MissingDoc {
426426
article: &'static str,
427427
desc: &'static str,
428428
) {
429-
// If we're building a test harness, then warning about
430-
// documentation is probably not really relevant right now.
431-
if cx.sess().opts.test {
432-
return;
433-
}
434-
435429
// Only check publicly-visible items, using the result from the privacy pass.
436430
// It's an option so the crate root can also use this function (it doesn't
437431
// have a `NodeId`).

Diff for: compiler/rustc_span/src/symbol.rs

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

Diff for: library/alloc/src/slice.rs

+2
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ pub(crate) mod hack {
9696
// We shouldn't add inline attribute to this since this is used in
9797
// `vec!` macro mostly and causes perf regression. See #71204 for
9898
// discussion and perf results.
99+
#[allow(missing_docs)]
99100
pub fn into_vec<T, A: Allocator>(b: Box<[T], A>) -> Vec<T, A> {
100101
unsafe {
101102
let len = b.len();
@@ -105,6 +106,7 @@ pub(crate) mod hack {
105106
}
106107

107108
#[cfg(not(no_global_oom_handling))]
109+
#[allow(missing_docs)]
108110
#[inline]
109111
pub fn to_vec<T: ConvertVec, A: Allocator>(s: &[T], alloc: A) -> Vec<T, A> {
110112
T::to_vec(s, alloc)

Diff for: library/alloc/src/string.rs

+1
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ impl String {
508508
// NB see the slice::hack module in slice.rs for more information
509509
#[inline]
510510
#[cfg(test)]
511+
#[allow(missing_docs)]
511512
pub fn from_str(_: &str) -> String {
512513
panic!("not available with cfg(test)");
513514
}

Diff for: library/std/src/io/buffered/bufreader.rs

+1
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ impl<R: ?Sized> BufReader<R> {
267267
// This is only used by a test which asserts that the initialization-tracking is correct.
268268
#[cfg(test)]
269269
impl<R: ?Sized> BufReader<R> {
270+
#[allow(missing_docs)]
270271
pub fn initialized(&self) -> usize {
271272
self.buf.initialized()
272273
}

Diff for: tests/pretty/tests-are-sorted.pp

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
fn a_test() {}
8484
#[rustc_main]
8585
#[coverage(off)]
86+
#[allow(missing_docs)]
8687
pub fn main() -> () {
8788
extern crate test;
8889
test::test_main_static(&[&a_test, &m_test, &z_test])

Diff for: tests/ui/lint/lint-missing-doc-crate.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// This test checks that we lint on the crate when it's missing a documentation.
2+
//
3+
//@ compile-flags: -Dmissing-docs --crate-type=lib
4+
//~ ERROR missing documentation for the crate

Diff for: tests/ui/lint/lint-missing-doc-crate.stderr

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: missing documentation for the crate
2+
--> $DIR/lint-missing-doc-crate.rs:4:47
3+
|
4+
LL |
5+
| ^
6+
|
7+
= note: requested on the command line with `-D missing-docs`
8+
9+
error: aborting due to 1 previous error
10+

Diff for: tests/ui/lint/lint-missing-doc-expect.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Make sure that `#[expect(missing_docs)]` is always correctly fulfilled.
2+
3+
//@ check-pass
4+
//@ revisions: lib bin test
5+
//@ [lib]compile-flags: --crate-type lib
6+
//@ [bin]compile-flags: --crate-type bin
7+
//@ [test]compile-flags: --test
8+
9+
#[expect(missing_docs)]
10+
pub fn foo() {}
11+
12+
#[cfg(bin)]
13+
fn main() {}

Diff for: tests/ui/lint/lint-missing-doc-test.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//! This test checks that denying the missing_docs lint does not trigger
2+
//! on the generated test harness.
3+
4+
//@ check-pass
5+
//@ compile-flags: --test -Dmissing_docs

0 commit comments

Comments
 (0)