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

unnameable_test_items does not detect tests in inner modules #131364

Open
kpreid opened this issue Oct 7, 2024 · 0 comments
Open

unnameable_test_items does not detect tests in inner modules #131364

kpreid opened this issue Oct 7, 2024 · 0 comments
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. L-unnameable_test_items Lint: unnameable_test_items T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@kpreid
Copy link
Contributor

kpreid commented Oct 7, 2024

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)

@kpreid kpreid added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 7, 2024
@jieyouxu jieyouxu added L-unnameable_test_items Lint: unnameable_test_items A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. and removed A-diagnostics Area: Messages for errors, warnings, and lints labels Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. L-unnameable_test_items Lint: unnameable_test_items T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants