@@ -33,6 +33,11 @@ pub fn method_context(cx: &LateContext<'_>, id: LocalDefId) -> MethodLateContext
3333 }
3434}
3535
36+ fn assoc_item_in_trait_impl ( cx : & LateContext < ' _ > , ii : & hir:: ImplItem < ' _ > ) -> bool {
37+ let item = cx. tcx . associated_item ( ii. owner_id ) ;
38+ item. trait_item_def_id . is_some ( )
39+ }
40+
3641declare_lint ! {
3742 /// The `non_camel_case_types` lint detects types, variants, traits and
3843 /// type parameters that don't have camel case names.
@@ -177,6 +182,7 @@ impl EarlyLintPass for NonCamelCaseTypes {
177182 // trait impls where we should have warned for the trait definition already.
178183 ast:: ItemKind :: Impl ( box ast:: Impl { of_trait : None , items, .. } ) => {
179184 for it in items {
185+ // FIXME: this doesn't respect `#[allow(..)]` on the item itself.
180186 if let ast:: AssocItemKind :: Type ( ..) = it. kind {
181187 self . check_case ( cx, "associated type" , & it. ident ) ;
182188 }
@@ -494,15 +500,6 @@ impl<'tcx> LateLintPass<'tcx> for NonUpperCaseGlobals {
494500 hir:: ItemKind :: Const ( ..) => {
495501 NonUpperCaseGlobals :: check_upper_case ( cx, "constant" , & it. ident ) ;
496502 }
497- // we only want to check inherent associated consts, trait consts
498- // are linted at def-site.
499- hir:: ItemKind :: Impl ( hir:: Impl { of_trait : None , items, .. } ) => {
500- for it in * items {
501- if let hir:: AssocItemKind :: Const = it. kind {
502- NonUpperCaseGlobals :: check_upper_case ( cx, "associated constant" , & it. ident ) ;
503- }
504- }
505- }
506503 _ => { }
507504 }
508505 }
@@ -513,6 +510,12 @@ impl<'tcx> LateLintPass<'tcx> for NonUpperCaseGlobals {
513510 }
514511 }
515512
513+ fn check_impl_item ( & mut self , cx : & LateContext < ' _ > , ii : & hir:: ImplItem < ' _ > ) {
514+ if let hir:: ImplItemKind :: Const ( ..) = ii. kind && !assoc_item_in_trait_impl ( cx, ii) {
515+ NonUpperCaseGlobals :: check_upper_case ( cx, "associated constant" , & ii. ident ) ;
516+ }
517+ }
518+
516519 fn check_pat ( & mut self , cx : & LateContext < ' _ > , p : & hir:: Pat < ' _ > ) {
517520 // Lint for constants that look like binding identifiers (#7526)
518521 if let PatKind :: Path ( hir:: QPath :: Resolved ( None , ref path) ) = p. kind {
0 commit comments