Skip to content

Commit ca7e955

Browse files
committed
upper_case_acronyms: add ui and ui-toml tests for private/public enums
1 parent 4e19d40 commit ca7e955

File tree

5 files changed

+52
-5
lines changed

5 files changed

+52
-5
lines changed

clippy_lints/src/upper_case_acronyms.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
2-
use if_chain::if_chain;
32
use itertools::Itertools;
4-
use rustc_ast::ast::{Item, ItemKind, Variant, VisibilityKind};
3+
use rustc_ast::ast::{Item, ItemKind, VisibilityKind};
54
use rustc_errors::Applicability;
65
use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
76
use rustc_middle::lint::in_external_macro;
@@ -109,7 +108,7 @@ impl EarlyLintPass for UpperCaseAcronyms {
109108
} else if let ItemKind::Enum(ref enumdef, _) = it.kind {
110109
// check enum variants seperately because again we only want to lint on private enums and
111110
// the fn check_variant does not know about the vis of the enum of its variants
112-
&enumdef
111+
enumdef
113112
.variants
114113
.iter()
115114
.for_each(|variant| check_ident(cx, &variant.ident, self.upper_case_acronyms_aggressive));

tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,20 @@ pub struct MIXEDCapital;
2525

2626
pub struct FULLCAPITAL;
2727

28+
// enum variants should not be linted if the num is pub
29+
pub enum ParseError<T> {
30+
FULLCAPITAL(u8),
31+
MIXEDCapital(String),
32+
Utf8(std::string::FromUtf8Error),
33+
Parse(T, String),
34+
}
35+
36+
// private, do lint here
37+
enum ParseErrorPrivate<T> {
38+
WASD(u8),
39+
WASDMixed(String),
40+
Utf8(std::string::FromUtf8Error),
41+
Parse(T, String),
42+
}
43+
2844
fn main() {}

tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.stderr

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,17 @@ error: name `GCCLLVMSomething` contains a capitalized acronym
6666
LL | struct GCCLLVMSomething;
6767
| ^^^^^^^^^^^^^^^^ help: consider making the acronym lowercase, except the initial letter: `GccllvmSomething`
6868

69-
error: aborting due to 11 previous errors
69+
error: name `WASD` contains a capitalized acronym
70+
--> $DIR/upper_case_acronyms.rs:38:5
71+
|
72+
LL | WASD(u8),
73+
| ^^^^ help: consider making the acronym lowercase, except the initial letter: `Wasd`
74+
75+
error: name `WASDMixed` contains a capitalized acronym
76+
--> $DIR/upper_case_acronyms.rs:39:5
77+
|
78+
LL | WASDMixed(String),
79+
| ^^^^^^^^^ help: consider making the acronym lowercase, except the initial letter: `WasdMixed`
80+
81+
error: aborting due to 13 previous errors
7082

tests/ui/upper_case_acronyms.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,18 @@ struct GCCLLVMSomething;
2424
pub struct NOWARNINGHERE;
2525
pub struct ALSONoWarningHERE;
2626

27+
// enum variants should not be linted if the num is pub
28+
pub enum ParseError<T> {
29+
YDB(u8),
30+
Utf8(std::string::FromUtf8Error),
31+
Parse(T, String),
32+
}
33+
34+
// private, do lint here
35+
enum ParseErrorPrivate<T> {
36+
WASD(u8),
37+
Utf8(std::string::FromUtf8Error),
38+
Parse(T, String),
39+
}
40+
2741
fn main() {}

tests/ui/upper_case_acronyms.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,11 @@ error: name `FIN` contains a capitalized acronym
4848
LL | FIN,
4949
| ^^^ help: consider making the acronym lowercase, except the initial letter: `Fin`
5050

51-
error: aborting due to 8 previous errors
51+
error: name `WASD` contains a capitalized acronym
52+
--> $DIR/upper_case_acronyms.rs:36:5
53+
|
54+
LL | WASD(u8),
55+
| ^^^^ help: consider making the acronym lowercase, except the initial letter: `Wasd`
56+
57+
error: aborting due to 9 previous errors
5258

0 commit comments

Comments
 (0)