Skip to content

unnameable_test_items does not detect tests in inner modules #131364

Open
@kpreid

Description

@kpreid

Code

fn _outer_function() {
    mod tests {
        #[test]
        fn inner_test() {}
    }
}

Current output

warning: function `inner_test` is never used
 --> src/lib.rs:4:12
  |
4 |         fn inner_test() {}
  |            ^^^^^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

Desired output

warning: cannot test inner items
 --> src/lib.rs:3:9
  |
3 |         #[test]
  |         ^^^^^^^
  |
  = note: `#[warn(unnameable_test_items)]` on by default
  = note: this warning originates in the attribute macro `test` (in Nightly builds, run with -Z macro-backtrace for more info)

Rationale and extra context

The desired warning is produced if mod tests is removed so that the inner_test() is directly in the function. The warning should be produced in both cases, since both cases are tests that will not be run.

The warning was last changed in #114414.

Rust Version

Stable 1.81.0 and nightly 1.83.0-nightly (2024-10-05 9096f4f)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.L-unnameable_test_itemsLint: unnameable_test_itemsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions