Skip to content
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

missing_docs_in_private_items requiring docs on function-local items #13802

Closed
connortsui20 opened this issue Dec 9, 2024 · 1 comment
Closed
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

@connortsui20
Copy link

Summary

When turning on the missing_docs_in_private_items lint, items that exist within a function get caught for not having documentation comments, even though adding doc comments there would not emit any documentation anyways. I've seen that this is true for inner functions and macros, and it is probably true for all items that can be declared within a function.

I feel it doesn't make too much sense to require doc comments there since I don't think there is a way to even view them via cargo doc.

Lint Name

missing_docs_in_private_items

Reproducer

I tried this code:

//! Crate-level docs.

#![warn(clippy::missing_docs_in_private_items)]

/// Example docs.
pub fn example() {
    // Normal comments should be sufficient as doc comments won't get emitted anyways?
    fn private_fn() -> i32 {
        2 + 2
    }

    assert_eq!(private_fn(), 4);
    println!("Hello, world!");
}

I saw this happen:

❯ cargo clippy
warning: missing documentation for a function
  --> src/lib.rs:8:5
   |
8  | /     fn private_fn() -> i32 {
9  | |         2 + 2
10 | |     }
   | |_____^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_docs_in_private_items
note: the lint level is defined here
  --> src/lib.rs:3:9
   |
3  | #![warn(clippy::missing_docs_in_private_items)]
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I expected to see no clippy warning.

Version

rustc 1.83.0 (90b35a623 2024-11-26)
binary: rustc
commit-hash: 90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf
commit-date: 2024-11-26
host: x86_64-unknown-linux-gnu
release: 1.83.0
LLVM version: 19.1.1

Additional Labels

No response

@connortsui20 connortsui20 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 Dec 9, 2024
@y21
Copy link
Member

y21 commented Dec 9, 2024

#13573 fixed this (no warning on nightly & beta), so the fix should be in the next release 1.84.0 (9th January)

it is probably true for all items that can be declared within a function

For what it's worth, impl trait blocks can be declared within functions and their documentation is visible, but my fix also stopped linting them because rustc will warn you to not do that anyway (non_local_definitions lint)

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