Skip to content

Commit

Permalink
fixup! new lint: source_item_ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
decryphe committed Oct 11, 2024
1 parent 5626d99 commit 1aa0157
Show file tree
Hide file tree
Showing 11 changed files with 268 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clippy_config/src/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const DEFAULT_MODULE_ITEM_ORDERING_GROUPS: &[(&str, &[SourceItemOrderingModuleIt
#[allow(clippy::enum_glob_use)] // Very local glob use for legibility.
use SourceItemOrderingModuleItemKind::*;
&[
("modules", &[Mod, ForeignMod]),
("modules", &[ExternCrate, Mod, ForeignMod]),
("use", &[Use]),
("macros", &[Macro]),
("global_asm", &[GlobalAsm]),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
trait-assoc-item-kinds-order = ["const", "type", "fn"]
source-item-ordering = ["enum", "impl", "module", "struct", "trait"]
module-item-order-groupings = [
["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"]]
]

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
source-item-ordering = ["enum"]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
source-item-ordering = ["impl"]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
source-item-ordering = ["trait"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_enum.rs:22:5
|
LL | A,
| ^
|
note: should be placed before `B`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_enum.rs:21:5
|
LL | B,
| ^
= note: `-D clippy::arbitrary-source-item-ordering` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::arbitrary_source_item_ordering)]`

error: aborting due to 1 previous error

43 changes: 43 additions & 0 deletions tests/ui-toml/arbitrary_source_item_ordering/ordering_only_enum.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//@aux-build:../../ui/auxiliary/proc_macros.rs
//@revisions: only_enum
//@[only_enum] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/arbitrary_source_item_ordering/only_enum

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

fn main() {}

struct StructUnordered {
b: bool,
a: bool,
}

enum EnumOrdered {
A,
B,
}

enum EnumUnordered {
B,
A,
}

trait TraitUnordered {
const B: bool;
const A: bool;

type SomeType;

fn b();
fn a();
}

trait TraitUnorderedItemKinds {
type SomeType;

const A: bool;

fn a();
}

const ZIS_SHOULD_BE_AT_THE_TOP: () = ();
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_impl.rs:43:8
|
LL | fn a() {}
| ^
|
note: should be placed before `b`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_impl.rs:42:8
|
LL | fn b() {}
| ^
= note: `-D clippy::arbitrary-source-item-ordering` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::arbitrary_source_item_ordering)]`

error: incorrect ordering of impl items (defined order: [Const, Type, Fn])
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_impl.rs:45:5
|
LL | type SomeType = i8;
| ^^^^^^^^^^^^^^^^^^^
|
note: should be placed before `a`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_impl.rs:43:5
|
LL | fn a() {}
| ^^^^^^^^^

error: incorrect ordering of impl items (defined order: [Const, Type, Fn])
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_impl.rs:47:5
|
LL | const A: bool = true;
| ^^^^^^^^^^^^^^^^^^^^^
|
note: should be placed before `SomeType`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_impl.rs:45:5
|
LL | type SomeType = i8;
| ^^^^^^^^^^^^^^^^^^^

error: aborting due to 3 previous errors

67 changes: 67 additions & 0 deletions tests/ui-toml/arbitrary_source_item_ordering/ordering_only_impl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//@aux-build:../../ui/auxiliary/proc_macros.rs
//@revisions: only_impl
//@[only_impl] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/arbitrary_source_item_ordering/only_impl

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

fn main() {}

struct StructUnordered {
b: bool,
a: bool,
}

struct BasicStruct {}

trait BasicTrait {
const A: bool;

type SomeType;

fn b();
fn a();
}

enum EnumUnordered {
B,
A,
}

trait TraitUnordered {
const B: bool;
const A: bool;

type SomeType;

fn b();
fn a();
}

impl BasicTrait for StructUnordered {
fn b() {}
fn a() {}

type SomeType = i8;

const A: bool = true;
}

trait TraitUnorderedItemKinds {
type SomeType;

const A: bool;

fn a();
}

const ZIS_SHOULD_BE_AT_THE_TOP: () = ();

impl BasicTrait for BasicStruct {
const A: bool = true;

type SomeType = i8;

fn a() {}
fn b() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_trait.rs:32:11
|
LL | const A: bool;
| ^
|
note: should be placed before `B`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_trait.rs:31:11
|
LL | const B: bool;
| ^
= note: `-D clippy::arbitrary-source-item-ordering` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::arbitrary_source_item_ordering)]`

error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_trait.rs:37:8
|
LL | fn a();
| ^
|
note: should be placed before `b`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_trait.rs:36:8
|
LL | fn b();
| ^

error: incorrect ordering of trait items (defined order: [Const, Type, Fn])
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_trait.rs:43:5
|
LL | const A: bool;
| ^^^^^^^^^^^^^^
|
note: should be placed before `SomeType`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_trait.rs:41:5
|
LL | type SomeType;
| ^^^^^^^^^^^^^^

error: aborting due to 3 previous errors

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//@aux-build:../../ui/auxiliary/proc_macros.rs
//@revisions: only_trait
//@[only_trait] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/arbitrary_source_item_ordering/only_trait

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

fn main() {}

struct StructUnordered {
b: bool,
a: bool,
}

trait TraitOrdered {
const A: bool;
const B: bool;

type SomeType;

fn a();
fn b();
}

enum EnumUnordered {
B,
A,
}

trait TraitUnordered {
const B: bool;
const A: bool;

type SomeType;

fn b();
fn a();
}

trait TraitUnorderedItemKinds {
type SomeType;

const A: bool;

fn a();
}

const ZIS_SHOULD_BE_AT_THE_TOP: () = ();

0 comments on commit 1aa0157

Please sign in to comment.