Auto merge of #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 https://github.com/rust-lang/rust/issues/130021 try-job: x86_64-gnu-aux
This commit is contained in:
commit
33855f80d4
@ -326,6 +326,8 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
|
|||||||
let main_attr = ecx.attr_word(sym::rustc_main, sp);
|
let main_attr = ecx.attr_word(sym::rustc_main, sp);
|
||||||
// #[coverage(off)]
|
// #[coverage(off)]
|
||||||
let coverage_attr = ecx.attr_nested_word(sym::coverage, sym::off, sp);
|
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() { ... }
|
// pub fn main() { ... }
|
||||||
let main_ret_ty = ecx.ty(sp, ast::TyKind::Tup(ThinVec::new()));
|
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> {
|
|||||||
|
|
||||||
let main = P(ast::Item {
|
let main = P(ast::Item {
|
||||||
ident: main_id,
|
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,
|
id: ast::DUMMY_NODE_ID,
|
||||||
kind: main,
|
kind: main,
|
||||||
vis: ast::Visibility { span: sp, kind: ast::VisibilityKind::Public, tokens: None },
|
vis: ast::Visibility { span: sp, kind: ast::VisibilityKind::Public, tokens: None },
|
||||||
|
@ -426,12 +426,6 @@ impl MissingDoc {
|
|||||||
article: &'static str,
|
article: &'static str,
|
||||||
desc: &'static str,
|
desc: &'static str,
|
||||||
) {
|
) {
|
||||||
// If we're building a test harness, then warning about
|
|
||||||
// documentation is probably not really relevant right now.
|
|
||||||
if cx.sess().opts.test {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Only check publicly-visible items, using the result from the privacy pass.
|
// Only check publicly-visible items, using the result from the privacy pass.
|
||||||
// It's an option so the crate root can also use this function (it doesn't
|
// It's an option so the crate root can also use this function (it doesn't
|
||||||
// have a `NodeId`).
|
// have a `NodeId`).
|
||||||
|
@ -1236,6 +1236,7 @@ symbols! {
|
|||||||
mir_unwind_unreachable,
|
mir_unwind_unreachable,
|
||||||
mir_variant,
|
mir_variant,
|
||||||
miri,
|
miri,
|
||||||
|
missing_docs,
|
||||||
mmx_reg,
|
mmx_reg,
|
||||||
modifiers,
|
modifiers,
|
||||||
module,
|
module,
|
||||||
|
@ -96,6 +96,7 @@ pub(crate) mod hack {
|
|||||||
// We shouldn't add inline attribute to this since this is used in
|
// We shouldn't add inline attribute to this since this is used in
|
||||||
// `vec!` macro mostly and causes perf regression. See #71204 for
|
// `vec!` macro mostly and causes perf regression. See #71204 for
|
||||||
// discussion and perf results.
|
// discussion and perf results.
|
||||||
|
#[allow(missing_docs)]
|
||||||
pub fn into_vec<T, A: Allocator>(b: Box<[T], A>) -> Vec<T, A> {
|
pub fn into_vec<T, A: Allocator>(b: Box<[T], A>) -> Vec<T, A> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let len = b.len();
|
let len = b.len();
|
||||||
@ -105,6 +106,7 @@ pub(crate) mod hack {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(no_global_oom_handling))]
|
#[cfg(not(no_global_oom_handling))]
|
||||||
|
#[allow(missing_docs)]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn to_vec<T: ConvertVec, A: Allocator>(s: &[T], alloc: A) -> Vec<T, A> {
|
pub fn to_vec<T: ConvertVec, A: Allocator>(s: &[T], alloc: A) -> Vec<T, A> {
|
||||||
T::to_vec(s, alloc)
|
T::to_vec(s, alloc)
|
||||||
|
@ -508,6 +508,7 @@ impl String {
|
|||||||
// NB see the slice::hack module in slice.rs for more information
|
// NB see the slice::hack module in slice.rs for more information
|
||||||
#[inline]
|
#[inline]
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
#[allow(missing_docs)]
|
||||||
pub fn from_str(_: &str) -> String {
|
pub fn from_str(_: &str) -> String {
|
||||||
panic!("not available with cfg(test)");
|
panic!("not available with cfg(test)");
|
||||||
}
|
}
|
||||||
|
@ -267,6 +267,7 @@ impl<R: ?Sized> BufReader<R> {
|
|||||||
// This is only used by a test which asserts that the initialization-tracking is correct.
|
// This is only used by a test which asserts that the initialization-tracking is correct.
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
impl<R: ?Sized> BufReader<R> {
|
impl<R: ?Sized> BufReader<R> {
|
||||||
|
#[allow(missing_docs)]
|
||||||
pub fn initialized(&self) -> usize {
|
pub fn initialized(&self) -> usize {
|
||||||
self.buf.initialized()
|
self.buf.initialized()
|
||||||
}
|
}
|
||||||
|
@ -83,6 +83,7 @@ pub const a_test: test::TestDescAndFn =
|
|||||||
fn a_test() {}
|
fn a_test() {}
|
||||||
#[rustc_main]
|
#[rustc_main]
|
||||||
#[coverage(off)]
|
#[coverage(off)]
|
||||||
|
#[allow(missing_docs)]
|
||||||
pub fn main() -> () {
|
pub fn main() -> () {
|
||||||
extern crate test;
|
extern crate test;
|
||||||
test::test_main_static(&[&a_test, &m_test, &z_test])
|
test::test_main_static(&[&a_test, &m_test, &z_test])
|
||||||
|
4
tests/ui/lint/lint-missing-doc-crate.rs
Normal file
4
tests/ui/lint/lint-missing-doc-crate.rs
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
// This test checks that we lint on the crate when it's missing a documentation.
|
||||||
|
//
|
||||||
|
//@ compile-flags: -Dmissing-docs --crate-type=lib
|
||||||
|
//~ ERROR missing documentation for the crate
|
10
tests/ui/lint/lint-missing-doc-crate.stderr
Normal file
10
tests/ui/lint/lint-missing-doc-crate.stderr
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
error: missing documentation for the crate
|
||||||
|
--> $DIR/lint-missing-doc-crate.rs:4:47
|
||||||
|
|
|
||||||
|
LL |
|
||||||
|
| ^
|
||||||
|
|
|
||||||
|
= note: requested on the command line with `-D missing-docs`
|
||||||
|
|
||||||
|
error: aborting due to 1 previous error
|
||||||
|
|
13
tests/ui/lint/lint-missing-doc-expect.rs
Normal file
13
tests/ui/lint/lint-missing-doc-expect.rs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
// Make sure that `#[expect(missing_docs)]` is always correctly fulfilled.
|
||||||
|
|
||||||
|
//@ check-pass
|
||||||
|
//@ revisions: lib bin test
|
||||||
|
//@ [lib]compile-flags: --crate-type lib
|
||||||
|
//@ [bin]compile-flags: --crate-type bin
|
||||||
|
//@ [test]compile-flags: --test
|
||||||
|
|
||||||
|
#[expect(missing_docs)]
|
||||||
|
pub fn foo() {}
|
||||||
|
|
||||||
|
#[cfg(bin)]
|
||||||
|
fn main() {}
|
5
tests/ui/lint/lint-missing-doc-test.rs
Normal file
5
tests/ui/lint/lint-missing-doc-test.rs
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user