Skip to content

arbitrary_source_item_ordering ignores test modules #14570

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

Closed
t-webber opened this issue Apr 9, 2025 · 3 comments · Fixed by #14585
Closed

arbitrary_source_item_ordering ignores test modules #14570

t-webber opened this issue Apr 9, 2025 · 3 comments · Fixed by #14585
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@t-webber
Copy link

t-webber commented Apr 9, 2025

Summary

When using the arbitrary_source_item_ordering, there is a conflict with the warn-by-default items_after_test_module lint.

When I add test modules, I want to put them at the end of the file, but arbitrary_source_item_ordering wants me to put my test module at the beginning of the file, which goes against the common practice and the warn-by-default items_after_test_module lint.

I would expect arbitrary_source_item_ordering to have an exception to the rule for the test modules.

Lint Name

arbitrary_source_item_ordering

Reproducer

I tried this code:

#![warn(clippy::arbitrary_source_item_ordering)]

const fn main() {}

#[cfg(test)]
mod test {}

I saw this happen:

warning: incorrect ordering of items (module item groupings specify another order)
 --> src/main.rs:6:5
  |
6 | mod test {}
  |     ^^^^
  |
note: should be placed before `main`
 --> src/main.rs:3:10
  |
3 | const fn main() {}
  |          ^^^^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#arbitrary_source_item_ordering
note: the lint level is defined here
 --> src/main.rs:1:9
  |
1 | #![warn(clippy::arbitrary_source_item_ordering)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I expected to see this happen:

nothing

Version

rustc 1.88.0-nightly (e2014e876 2025-04-01)
binary: rustc
commit-hash: e2014e876e3efaa69bf51c19579adb16c3df5f81
commit-date: 2025-04-01
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.1

Additional Labels

No response

@t-webber t-webber added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Apr 9, 2025
@samueltardieu samueltardieu added the good-first-issue These issues are a good way to get started with Clippy label Apr 9, 2025
@alex-semenyuk
Copy link
Member

@rustbot claim

@alex-semenyuk
Copy link
Member

Can't reproduce this also there is test case for this

@samueltardieu
Copy link
Contributor

The test case is incorrect, as it is missing //@compile-flags: --test. Add it, and it will no longer pass.

github-merge-queue bot pushed a commit that referenced this issue Apr 11, 2025
Close #14570

The test is provided
[here](https://github.com/rust-lang/rust-clippy/blob/master/tests/ui-toml/arbitrary_source_item_ordering/ordering_good_var_1.rs#L171)
but it's passed without `//@compile-flags: --test`

changelog: [`arbitrary_source_item_ordering`]: should ignore test
modules
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants