Skip to content

arbitrary_source_item_ordering should ignore test modules #14585

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions clippy_lints/src/arbitrary_source_item_ordering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use clippy_config::types::{
SourceItemOrderingWithinModuleItemGroupings,
};
use clippy_utils::diagnostics::span_lint_and_note;
use clippy_utils::is_cfg_test;
use rustc_hir::{
AssocItemKind, FieldDef, HirId, ImplItemRef, IsAuto, Item, ItemKind, Mod, QPath, TraitItemRef, TyKind, Variant,
VariantData,
Expand Down Expand Up @@ -361,6 +362,10 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering {
// as no sorting by source map/line of code has to be applied.
//
for item in items {
if is_cfg_test(cx.tcx, item.hir_id()) {
continue;
}

if item.span.in_external_macro(cx.sess().source_map()) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
//@[bad_conf_4] error-in-other-file:
//@[bad_conf_5] error-in-other-file:
//@[bad_conf_6] error-in-other-file:
//@compile-flags: --test

#![allow(dead_code)]
#![warn(clippy::arbitrary_source_item_ordering)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:35:5
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:36:5
|
LL | a: bool,
| ^
|
note: should be placed before `b`
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:34:5
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:35:5
|
LL | b: bool,
| ^
note: the lint level is defined here
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:32:8
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:33:8
|
LL | #[deny(clippy::arbitrary_source_item_ordering)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:24:8
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:25:8
|
LL | struct OrderedChecked {
| ^^^^^^^^^^^^^^
|
note: should be placed before `Unordered`
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:18:8
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:19:8
|
LL | struct Unordered {
| ^^^^^^^^^
note: the lint level is defined here
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:9:9
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:10:9
|
LL | #![deny(clippy::arbitrary_source_item_ordering)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:35:5
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:36:5
|
LL | a: bool,
| ^
|
note: should be placed before `b`
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:34:5
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:35:5
|
LL | b: bool,
| ^
note: the lint level is defined here
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:32:8
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:33:8
|
LL | #[deny(clippy::arbitrary_source_item_ordering)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:24:8
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:25:8
|
LL | struct OrderedChecked {
| ^^^^^^^^^^^^^^
|
note: should be placed before `Unordered`
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:18:8
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:19:8
|
LL | struct Unordered {
| ^^^^^^^^^
note: the lint level is defined here
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:9:9
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:10:9
|
LL | #![deny(clippy::arbitrary_source_item_ordering)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -1,48 +1,60 @@
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:24:8
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:25:8
|
LL | struct OrderedChecked {
| ^^^^^^^^^^^^^^
|
note: should be placed before `Unordered`
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:18:8
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:19:8
|
LL | struct Unordered {
| ^^^^^^^^^
note: the lint level is defined here
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:9:9
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:10:9
|
LL | #![deny(clippy::arbitrary_source_item_ordering)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:45:4
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:46:4
|
LL | fn before_main() {}
| ^^^^^^^^^^^
|
note: should be placed before `main`
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:41:4
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:42:4
|
LL | fn main() {
| ^^^^

error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:35:5
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:36:5
|
LL | a: bool,
| ^
|
note: should be placed before `b`
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:34:5
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:35:5
|
LL | b: bool,
| ^
note: the lint level is defined here
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:32:8
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:33:8
|
LL | #[deny(clippy::arbitrary_source_item_ordering)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 3 previous errors
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:52:11
|
LL | const A: i8 = 0;
| ^
|
note: should be placed before `B`
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:51:11
|
LL | const B: i8 = 1;
| ^

error: aborting due to 4 previous errors

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//@[ord_within] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/arbitrary_source_item_ordering/ord_within
//@[ord_in_2] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/arbitrary_source_item_ordering/ord_in_2
//@[ord_in_3] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/arbitrary_source_item_ordering/ord_in_3
//@compile-flags: --test

#![allow(dead_code)]
#![deny(clippy::arbitrary_source_item_ordering)]
Expand Down Expand Up @@ -44,3 +45,10 @@ fn main() {

fn before_main() {}
//~[ord_within]^ arbitrary_source_item_ordering

#[cfg(test)]
mod test {
const B: i8 = 1;
const A: i8 = 0;
//~[ord_within]^ arbitrary_source_item_ordering
}