Skip to content

Commit d145f69

Browse files
committed
arbitrary_source_item_ordering should ignore test modules
1 parent e0e2a93 commit d145f69

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
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)]

0 commit comments

Comments
 (0)