Skip to content

Commit c67df05

Browse files
arbitrary_source_item_ordering should ignore test modules (#14585)
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
2 parents 0cd5b62 + e1bd4e4 commit c67df05

File tree

7 files changed

+47
-21
lines changed

7 files changed

+47
-21
lines changed

clippy_lints/src/arbitrary_source_item_ordering.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use clippy_config::types::{
55
SourceItemOrderingWithinModuleItemGroupings,
66
};
77
use clippy_utils::diagnostics::span_lint_and_note;
8+
use clippy_utils::is_cfg_test;
89
use rustc_hir::{
910
AssocItemKind, FieldDef, HirId, ImplItemRef, IsAuto, Item, ItemKind, Mod, QPath, TraitItemRef, TyKind, Variant,
1011
VariantData,
@@ -361,6 +362,10 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering {
361362
// as no sorting by source map/line of code has to be applied.
362363
//
363364
for item in items {
365+
if is_cfg_test(cx.tcx, item.hir_id()) {
366+
continue;
367+
}
368+
364369
if item.span.in_external_macro(cx.sess().source_map()) {
365370
continue;
366371
}

tests/ui-toml/arbitrary_source_item_ordering/ordering_good.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
//@[bad_conf_4] error-in-other-file:
1717
//@[bad_conf_5] error-in-other-file:
1818
//@[bad_conf_6] error-in-other-file:
19+
//@compile-flags: --test
1920

2021
#![allow(dead_code)]
2122
#![warn(clippy::arbitrary_source_item_ordering)]

tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.default.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
error: incorrect ordering of items (must be alphabetically ordered)
2-
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:35:5
2+
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:36:5
33
|
44
LL | a: bool,
55
| ^
66
|
77
note: should be placed before `b`
8-
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:34:5
8+
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:35:5
99
|
1010
LL | b: bool,
1111
| ^
1212
note: the lint level is defined here
13-
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:32:8
13+
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:33:8
1414
|
1515
LL | #[deny(clippy::arbitrary_source_item_ordering)]
1616
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.ord_in_2.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
error: incorrect ordering of items (must be alphabetically ordered)
2-
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:24:8
2+
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:25:8
33
|
44
LL | struct OrderedChecked {
55
| ^^^^^^^^^^^^^^
66
|
77
note: should be placed before `Unordered`
8-
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:18:8
8+
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:19:8
99
|
1010
LL | struct Unordered {
1111
| ^^^^^^^^^
1212
note: the lint level is defined here
13-
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:9:9
13+
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:10:9
1414
|
1515
LL | #![deny(clippy::arbitrary_source_item_ordering)]
1616
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1717

1818
error: incorrect ordering of items (must be alphabetically ordered)
19-
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:35:5
19+
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:36:5
2020
|
2121
LL | a: bool,
2222
| ^
2323
|
2424
note: should be placed before `b`
25-
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:34:5
25+
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:35:5
2626
|
2727
LL | b: bool,
2828
| ^
2929
note: the lint level is defined here
30-
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:32:8
30+
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:33:8
3131
|
3232
LL | #[deny(clippy::arbitrary_source_item_ordering)]
3333
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.ord_in_3.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
error: incorrect ordering of items (must be alphabetically ordered)
2-
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:24:8
2+
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:25:8
33
|
44
LL | struct OrderedChecked {
55
| ^^^^^^^^^^^^^^
66
|
77
note: should be placed before `Unordered`
8-
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:18:8
8+
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:19:8
99
|
1010
LL | struct Unordered {
1111
| ^^^^^^^^^
1212
note: the lint level is defined here
13-
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:9:9
13+
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:10:9
1414
|
1515
LL | #![deny(clippy::arbitrary_source_item_ordering)]
1616
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,60 @@
11
error: incorrect ordering of items (must be alphabetically ordered)
2-
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:24:8
2+
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:25:8
33
|
44
LL | struct OrderedChecked {
55
| ^^^^^^^^^^^^^^
66
|
77
note: should be placed before `Unordered`
8-
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:18:8
8+
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:19:8
99
|
1010
LL | struct Unordered {
1111
| ^^^^^^^^^
1212
note: the lint level is defined here
13-
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:9:9
13+
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:10:9
1414
|
1515
LL | #![deny(clippy::arbitrary_source_item_ordering)]
1616
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1717

1818
error: incorrect ordering of items (must be alphabetically ordered)
19-
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:45:4
19+
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:46:4
2020
|
2121
LL | fn before_main() {}
2222
| ^^^^^^^^^^^
2323
|
2424
note: should be placed before `main`
25-
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:41:4
25+
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:42:4
2626
|
2727
LL | fn main() {
2828
| ^^^^
2929

3030
error: incorrect ordering of items (must be alphabetically ordered)
31-
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:35:5
31+
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:36:5
3232
|
3333
LL | a: bool,
3434
| ^
3535
|
3636
note: should be placed before `b`
37-
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:34:5
37+
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:35:5
3838
|
3939
LL | b: bool,
4040
| ^
4141
note: the lint level is defined here
42-
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:32:8
42+
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:33:8
4343
|
4444
LL | #[deny(clippy::arbitrary_source_item_ordering)]
4545
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4646

47-
error: aborting due to 3 previous errors
47+
error: incorrect ordering of items (must be alphabetically ordered)
48+
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:52:11
49+
|
50+
LL | const A: i8 = 0;
51+
| ^
52+
|
53+
note: should be placed before `B`
54+
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:51:11
55+
|
56+
LL | const B: i8 = 1;
57+
| ^
58+
59+
error: aborting due to 4 previous errors
4860

tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//@[ord_within] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/arbitrary_source_item_ordering/ord_within
55
//@[ord_in_2] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/arbitrary_source_item_ordering/ord_in_2
66
//@[ord_in_3] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/arbitrary_source_item_ordering/ord_in_3
7+
//@compile-flags: --test
78

89
#![allow(dead_code)]
910
#![deny(clippy::arbitrary_source_item_ordering)]
@@ -44,3 +45,10 @@ fn main() {
4445

4546
fn before_main() {}
4647
//~[ord_within]^ arbitrary_source_item_ordering
48+
49+
#[cfg(test)]
50+
mod test {
51+
const B: i8 = 1;
52+
const A: i8 = 0;
53+
//~[ord_within]^ arbitrary_source_item_ordering
54+
}

0 commit comments

Comments
 (0)