Skip to content

Commit 7ac8f2c

Browse files
committed
fixup! new lint: source_item_ordering
1 parent e7a7bf5 commit 7ac8f2c

13 files changed

+525
-46
lines changed

clippy_config/src/types.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -295,13 +295,14 @@ impl<'de> Deserialize<'de> for SourceItemOrderingModuleItemGroupings {
295295

296296
Ok(Self { groups, lut })
297297
} else if items_total != all_items.len() {
298-
Err(de::Error::custom(
299-
"Some module item kinds were configured more than once in the source ordering configuration.",
300-
))
298+
Err(de::Error::custom(format!(
299+
"Some module item kinds were configured more than once, or were missing, in the source ordering configuration. \
300+
The module item kinds are: {all_items:?}"
301+
)))
301302
} else {
302303
Err(de::Error::custom(format!(
303304
"Not all module item kinds were part of the configured source ordering rule. \
304-
All item kinds must be provided in the config, otherwise the required source ordering would remain ambiguous.\
305+
All item kinds must be provided in the config, otherwise the required source ordering would remain ambiguous. \
305306
The module item kinds are: {all_items:?}"
306307
)))
307308
}
@@ -381,13 +382,14 @@ impl<'de> Deserialize<'de> for SourceItemOrderingTraitAssocItemKinds {
381382
if expected_items.is_empty() && items.len() == all_items.len() {
382383
Ok(Self(items))
383384
} else if items.len() != all_items.len() {
384-
Err(de::Error::custom(
385-
"Some associated item kinds were configured more than once in the source ordering configuration.",
386-
))
385+
Err(de::Error::custom(format!(
386+
"Some trait associated item kinds were configured more than once, or were missing, in the source ordering configuration. \
387+
The trait associated item kinds are: {all_items:?}",
388+
)))
387389
} else {
388390
Err(de::Error::custom(format!(
389391
"Not all trait associated item kinds were part of the configured source ordering rule. \
390-
All item kinds must be provided in the config, otherwise the required source ordering would remain ambiguous.\
392+
All item kinds must be provided in the config, otherwise the required source ordering would remain ambiguous. \
391393
The trait associated item kinds are: {all_items:?}"
392394
)))
393395
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
trait-assoc-item-kinds-order = ["fn", "type", "const", "type"]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
trait-assoc-item-kinds-order = ["const", "type"]

tests/ui-toml/arbitrary_source_item_ordering/default/clippy.toml

Whitespace-only changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: error reading Clippy's configuration file: Some trait associated item kinds were configured more than once, or were missing, in the source ordering configuration. The trait associated item kinds are: [Const, Fn, Type]
2+
--> $DIR/tests/ui-toml/arbitrary_source_item_ordering/bad_conf_1/clippy.toml:1:32
3+
|
4+
LL | trait-assoc-item-kinds-order = ["fn", "type", "const", "type"]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to 1 previous error
8+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: error reading Clippy's configuration file: Some trait associated item kinds were configured more than once, or were missing, in the source ordering configuration. The trait associated item kinds are: [Const, Fn, Type]
2+
--> $DIR/tests/ui-toml/arbitrary_source_item_ordering/bad_conf_2/clippy.toml:1:32
3+
|
4+
LL | trait-assoc-item-kinds-order = ["const", "type"]
5+
| ^^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to 1 previous error
8+

tests/ui/arbitrary_source_item_ordering/ordering_good.rs renamed to tests/ui-toml/arbitrary_source_item_ordering/ordering_good.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
//@aux-build:../../ui/auxiliary/proc_macros.rs
2+
//@revisions: default bad_conf_1 bad_conf_2
3+
//@[default] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/arbitrary_source_item_ordering/default
4+
//@[bad_conf_1] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/arbitrary_source_item_ordering/bad_conf_1
5+
//@[bad_conf_2] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/arbitrary_source_item_ordering/bad_conf_2
6+
17
#![allow(dead_code)]
28
#![warn(clippy::arbitrary_source_item_ordering)]
39

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
//@aux-build:../../ui/auxiliary/proc_macros.rs
2+
//@revisions: var_1
3+
//@[var_1] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/arbitrary_source_item_ordering/var_1
4+
5+
#![allow(dead_code)]
6+
#![warn(clippy::arbitrary_source_item_ordering)]
7+
8+
/// This module gets linted before clippy gives up.
9+
mod i_am_just_right {
10+
const AFTER: i8 = 0;
11+
12+
const BEFORE: i8 = 0;
13+
}
14+
15+
/// Since the upper module passes linting, the lint now recurses into this module.
16+
mod this_is_in_the_wrong_position {
17+
const A: i8 = 1;
18+
const C: i8 = 0;
19+
}
20+
21+
// Use statements should not be linted internally - this is normally auto-sorted using rustfmt.
22+
use std::rc::{Rc, Weak};
23+
use std::sync::{Arc, Barrier, RwLock};
24+
25+
const SNAKE_CASE: &str = "zzzzzzzz";
26+
27+
const ZIS_SHOULD_BE_EVEN_EARLIER: () = ();
28+
29+
const ZIS_SHOULD_BE_REALLY_EARLY: () = ();
30+
31+
trait BasicEmptyTrait {}
32+
33+
trait CloneSelf {
34+
fn clone_self(&self) -> Self;
35+
}
36+
37+
enum EnumOrdered {
38+
A,
39+
B,
40+
C,
41+
}
42+
43+
enum EnumUnordered {
44+
A,
45+
B,
46+
C,
47+
}
48+
49+
#[allow(clippy::arbitrary_source_item_ordering)]
50+
enum EnumUnorderedAllowed {
51+
A,
52+
B,
53+
C,
54+
}
55+
56+
struct StructOrdered {
57+
a: bool,
58+
b: bool,
59+
c: bool,
60+
}
61+
62+
impl BasicEmptyTrait for StructOrdered {}
63+
64+
impl CloneSelf for StructOrdered {
65+
fn clone_self(&self) -> Self {
66+
Self {
67+
a: true,
68+
b: true,
69+
c: true,
70+
}
71+
}
72+
}
73+
74+
impl Default for StructOrdered {
75+
fn default() -> Self {
76+
Self {
77+
a: true,
78+
b: true,
79+
c: true,
80+
}
81+
}
82+
}
83+
84+
impl std::clone::Clone for StructOrdered {
85+
fn clone(&self) -> Self {
86+
Self {
87+
a: true,
88+
b: true,
89+
c: true,
90+
}
91+
}
92+
}
93+
94+
#[derive(Clone, Default)]
95+
struct StructUnordered {
96+
a: bool,
97+
b: bool,
98+
c: bool,
99+
d: bool,
100+
}
101+
102+
impl TraitUnordered for StructUnordered {
103+
fn a() {}
104+
fn b() {}
105+
fn c() {}
106+
107+
type SomeType = ();
108+
109+
const A: bool = false;
110+
const B: bool = false;
111+
const C: bool = false;
112+
}
113+
114+
impl TraitUnorderedItemKinds for StructUnordered {
115+
fn a() {}
116+
117+
type SomeType = ();
118+
119+
const A: bool = false;
120+
}
121+
122+
struct StructUnorderedGeneric<T> {
123+
_1: std::marker::PhantomData<T>,
124+
a: bool,
125+
b: bool,
126+
c: bool,
127+
d: bool,
128+
}
129+
130+
trait TraitOrdered {
131+
fn a();
132+
fn b();
133+
fn c();
134+
135+
type SomeType;
136+
137+
const A: bool;
138+
const B: bool;
139+
const C: bool;
140+
}
141+
142+
trait TraitUnordered {
143+
fn a();
144+
fn b();
145+
fn c();
146+
147+
type SomeType;
148+
149+
const A: bool;
150+
const B: bool;
151+
const C: bool;
152+
}
153+
154+
trait TraitUnorderedItemKinds {
155+
fn a();
156+
157+
type SomeType;
158+
159+
const A: bool;
160+
}
161+
162+
#[derive(std::clone::Clone, Default)]
163+
struct ZisShouldBeBeforeZeMainFn;
164+
165+
fn main() {
166+
// test code goes here
167+
}
168+
169+
#[cfg(test)]
170+
mod test {
171+
const B: i8 = 1;
172+
173+
const A: i8 = 0;
174+
}

0 commit comments

Comments
 (0)