Skip to content

Commit 9dba6a9

Browse files
committed
upper_case_acronyms: don't warn on public items
Fixes #6803 changelog: upper_case_acronyms: ignore public items
1 parent 6343446 commit 9dba6a9

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

clippy_lints/src/upper_case_acronyms.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::utils::span_lint_and_sugg;
22
use if_chain::if_chain;
33
use itertools::Itertools;
4-
use rustc_ast::ast::{Item, ItemKind, Variant};
4+
use rustc_ast::ast::{Item, ItemKind, Variant, VisibilityKind};
55
use rustc_errors::Applicability;
66
use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
77
use rustc_middle::lint::in_external_macro;
@@ -105,6 +105,8 @@ impl EarlyLintPass for UpperCaseAcronyms {
105105
it.kind,
106106
ItemKind::TyAlias(..) | ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Trait(..)
107107
);
108+
// do not lint public items
109+
if !matches!(it.vis.kind, VisibilityKind::Public);
108110
then {
109111
check_ident(cx, &it.ident, self.upper_case_acronyms_aggressive);
110112
}

tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,9 @@ enum Flags {
1919
struct GCCLLVMSomething; // linted with cfg option, beware that lint suggests `GccllvmSomething` instead of
2020
// `GccLlvmSomething`
2121

22+
// don't warn on public items
23+
pub struct MIXEDCapital;
24+
25+
pub struct FULLCAPITAL;
26+
2227
fn main() {}

tests/ui/upper_case_acronyms.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,8 @@ enum Flags {
1919
struct GCCLLVMSomething; // linted with cfg option, beware that lint suggests `GccllvmSomething` instead of
2020
// `GccLlvmSomething`
2121

22+
// public items must not be linted
23+
pub struct NOWARNINGHERE;
24+
pub struct ALSONoWarningHERE;
25+
2226
fn main() {}

0 commit comments

Comments
 (0)