Skip to content

unused_doc_comment doesn't fire on fn-nested doc attributes #158513

Description

@notriddle

Code

pub fn foo() {
    /// nested fn
    pub fn bar() {
    }
    bar();
}

Current output

*nothing*

Desired output

warning: unused doc comment
 --> src/lib.rs:3:3
  |
3 |     /// nested fn
  |     ^^^^^^^^^^^^^
4 |     pub fn bar() {
  |     -------------- rustdoc does not generate documentation for items defined in functions
  |
  = help: use `//` for a plain comment
  = note: `#[warn(unused_doc_comments)]` (part of `#[warn(unused)]`) on by default

Rationale and extra context

The bar function doesn't appear in the generated documentation, even when --document-private-items is passed. That's intentional, and #110422 added code and tests to make it happen.

Other cases

Rust Version

% rustc +dev --version --verbose
rustc 1.98.0-dev
binary: rustc
commit-hash: unknown
commit-date: unknown
host: aarch64-apple-darwin
release: 1.98.0-dev
LLVM version: 22.1.8

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.L-false-negativeLint: False negative (should have fired but didn't).L-unused_doc_commentsLint: unused_doc_commentsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions