Skip to content

Commit d09f334

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

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

clippy_lints/src/arbitrary_source_item_ordering.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use clippy_config::types::{
44
SourceItemOrderingTraitAssocItemKind, SourceItemOrderingTraitAssocItemKinds,
55
SourceItemOrderingWithinModuleItemGroupings,
66
};
7-
use clippy_utils::diagnostics::span_lint_and_note;
7+
use clippy_utils::{diagnostics::span_lint_and_note, is_cfg_test};
88
use rustc_hir::{
99
AssocItemKind, FieldDef, HirId, ImplItemRef, IsAuto, Item, ItemKind, Mod, QPath, TraitItemRef, TyKind, Variant,
1010
VariantData,
@@ -361,6 +361,10 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering {
361361
// as no sorting by source map/line of code has to be applied.
362362
//
363363
for item in items {
364+
if is_cfg_test(cx.tcx, item.hir_id()) {
365+
continue;
366+
}
367+
364368
if item.span.in_external_macro(cx.sess().source_map()) {
365369
continue;
366370
}

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)