Skip to content

arbitrary_source_item_ordering ignores test modules #14570

@t-webber

Description

@t-webber

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

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't havegood first issueThese issues are a good way to get started with Clippy

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions