Skip to content

Commit 72fccdf

Browse files
committed
fixup! new lint: source_item_ordering
1 parent a56cab4 commit 72fccdf

File tree

12 files changed

+269
-2
lines changed

12 files changed

+269
-2
lines changed

book/src/lint_configuration.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ crate. For example, `pub(crate)` items.
669669
## `module-item-order-groupings`
670670
The named groupings of different source item kinds within modules.
671671

672-
**Default Value:** `[["modules", ["mod", "foreign_mod"]], ["use", ["use"]], ["macros", ["macro"]], ["global_asm", ["global_asm"]], ["UPPER_SNAKE_CASE", ["static", "const"]], ["PascalCase", ["ty_alias", "opaque_ty", "enum", "struct", "union", "trait", "trait_alias", "impl"]], ["lower_snake_case", ["fn"]]]`
672+
**Default Value:** `[["modules", ["extern_crate", "mod", "foreign_mod"]], ["use", ["use"]], ["macros", ["macro"]], ["global_asm", ["global_asm"]], ["UPPER_SNAKE_CASE", ["static", "const"]], ["PascalCase", ["ty_alias", "opaque_ty", "enum", "struct", "union", "trait", "trait_alias", "impl"]], ["lower_snake_case", ["fn"]]]`
673673

674674
---
675675
**Affected lints:**

