Skip to content

Commit 55ccc7a

Browse files
committed
Use break api config for upper_case_acronyms
1 parent 1ce581d commit 55ccc7a

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

clippy_lints/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2020,7 +2020,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
20202020
store.register_late_pass(move || box enum_variants::EnumVariantNames::new(enum_variant_name_threshold, avoid_breaking_exported_api));
20212021
store.register_early_pass(|| box tabs_in_doc_comments::TabsInDocComments);
20222022
let upper_case_acronyms_aggressive = conf.upper_case_acronyms_aggressive;
2023-
store.register_early_pass(move || box upper_case_acronyms::UpperCaseAcronyms::new(upper_case_acronyms_aggressive));
2023+
store.register_late_pass(move || box upper_case_acronyms::UpperCaseAcronyms::new(avoid_breaking_exported_api, upper_case_acronyms_aggressive));
20242024
store.register_late_pass(|| box default::Default::default());
20252025
store.register_late_pass(|| box unused_self::UnusedSelf);
20262026
store.register_late_pass(|| box mutable_debug_assertion::DebugAssertWithMutCall);

clippy_lints/src/upper_case_acronyms.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use itertools::Itertools;
3-
use rustc_ast::ast::{Item, ItemKind, VisibilityKind};
43
use rustc_errors::Applicability;
5-
use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
4+
use rustc_hir::{Item, ItemKind};
5+
use rustc_lint::{LateContext, LateLintPass, LintContext};
66
use rustc_middle::lint::in_external_macro;
77
use rustc_session::{declare_tool_lint, impl_lint_pass};
88
use rustc_span::symbol::Ident;
@@ -38,12 +38,14 @@ declare_clippy_lint! {
3838

3939
#[derive(Default)]
4040
pub struct UpperCaseAcronyms {
41+
avoid_breaking_exported_api: bool,
4142
upper_case_acronyms_aggressive: bool,
4243
}
4344

4445
impl UpperCaseAcronyms {
45-
pub fn new(aggressive: bool) -> Self {
46+
pub fn new(avoid_breaking_exported_api: bool, aggressive: bool) -> Self {
4647
Self {
48+
avoid_breaking_exported_api,
4749
upper_case_acronyms_aggressive: aggressive,
4850
}
4951
}
@@ -72,7 +74,7 @@ fn correct_ident(ident: &str) -> String {
7274
ident
7375
}
7476

75-
fn check_ident(cx: &EarlyContext<'_>, ident: &Ident, be_aggressive: bool) {
77+
fn check_ident(cx: &LateContext<'_>, ident: &Ident, be_aggressive: bool) {
7678
let span = ident.span;
7779
let ident = &ident.as_str();
7880
let corrected = correct_ident(ident);
@@ -96,23 +98,27 @@ fn check_ident(cx: &EarlyContext<'_>, ident: &Ident, be_aggressive: bool) {
9698
}
9799
}
98100

99-
impl EarlyLintPass for UpperCaseAcronyms {
100-
fn check_item(&mut self, cx: &EarlyContext<'_>, it: &Item) {
101+
impl LateLintPass<'_> for UpperCaseAcronyms {
102+
fn check_item(&mut self, cx: &LateContext<'_>, it: &Item<'_>) {
101103
// do not lint public items or in macros
102-
if !in_external_macro(cx.sess(), it.span) && !matches!(it.vis.kind, VisibilityKind::Public) {
103-
if matches!(
104-
it.kind,
105-
ItemKind::TyAlias(..) | ItemKind::Struct(..) | ItemKind::Trait(..)
106-
) {
104+
if in_external_macro(cx.sess(), it.span)
105+
|| (self.avoid_breaking_exported_api && cx.access_levels.is_exported(it.hir_id()))
106+
{
107+
return;
108+
}
109+
match it.kind {
110+
ItemKind::TyAlias(..) | ItemKind::Struct(..) | ItemKind::Trait(..) => {
107111
check_ident(cx, &it.ident, self.upper_case_acronyms_aggressive);
108-
} else if let ItemKind::Enum(ref enumdef, _) = it.kind {
112+
},
113+
ItemKind::Enum(ref enumdef, _) => {
109114
// check enum variants seperately because again we only want to lint on private enums and
110115
// the fn check_variant does not know about the vis of the enum of its variants
111116
enumdef
112117
.variants
113118
.iter()
114119
.for_each(|variant| check_ident(cx, &variant.ident, self.upper_case_acronyms_aggressive));
115-
}
120+
},
121+
_ => {},
116122
}
117123
}
118124
}

0 commit comments

Comments
 (0)