rust-lang / rust-lang/rust

`unnameable_test_items` does not detect tests in inner modules

Open
#131,364 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-lints C-bug L-unnameable_test_items T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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 9096f4fafa2ac2d771f8)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the example in src/lib.rs on the stable and nightly Rust versions listed, then trace how the unnameable_test_items lint handles #[test] inside nested modules. Add regression coverage for the inner-module case and verify that the compiler emits the cannot test inner items warning at the attribute.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.