Skip to content

Commit

Permalink
Rollup merge of rust-lang#130025 - Urgau:missing_docs-expect, r=petro…
Browse files Browse the repository at this point in the history
…chenkov

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
  • Loading branch information
matthiaskrgr authored Sep 8, 2024
2 parents 2f82550 + ae661dd commit 5f12177
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
15 changes: 4 additions & 11 deletions compiler/rustc_lint/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,12 +426,6 @@ impl MissingDoc {
article: &'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.
// It's an option so the crate root can also use this function (it doesn't
// have a `NodeId`).
Expand All @@ -444,11 +438,10 @@ impl MissingDoc {
let attrs = cx.tcx.hir().attrs(cx.tcx.local_def_id_to_hir_id(def_id));
let has_doc = attrs.iter().any(has_doc);
if !has_doc {
cx.emit_span_lint(
MISSING_DOCS,
cx.tcx.def_span(def_id),
BuiltinMissingDoc { article, desc },
);
let sp = cx.tcx.def_span(def_id);
if !sp.is_dummy() {
cx.emit_span_lint(MISSING_DOCS, sp, BuiltinMissingDoc { article, desc });
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions library/alloc/src/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ pub(crate) mod hack {
// We shouldn't add inline attribute to this since this is used in
// `vec!` macro mostly and causes perf regression. See #71204 for
// discussion and perf results.
#[allow(missing_docs)]
pub fn into_vec<T, A: Allocator>(b: Box<[T], A>) -> Vec<T, A> {
unsafe {
let len = b.len();
Expand All @@ -105,6 +106,7 @@ pub(crate) mod hack {
}

#[cfg(not(no_global_oom_handling))]
#[allow(missing_docs)]
#[inline]
pub fn to_vec<T: ConvertVec, A: Allocator>(s: &[T], alloc: A) -> Vec<T, A> {
T::to_vec(s, alloc)
Expand Down
1 change: 1 addition & 0 deletions library/alloc/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ impl String {
// NB see the slice::hack module in slice.rs for more information
#[inline]
#[cfg(test)]
#[allow(missing_docs)]
pub fn from_str(_: &str) -> String {
panic!("not available with cfg(test)");
}
Expand Down
1 change: 1 addition & 0 deletions library/std/src/io/buffered/bufreader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ impl<R: ?Sized> BufReader<R> {
// This is only used by a test which asserts that the initialization-tracking is correct.
#[cfg(test)]
impl<R: ?Sized> BufReader<R> {
#[allow(missing_docs)]
pub fn initialized(&self) -> usize {
self.buf.initialized()
}
Expand Down
13 changes: 13 additions & 0 deletions tests/ui/lint/lint-missing-doc-expect.rs
Original file line number Diff line number Diff line change
@@ -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() {}

0 comments on commit 5f12177

Please sign in to comment.