Skip to content

missing_panics_doc with check-private-items should not trigger on tests #12265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jwodder opened this issue Feb 10, 2024 · 2 comments
Open
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@jwodder
Copy link

jwodder commented Feb 10, 2024

Summary

When the missing_panics_doc lint is set to "warn" or "deny" and clippy.toml contains "check-private-items = true", then the lint will warn/deny about assert!(), unwrap(), etc. in #[test] functions that lack "Panics" docs, even though there is no need for test functions to have "Panics" docs.

Lint Name

missing_panics_doc

Reproducer

I tried this code:

pub fn add(left: usize, right: usize) -> usize {
    left + right
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn it_works() {
        let result = add(2, 2);
        assert_eq!(result, 4);
    }
}

with this [lints] block in Cargo.toml:

[lints.clippy]
missing_panics_doc = "deny"

and this clippy.toml:

check-private-items = true

I saw this happen:

    Checking missing-panic v0.1.0 (/Users/jwodder/work/dev/tmp/missing-panic)
error: docs for function which may panic missing `# Panics` section
  --> src/lib.rs:10:5
   |
10 |     fn it_works() {
   |     ^^^^^^^^^^^^^
   |
note: first possible panic found here
  --> src/lib.rs:12:9
   |
12 |         assert_eq!(result, 4);
   |         ^^^^^^^^^^^^^^^^^^^^^
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_panics_doc
   = note: requested on the command line with `-D clippy::missing-panics-doc`

error: could not compile `missing-panic` (lib test) due to 1 previous error

I expected to see this happen: [no lints]

Version

rustc 1.76.0 (07dca489a 2024-02-04)
binary: rustc
commit-hash: 07dca489ac2d933c78d3c5158e3f43beefeb02ce
commit-date: 2024-02-04
host: x86_64-apple-darwin
release: 1.76.0
LLVM version: 17.0.6

Additional Labels

No response

@jwodder jwodder added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Feb 10, 2024
@alex-semenyuk
Copy link
Member

Seems not an issue on version 0.1.80

@jwodder
Copy link
Author

jwodder commented Dec 20, 2024

This is still happening with Rust 1.83.0. Note that you have to run cargo clippy --all-targets, not just cargo clippy, in order for clippy to lint the test function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

No branches or pull requests

2 participants