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 Sep 27, 2024
1 parent ba10a89 commit 894bd20
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6150,7 +6150,6 @@ Released 2018-09-13
[`disallowed-types`]: https://doc.rust-lang.org/clippy/lint_configuration.html#disallowed-types
[`doc-valid-idents`]: https://doc.rust-lang.org/clippy/lint_configuration.html#doc-valid-idents
[`enable-raw-pointer-heuristic-for-send`]: https://doc.rust-lang.org/clippy/lint_configuration.html#enable-raw-pointer-heuristic-for-send
[`enable-source-item-ordering-for`]: https://doc.rust-lang.org/clippy/lint_configuration.html#enable-source-item-ordering-for
[`enforce-iter-loop-reborrow`]: https://doc.rust-lang.org/clippy/lint_configuration.html#enforce-iter-loop-reborrow
[`enforced-import-renames`]: https://doc.rust-lang.org/clippy/lint_configuration.html#enforced-import-renames
[`enum-variant-name-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#enum-variant-name-threshold
Expand All @@ -6175,6 +6174,7 @@ Released 2018-09-13
[`semicolon-inside-block-ignore-singleline`]: https://doc.rust-lang.org/clippy/lint_configuration.html#semicolon-inside-block-ignore-singleline
[`semicolon-outside-block-ignore-multiline`]: https://doc.rust-lang.org/clippy/lint_configuration.html#semicolon-outside-block-ignore-multiline
[`single-char-binding-names-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#single-char-binding-names-threshold
[`source-item-ordering`]: https://doc.rust-lang.org/clippy/lint_configuration.html#source-item-ordering
[`stack-size-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#stack-size-threshold
[`standard-macro-braces`]: https://doc.rust-lang.org/clippy/lint_configuration.html#standard-macro-braces
[`struct-field-name-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#struct-field-name-threshold
Expand Down
20 changes: 10 additions & 10 deletions book/src/lint_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -472,16 +472,6 @@ Whether to apply the raw pointer heuristic to determine if a type is `Send`.
* [`non_send_fields_in_send_ty`](https://rust-lang.github.io/rust-clippy/master/index.html#non_send_fields_in_send_ty)


## `enable-source-item-ordering-for`
Which kind of elements should be ordered internally, possible values being `enum`, `impl`, `module`, `struct`, `trait`.

**Default Value:** `["enum", "impl", "module", "struct", "trait"]`

---
**Affected lints:**
* [`arbitrary_source_item_ordering`](https://rust-lang.github.io/rust-clippy/master/index.html#arbitrary_source_item_ordering)


## `enforce-iter-loop-reborrow`
Whether to recommend using implicit into iter for reborrowed values.

Expand Down Expand Up @@ -802,6 +792,16 @@ The maximum number of single char bindings a scope may have
* [`many_single_char_names`](https://rust-lang.github.io/rust-clippy/master/index.html#many_single_char_names)


## `source-item-ordering`
Which kind of elements should be ordered internally, possible values being `enum`, `impl`, `module`, `struct`, `trait`.

**Default Value:** `["enum", "impl", "module", "struct", "trait"]`

---
**Affected lints:**
* [`arbitrary_source_item_ordering`](https://rust-lang.github.io/rust-clippy/master/index.html#arbitrary_source_item_ordering)


## `stack-size-threshold`
The maximum allowed stack size for functions in bytes

Expand Down
12 changes: 6 additions & 6 deletions clippy_config/src/conf.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::ClippyConfiguration;
use crate::msrvs::Msrv;
use crate::types::{
DisallowedPath, MacroMatcher, MatchLintBehaviour, PubUnderscoreFieldsBehaviour, Rename, SourceItemOrderingCategory,
SourceItemOrderingEnableFor, SourceItemOrderingModuleItemGroupings, SourceItemOrderingModuleItemKind,
DisallowedPath, MacroMatcher, MatchLintBehaviour, PubUnderscoreFieldsBehaviour, Rename, SourceItemOrdering,
SourceItemOrderingCategory, SourceItemOrderingModuleItemGroupings, SourceItemOrderingModuleItemKind,
SourceItemOrderingTraitAssocItemKind, SourceItemOrderingTraitAssocItemKinds,
};
use rustc_errors::Applicability;
Expand Down Expand Up @@ -71,7 +71,7 @@ const DEFAULT_TRAIT_ASSOC_ITEM_KINDS_ORDER: &[SourceItemOrderingTraitAssocItemKi
use SourceItemOrderingTraitAssocItemKind::*;
&[Const, Type, Fn]
};
const DEFAULT_ENABLE_SOURCE_ITEM_ORDERING_FOR: &[SourceItemOrderingCategory] = {
const DEFAULT_SOURCE_ITEM_ORDERING: &[SourceItemOrderingCategory] = {
#[allow(clippy::enum_glob_use)] // Very local glob use for legibility.
use SourceItemOrderingCategory::*;
&[Enum, Impl, Module, Struct, Trait]
Expand Down Expand Up @@ -464,9 +464,6 @@ define_Conf! {
/// Whether to apply the raw pointer heuristic to determine if a type is `Send`.
#[lints(non_send_fields_in_send_ty)]
enable_raw_pointer_heuristic_for_send: bool = true,
/// Which kind of elements should be ordered internally, possible values being `enum`, `impl`, `module`, `struct`, `trait`.
#[lints(arbitrary_source_item_ordering)]
enable_source_item_ordering_for: SourceItemOrderingEnableFor = DEFAULT_ENABLE_SOURCE_ITEM_ORDERING_FOR.into(),
/// Whether to recommend using implicit into iter for reborrowed values.
///
/// #### Example
Expand Down Expand Up @@ -619,6 +616,9 @@ define_Conf! {
/// The maximum number of single char bindings a scope may have
#[lints(many_single_char_names)]
single_char_binding_names_threshold: u64 = 4,
/// Which kind of elements should be ordered internally, possible values being `enum`, `impl`, `module`, `struct`, `trait`.
#[lints(arbitrary_source_item_ordering)]
source_item_ordering: SourceItemOrdering = DEFAULT_SOURCE_ITEM_ORDERING.into(),
/// The maximum allowed stack size for functions in bytes
#[lints(large_stack_frames)]
stack_size_threshold: u64 = 512_000,
Expand Down
12 changes: 6 additions & 6 deletions clippy_config/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ pub enum SourceItemOrderingCategory {
///
/// The [`Deserialize`] implementation checks that there are no duplicates in
/// the user configuration.
pub struct SourceItemOrderingEnableFor(Vec<SourceItemOrderingCategory>);
pub struct SourceItemOrdering(Vec<SourceItemOrderingCategory>);

impl SourceItemOrderingEnableFor {
impl SourceItemOrdering {
pub fn contains(&self, category: &SourceItemOrderingCategory) -> bool {
self.0.contains(category)
}
}

impl<T> From<T> for SourceItemOrderingEnableFor
impl<T> From<T> for SourceItemOrdering
where
T: Into<Vec<SourceItemOrderingCategory>>,
{
Expand All @@ -135,13 +135,13 @@ where
}
}

impl core::fmt::Debug for SourceItemOrderingEnableFor {
impl core::fmt::Debug for SourceItemOrdering {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}

impl<'de> Deserialize<'de> for SourceItemOrderingEnableFor {
impl<'de> Deserialize<'de> for SourceItemOrdering {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
Expand All @@ -162,7 +162,7 @@ impl<'de> Deserialize<'de> for SourceItemOrderingEnableFor {
}
}

impl Serialize for SourceItemOrderingEnableFor {
impl Serialize for SourceItemOrdering {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: ser::Serializer,
Expand Down
10 changes: 5 additions & 5 deletions clippy_lints/src/arbitrary_source_item_ordering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ impl ArbitrarySourceItemOrdering {
use SourceItemOrderingCategory::*;
Self {
assoc_types_order: conf.trait_assoc_item_kinds_order.clone(),
enable_ordering_for_enum: conf.enable_source_item_ordering_for.contains(&Enum),
enable_ordering_for_impl: conf.enable_source_item_ordering_for.contains(&Impl),
enable_ordering_for_module: conf.enable_source_item_ordering_for.contains(&Module),
enable_ordering_for_struct: conf.enable_source_item_ordering_for.contains(&Struct),
enable_ordering_for_trait: conf.enable_source_item_ordering_for.contains(&Trait),
enable_ordering_for_enum: conf.source_item_ordering.contains(&Enum),
enable_ordering_for_impl: conf.source_item_ordering.contains(&Impl),
enable_ordering_for_module: conf.source_item_ordering.contains(&Module),
enable_ordering_for_struct: conf.source_item_ordering.contains(&Struct),
enable_ordering_for_trait: conf.source_item_ordering.contains(&Trait),
module_item_order_groupings: conf.module_item_order_groupings.clone(),
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ error: error reading Clippy's configuration file: unknown field `foobar`, expect
disallowed-types
doc-valid-idents
enable-raw-pointer-heuristic-for-send
enable-source-item-ordering-for
enforce-iter-loop-reborrow
enforced-import-renames
enum-variant-name-threshold
Expand All @@ -62,6 +61,7 @@ error: error reading Clippy's configuration file: unknown field `foobar`, expect
semicolon-inside-block-ignore-singleline
semicolon-outside-block-ignore-multiline
single-char-binding-names-threshold
source-item-ordering
stack-size-threshold
standard-macro-braces
struct-field-name-threshold
Expand Down Expand Up @@ -124,7 +124,6 @@ error: error reading Clippy's configuration file: unknown field `barfoo`, expect
disallowed-types
doc-valid-idents
enable-raw-pointer-heuristic-for-send
enable-source-item-ordering-for
enforce-iter-loop-reborrow
enforced-import-renames
enum-variant-name-threshold
Expand All @@ -149,6 +148,7 @@ error: error reading Clippy's configuration file: unknown field `barfoo`, expect
semicolon-inside-block-ignore-singleline
semicolon-outside-block-ignore-multiline
single-char-binding-names-threshold
source-item-ordering
stack-size-threshold
standard-macro-braces
struct-field-name-threshold
Expand Down Expand Up @@ -211,7 +211,6 @@ error: error reading Clippy's configuration file: unknown field `allow_mixed_uni
disallowed-types
doc-valid-idents
enable-raw-pointer-heuristic-for-send
enable-source-item-ordering-for
enforce-iter-loop-reborrow
enforced-import-renames
enum-variant-name-threshold
Expand All @@ -236,6 +235,7 @@ error: error reading Clippy's configuration file: unknown field `allow_mixed_uni
semicolon-inside-block-ignore-singleline
semicolon-outside-block-ignore-multiline
single-char-binding-names-threshold
source-item-ordering
stack-size-threshold
standard-macro-braces
struct-field-name-threshold
Expand Down

0 comments on commit 894bd20

Please sign in to comment.