upper_case_acronyms: don't warn on public items

Fixes #6803

changelog: upper_case_acronyms: ignore public items
This commit is contained in:
Matthias Krüger 2021-02-26 21:22:30 +01:00
parent 6343446b89
commit 9dba6a9fde
3 changed files with 12 additions and 1 deletions

View file

@ -1,7 +1,7 @@
use crate::utils::span_lint_and_sugg; use crate::utils::span_lint_and_sugg;
use if_chain::if_chain; use if_chain::if_chain;
use itertools::Itertools; use itertools::Itertools;
use rustc_ast::ast::{Item, ItemKind, Variant}; use rustc_ast::ast::{Item, ItemKind, Variant, VisibilityKind};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
use rustc_middle::lint::in_external_macro; use rustc_middle::lint::in_external_macro;
@ -105,6 +105,8 @@ impl EarlyLintPass for UpperCaseAcronyms {
it.kind, it.kind,
ItemKind::TyAlias(..) | ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Trait(..) ItemKind::TyAlias(..) | ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Trait(..)
); );
// do not lint public items
if !matches!(it.vis.kind, VisibilityKind::Public);
then { then {
check_ident(cx, &it.ident, self.upper_case_acronyms_aggressive); check_ident(cx, &it.ident, self.upper_case_acronyms_aggressive);
} }

View file

@ -19,4 +19,9 @@ enum Flags {
struct GCCLLVMSomething; // linted with cfg option, beware that lint suggests `GccllvmSomething` instead of struct GCCLLVMSomething; // linted with cfg option, beware that lint suggests `GccllvmSomething` instead of
// `GccLlvmSomething` // `GccLlvmSomething`
// don't warn on public items
pub struct MIXEDCapital;
pub struct FULLCAPITAL;
fn main() {} fn main() {}

View file

@ -19,4 +19,8 @@ enum Flags {
struct GCCLLVMSomething; // linted with cfg option, beware that lint suggests `GccllvmSomething` instead of struct GCCLLVMSomething; // linted with cfg option, beware that lint suggests `GccllvmSomething` instead of
// `GccLlvmSomething` // `GccLlvmSomething`
// public items must not be linted
pub struct NOWARNINGHERE;
pub struct ALSONoWarningHERE;
fn main() {} fn main() {}