|
1 | 1 | use clippy_utils::diagnostics::span_lint_and_sugg;
|
2 |
| -use if_chain::if_chain; |
3 | 2 | use itertools::Itertools;
|
4 |
| -use rustc_ast::ast::{Item, ItemKind, Variant, VisibilityKind}; |
| 3 | +use rustc_ast::ast::{Item, ItemKind, VisibilityKind}; |
5 | 4 | use rustc_errors::Applicability;
|
6 | 5 | use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
|
7 | 6 | use rustc_middle::lint::in_external_macro;
|
@@ -99,21 +98,21 @@ fn check_ident(cx: &EarlyContext<'_>, ident: &Ident, be_aggressive: bool) {
|
99 | 98 |
|
100 | 99 | impl EarlyLintPass for UpperCaseAcronyms {
|
101 | 100 | fn check_item(&mut self, cx: &EarlyContext<'_>, it: &Item) {
|
102 |
| - if_chain! { |
103 |
| - if !in_external_macro(cx.sess(), it.span); |
| 101 | + // do not lint public items or in macros |
| 102 | + if !in_external_macro(cx.sess(), it.span) && !matches!(it.vis.kind, VisibilityKind::Public) { |
104 | 103 | if matches!(
|
105 | 104 | it.kind,
|
106 |
| - ItemKind::TyAlias(..) | ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Trait(..) |
107 |
| - ); |
108 |
| - // do not lint public items |
109 |
| - if !matches!(it.vis.kind, VisibilityKind::Public); |
110 |
| - then { |
| 105 | + ItemKind::TyAlias(..) | ItemKind::Struct(..) | ItemKind::Trait(..) |
| 106 | + ) { |
111 | 107 | check_ident(cx, &it.ident, self.upper_case_acronyms_aggressive);
|
| 108 | + } else if let ItemKind::Enum(ref enumdef, _) = it.kind { |
| 109 | + // check enum variants seperately because again we only want to lint on private enums and |
| 110 | + // the fn check_variant does not know about the vis of the enum of its variants |
| 111 | + enumdef |
| 112 | + .variants |
| 113 | + .iter() |
| 114 | + .for_each(|variant| check_ident(cx, &variant.ident, self.upper_case_acronyms_aggressive)); |
112 | 115 | }
|
113 | 116 | }
|
114 | 117 | }
|
115 |
| - |
116 |
| - fn check_variant(&mut self, cx: &EarlyContext<'_>, v: &Variant) { |
117 |
| - check_ident(cx, &v.ident, self.upper_case_acronyms_aggressive); |
118 |
| - } |
119 | 118 | }
|
0 commit comments