Skip to content

Add empty_test lint - #17626

Open
willwang-io wants to merge 2 commits into
rust-lang:masterfrom
willwang-io:empty-test
Open

Add empty_test lint#17626
willwang-io wants to merge 2 commits into
rust-lang:masterfrom
willwang-io:empty-test

Conversation

@willwang-io

@willwang-io willwang-io commented Aug 24, 2026

Copy link
Copy Markdown

Fixes #17488

Empty test functions pass automatically without asserting behavior, which can give a false sense of coverage. This adds empty_test, a suspicious lint that detects test functions with empty bodies.

changelog: [empty_test]: add a suspicious lint for test functions with empty bodies

  • Followed lint naming conventions
  • Added passing UI tests, including the .stderr file
  • cargo test passes locally
  • Executed cargo dev update_lints
  • Added lint documentation
  • Ran cargo dev fmt

@rustbot rustbot added the S-waiting-on-community-reviews Status: This is awaiting for positive reviews from the community before a maintainer is assigned. label Aug 24, 2026
@rustbot

rustbot commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome!

You should hear from one of our reviewers after this PR gets at least 2 reviews from the community.

Please see the contribution instructions for more information.

@rustbot rustbot added needs-fcp PRs that add, remove, or rename lints and need an FCP S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Aug 24, 2026
@rustbot

rustbot commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

Empty test functions execute no test code and cannot verify behaviour.
Provide an opt-in restriction lint so projects can detect these no-op
tests while allowing temporary placeholders where appropriate.

@CommanderStorm CommanderStorm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Community review

From the issue:

This can be a more general lint for tests which can never fail or always fail. Empty tests aren't particularly unique other than being the degenerate case.

I think you missed this part.
the lint I guess can start out with only linting for the degenerate case, but it should have the ambition to also lint for the provably true/false cases..

🤔
unless..
Actually I think type tests (where you ensure that for example a types size always is below a cache line for perf) cannot happen.
But that sounds a bit like an edge case
CC @Jarcho if that would be something where a "false positive" (is it one?) is good or bad?

View changes since this review

Comment thread clippy_lints/src/empty_test.rs
Comment thread clippy_lints/src/empty_test.rs Outdated
Comment on lines +13 to +16
LL | / fn empty_with_comment() {
LL | | // This is still an empty body.
LL | | }
| |_^

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be very nice to get the #[test] attr into this span, but that sounds like some work, so this is also fine likely.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I agree that including #[test] in the span would make the diagnostic clearer. I looked into it, but it seems that #[test] has already been expanded by the time this late lint runs. I left the current function span as is for now. Please let me know if there is a simpler approach I have missed.

Empty test functions pass without exercising behaviour and can create
a false sense of coverage. Classify the lint as suspicious and document
a concrete assertion-based replacement.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-fcp PRs that add, remove, or rename lints and need an FCP S-waiting-on-community-reviews Status: This is awaiting for positive reviews from the community before a maintainer is assigned. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Empty Test Lint

3 participants