clippy_config/src/conf.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const DEFAULT_MODULE_ITEM_ORDERING_GROUPS: &[(&str, &[SourceItemOrderingModuleIt
5454
#[allow(clippy::enum_glob_use)] // Very local glob use for legibility.
5555
use SourceItemOrderingModuleItemKind::*;
5656
&[
57-
("modules", &[Mod, ForeignMod]),
57+
("modules", &[ExternCrate, Mod, ForeignMod]),
5858
("use", &[Use]),
5959
("macros", &[Macro]),
6060
("global_asm", &[GlobalAsm]),
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
11
trait-assoc-item-kinds-order = ["const", "type", "fn"]
22
source-item-ordering = ["enum", "impl", "module", "struct", "trait"]
3+
module-item-order-groupings = [
4+
["modules", ["extern_crate", "mod", "foreign_mod"]],
5+
["use", ["use"]],
6+
["macros", ["macro"]],
7+
["global_asm", ["global_asm"]],
8+
["UPPER_SNAKE_CASE", ["static", "const"]],
9+
["PascalCase", ["ty_alias", "opaque_ty", "enum", "struct", "union", "trait", "trait_alias", "impl"]],
10+
["lower_snake_case", ["fn"]]
11+
]
12+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
source-item-ordering = ["enum"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
source-item-ordering = ["impl"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
source-item-ordering = ["trait"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error: incorrect ordering of items (must be alphabetically ordered)
2+
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_enum.rs:22:5
3+
|
4+
LL | A,
5+
| ^
6+
|
7+
note: should be placed before `B`
8+
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_enum.rs:21:5
9+
|
10+
LL | B,
11+
| ^
12+
= note: `-D clippy::arbitrary-source-item-ordering` implied by `-D warnings`
13+
= help: to override `-D warnings` add `#[allow(clippy::arbitrary_source_item_ordering)]`
14+
15+
error: aborting due to 1 previous error
16+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//@aux-build:../../ui/auxiliary/proc_macros.rs
2+
//@revisions: only_enum
3+
//@[only_enum] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/arbitrary_source_item_ordering/only_enum
4+
5+
#![allow(dead_code)]
6+
#![warn(clippy::arbitrary_source_item_ordering)]
7+
8+
fn main() {}
9+
10+
struct StructUnordered {
11+
b: bool,
12+
a: bool,
13+
}
14+
15+
enum EnumOrdered {
16+
A,
17+
B,
18+
}
19+
20+
enum EnumUnordered {
21+
B,
22+
A,
23+
}
24+
25+
trait TraitUnordered {
26+
const B: bool;
27+
const A: bool;
28+
29+
type SomeType;
30+
31+
fn b();
32+
fn a();
33+
}
34+
35+
trait TraitUnorderedItemKinds {
36+
type SomeType;
37+
38+
const A: bool;
39+
40+
fn a();
41+
}
42+
43+
const ZIS_SHOULD_BE_AT_THE_TOP: () = ();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
error: incorrect ordering of items (must be alphabetically ordered)
2+
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_impl.rs:43:8
3+
|
4+
LL | fn a() {}
5+
| ^
6+
|
7+
note: should be placed before `b`
8+
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_impl.rs:42:8
9+
|
10+
LL | fn b() {}
11+
| ^
12+
= note: `-D clippy::arbitrary-source-item-ordering` implied by `-D warnings`
13+
= help: to override `-D warnings` add `#[allow(clippy::arbitrary_source_item_ordering)]`
14+
15+
error: incorrect ordering of impl items (defined order: [Const, Type, Fn])
16+
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_impl.rs:45:5
17+
|
18+
LL | type SomeType = i8;
19+
| ^^^^^^^^^^^^^^^^^^^
20+
|
21+
note: should be placed before `a`
22+
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_impl.rs:43:5
23+
|
24+
LL | fn a() {}
25+
| ^^^^^^^^^
26+
27+
error: incorrect ordering of impl items (defined order: [Const, Type, Fn])
28+
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_impl.rs:47:5
29+
|
30+
LL | const A: bool = true;
31+
| ^^^^^^^^^^^^^^^^^^^^^
32+
|
33+
note: should be placed before `SomeType`
34+
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_impl.rs:45:5
35+
|
36+
LL | type SomeType = i8;
37+
| ^^^^^^^^^^^^^^^^^^^
38+
39+
error: aborting due to 3 previous errors
40+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//@aux-build:../../ui/auxiliary/proc_macros.rs
2+
//@revisions: only_impl
3+
//@[only_impl] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/arbitrary_source_item_ordering/only_impl
4+
5+
#![allow(dead_code)]
6+
#![warn(clippy::arbitrary_source_item_ordering)]
7+
8+
fn main() {}
9+
10+
struct StructUnordered {
11+
b: bool,
12+
a: bool,
13+
}
14+
15+
struct BasicStruct {}
16+
17+
trait BasicTrait {
18+
const A: bool;
19+
20+
type SomeType;
21+
22+
fn b();
23+
fn a();
24+
}
25+
26+
enum EnumUnordered {
27+
B,
28+
A,
29+
}
30+
31+
trait TraitUnordered {
32+
const B: bool;
33+
const A: bool;
34+
35+
type SomeType;
36+
37+
fn b();
38+
fn a();
39+
}
40+
41+
impl BasicTrait for StructUnordered {
42+
fn b() {}
43+
fn a() {}
44+
45+
type SomeType = i8;
46+
47+
const A: bool = true;
48+
}
49+
50+
trait TraitUnorderedItemKinds {
51+
type SomeType;
52+
53+
const A: bool;
54+
55+
fn a();
56+
}
57+
58+
const ZIS_SHOULD_BE_AT_THE_TOP: () = ();
59+
60+
impl BasicTrait for BasicStruct {
61+
const A: bool = true;
62+
63+
type SomeType = i8;
64+
65+
fn a() {}
66+
fn b() {}
67+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
error: incorrect ordering of items (must be alphabetically ordered)
2+
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_trait.rs:32:11
3+
|
4+
LL | const A: bool;
5+
| ^
6+
|
7+
note: should be placed before `B`
8+
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_trait.rs:31:11
9+
|
10+
LL | const B: bool;
11+
| ^
12+
= note: `-D clippy::arbitrary-source-item-ordering` implied by `-D warnings`
13+
= help: to override `-D warnings` add `#[allow(clippy::arbitrary_source_item_ordering)]`
14+
15+
error: incorrect ordering of items (must be alphabetically ordered)
16+
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_trait.rs:37:8
17+
|
18+
LL | fn a();
19+
| ^
20+
|
21+
note: should be placed before `b`
22+
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_trait.rs:36:8
23+
|
24+
LL | fn b();
25+
| ^
26+
27+
error: incorrect ordering of trait items (defined order: [Const, Type, Fn])
28+
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_trait.rs:43:5
29+
|
30+
LL | const A: bool;
31+
| ^^^^^^^^^^^^^^
32+
|
33+
note: should be placed before `SomeType`
34+
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_trait.rs:41:5
35+
|
36+
LL | type SomeType;
37+
| ^^^^^^^^^^^^^^
38+
39+
error: aborting due to 3 previous errors
40+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//@aux-build:../../ui/auxiliary/proc_macros.rs
2+
//@revisions: only_trait
3+
//@[only_trait] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/arbitrary_source_item_ordering/only_trait
4+
5+
#![allow(dead_code)]
6+
#![warn(clippy::arbitrary_source_item_ordering)]
7+
8+
fn main() {}
9+
10+
struct StructUnordered {
11+
b: bool,
12+
a: bool,
13+
}
14+
15+
trait TraitOrdered {
16+
const A: bool;
17+
const B: bool;
18+
19+
type SomeType;
20+
21+
fn a();
22+
fn b();
23+
}
24+
25+
enum EnumUnordered {
26+
B,
27+
A,
28+
}
29+
30+
trait TraitUnordered {
31+
const B: bool;
32+
const A: bool;
33+
34+
type SomeType;
35+
36+
fn b();
37+
fn a();
38+
}
39+
40+
trait TraitUnorderedItemKinds {
41+
type SomeType;
42+
43+
const A: bool;
44+
45+
fn a();
46+
}
47+
48+
const ZIS_SHOULD_BE_AT_THE_TOP: () = ();

0 commit comments

Comments
 (0)